Skip to content

Commit

Permalink
Fix the DCHECK failure when starting and stopping GCMClient immediately
Browse files Browse the repository at this point in the history
BUG=383561
TEST=new test added

Review URL: https://codereview.chromium.org/327263003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277072 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jianli@chromium.org committed Jun 13, 2014
1 parent 0928c80 commit 1abdf20
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions components/gcm_driver/gcm_client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ void GCMClientImpl::UpdateRegistrationCallback(bool success) {
}

void GCMClientImpl::Stop() {
weak_ptr_factory_.InvalidateWeakPtrs();
device_checkin_info_.Reset();
connection_factory_.reset();
mcs_client_.reset();
Expand Down
60 changes: 60 additions & 0 deletions components/gcm_driver/gcm_client_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class GCMClientImplTest : public testing::Test,

void BuildGCMClient(base::TimeDelta clock_step);
void InitializeGCMClient();
void StartGCMClient();
void ReceiveMessageFromMCS(const MCSMessage& message);
void CompleteCheckin(uint64 android_id,
uint64 security_token,
Expand Down Expand Up @@ -333,6 +334,7 @@ void GCMClientImplTest::SetUp() {
InitializeLoop();
BuildGCMClient(base::TimeDelta());
InitializeGCMClient();
StartGCMClient();
CompleteCheckin(kDeviceAndroidId,
kDeviceSecurityToken,
std::string(),
Expand Down Expand Up @@ -452,7 +454,9 @@ void GCMClientImplTest::InitializeGCMClient() {
url_request_context_getter_,
make_scoped_ptr<Encryptor>(new FakeEncryptor),
this);
}

void GCMClientImplTest::StartGCMClient() {
// Start loading and check-in.
gcm_client_->Start();

Expand Down Expand Up @@ -556,6 +560,7 @@ TEST_F(GCMClientImplTest, DISABLED_RegisterAppFromCache) {
// Recreate GCMClient in order to load from the persistent store.
BuildGCMClient(base::TimeDelta());
InitializeGCMClient();
StartGCMClient();

EXPECT_TRUE(ExistsRegistration(kAppId));
}
Expand Down Expand Up @@ -704,6 +709,7 @@ void GCMClientImplCheckinTest::SetUp() {
// Time will be advancing one hour every time it is checked.
BuildGCMClient(base::TimeDelta::FromSeconds(kSettingsCheckinInterval));
InitializeGCMClient();
StartGCMClient();
}

TEST_F(GCMClientImplCheckinTest, GServicesSettingsAfterInitialCheckin) {
Expand Down Expand Up @@ -764,6 +770,7 @@ TEST_F(GCMClientImplCheckinTest, LoadGSettingsFromStore) {

BuildGCMClient(base::TimeDelta());
InitializeGCMClient();
StartGCMClient();

EXPECT_EQ(base::TimeDelta::FromSeconds(kSettingsCheckinInterval),
gservices_settings().GetCheckinInterval());
Expand All @@ -777,4 +784,57 @@ TEST_F(GCMClientImplCheckinTest, LoadGSettingsFromStore) {
gservices_settings().GetMCSFallbackEndpoint());
}

class GCMClientImplStartAndStopTest : public GCMClientImplTest {
public:
GCMClientImplStartAndStopTest();
virtual ~GCMClientImplStartAndStopTest();

virtual void SetUp() OVERRIDE;
};

GCMClientImplStartAndStopTest::GCMClientImplStartAndStopTest() {
}

GCMClientImplStartAndStopTest::~GCMClientImplStartAndStopTest() {
}

void GCMClientImplStartAndStopTest::SetUp() {
testing::Test::SetUp();
ASSERT_TRUE(CreateUniqueTempDir());
InitializeLoop();
BuildGCMClient(base::TimeDelta());
InitializeGCMClient();
}

TEST_F(GCMClientImplStartAndStopTest, StartStopAndRestart) {
// Start the GCM and wait until it is ready.
gcm_client()->Start();
PumpLoopUntilIdle();

// Stop the GCM.
gcm_client()->Stop();
PumpLoopUntilIdle();

// Restart the GCM.
gcm_client()->Start();
PumpLoopUntilIdle();
}

TEST_F(GCMClientImplStartAndStopTest, StartAndStopImmediately) {
// Start the GCM and then stop it immediately.
gcm_client()->Start();
gcm_client()->Stop();

PumpLoopUntilIdle();
}

TEST_F(GCMClientImplStartAndStopTest, StartStopAndRestartImmediately) {
// Start the GCM and then stop and restart it immediately.
gcm_client()->Start();
gcm_client()->Stop();
gcm_client()->Start();

PumpLoopUntilIdle();
}

} // namespace gcm
2 changes: 2 additions & 0 deletions google_apis/gcm/engine/gcm_store_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,8 @@ void GCMStoreImpl::Load(const LoadCallback& callback) {
}

void GCMStoreImpl::Close() {
weak_ptr_factory_.InvalidateWeakPtrs();
app_message_counts_.clear();
blocking_task_runner_->PostTask(
FROM_HERE,
base::Bind(&GCMStoreImpl::Backend::Close, backend_));
Expand Down

0 comments on commit 1abdf20

Please sign in to comment.