Skip to content

Commit

Permalink
Rename GCMClient::Load to GCMClient::Start
Browse files Browse the repository at this point in the history
This is to address TODO and keep the naming consistent.

BUG=none
TEST=none due to no functionality changes

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270020 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jianli@chromium.org committed May 13, 2014
1 parent c3eb3c8 commit fc767e4
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class ExtensionGCMAppHandlerTest : public testing::Test {
profile(),
&ExtensionGCMAppHandlerTest::BuildGCMProfileService));
scoped_ptr<gcm::GCMClientFactory> gcm_client_factory(
new gcm::FakeGCMClientFactory(gcm::GCMClientMock::NO_DELAY_LOADING));
new gcm::FakeGCMClientFactory(gcm::GCMClientMock::NO_DELAY_START));
gcm_profile_service->Initialize(gcm_client_factory.Pass());

// Create a fake version of ExtensionGCMAppHandler.
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/services/gcm/fake_gcm_client_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
namespace gcm {

FakeGCMClientFactory::FakeGCMClientFactory(
GCMClientMock::LoadingDelay gcm_client_loading_delay)
: gcm_client_loading_delay_(gcm_client_loading_delay) {
GCMClientMock::StartMode gcm_client_start_mode)
: gcm_client_start_mode_(gcm_client_start_mode) {
}

FakeGCMClientFactory::~FakeGCMClientFactory() {
}

scoped_ptr<GCMClient> FakeGCMClientFactory::BuildInstance() {
return scoped_ptr<GCMClient>(new GCMClientMock(gcm_client_loading_delay_));
return scoped_ptr<GCMClient>(new GCMClientMock(gcm_client_start_mode_));
}

} // namespace gcm
5 changes: 2 additions & 3 deletions chrome/browser/services/gcm/fake_gcm_client_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ class GCMClient;

class FakeGCMClientFactory : public GCMClientFactory {
public:
explicit FakeGCMClientFactory(
GCMClientMock::LoadingDelay gcm_client_loading_delay);
explicit FakeGCMClientFactory(GCMClientMock::StartMode gcm_client_start_mode);
virtual ~FakeGCMClientFactory();

// GCMClientFactory:
virtual scoped_ptr<GCMClient> BuildInstance() OVERRIDE;

private:
GCMClientMock::LoadingDelay gcm_client_loading_delay_;
GCMClientMock::StartMode gcm_client_start_mode_;

DISALLOW_COPY_AND_ASSIGN(FakeGCMClientFactory);
};
Expand Down
12 changes: 6 additions & 6 deletions chrome/browser/services/gcm/gcm_client_mock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

namespace gcm {

GCMClientMock::GCMClientMock(LoadingDelay loading_delay)
GCMClientMock::GCMClientMock(StartMode start_mode)
: delegate_(NULL),
status_(UNINITIALIZED),
loading_delay_(loading_delay),
start_mode_(start_mode),
weak_ptr_factory_(this) {
}

Expand All @@ -34,17 +34,17 @@ void GCMClientMock::Initialize(
delegate_ = delegate;
}

void GCMClientMock::Load() {
void GCMClientMock::Start() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
DCHECK_NE(LOADED, status_);
DCHECK_NE(STARTED, status_);

if (loading_delay_ == DELAY_LOADING)
if (start_mode_ == DELAY_START)
return;
DoLoading();
}

void GCMClientMock::DoLoading() {
status_ = LOADED;
status_ = STARTED;
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&GCMClientMock::CheckinFinished,
Expand Down
15 changes: 7 additions & 8 deletions chrome/browser/services/gcm/gcm_client_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ class GCMClientMock : public GCMClient {
public:
enum Status {
UNINITIALIZED,
LOADED,
STARTED,
STOPPED,
CHECKED_OUT
};

enum LoadingDelay {
NO_DELAY_LOADING,
DELAY_LOADING,
enum StartMode {
NO_DELAY_START,
DELAY_START,
};

// |loading_delay| denotes if the check-in should be delayed.
explicit GCMClientMock(LoadingDelay loading_delay);
explicit GCMClientMock(StartMode start_mode);
virtual ~GCMClientMock();

// Overridden from GCMClient:
Expand All @@ -39,7 +38,7 @@ class GCMClientMock : public GCMClient {
const scoped_refptr<net::URLRequestContextGetter>&
url_request_context_getter,
Delegate* delegate) OVERRIDE;
virtual void Load() OVERRIDE;
virtual void Start() OVERRIDE;
virtual void Stop() OVERRIDE;
virtual void CheckOut() OVERRIDE;
virtual void Register(const std::string& app_id,
Expand Down Expand Up @@ -83,7 +82,7 @@ class GCMClientMock : public GCMClient {

Delegate* delegate_;
Status status_;
LoadingDelay loading_delay_;
StartMode start_mode_;
base::WeakPtrFactory<GCMClientMock> weak_ptr_factory_;

DISALLOW_COPY_AND_ASSIGN(GCMClientMock);
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/services/gcm/gcm_profile_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void GCMProfileServiceTest::SetUp() {
profile_.get(),
&BuildGCMProfileService));
gcm_profile_service_->Initialize(scoped_ptr<GCMClientFactory>(
new FakeGCMClientFactory(GCMClientMock::NO_DELAY_LOADING)));
new FakeGCMClientFactory(GCMClientMock::NO_DELAY_START)));

FakeSigninManager* signin_manager = static_cast<FakeSigninManager*>(
SigninManagerFactory::GetInstance()->GetForProfile(profile_.get()));
Expand Down Expand Up @@ -158,7 +158,7 @@ TEST_F(GCMProfileServiceTest, RegisterUnderNeutralChannelSignal) {

// GCMClient should be checked in.
EXPECT_TRUE(gcm_profile_service_->IsGCMClientReady());
EXPECT_EQ(GCMClientMock::LOADED, GetGCMClient()->status());
EXPECT_EQ(GCMClientMock::STARTED, GetGCMClient()->status());

// Registration should succeed.
std::string expected_registration_id =
Expand All @@ -180,7 +180,7 @@ TEST_F(GCMProfileServiceTest, SendUnderNeutralChannelSignal) {

// GCMClient should be checked in.
EXPECT_TRUE(gcm_profile_service_->IsGCMClientReady());
EXPECT_EQ(GCMClientMock::LOADED, GetGCMClient()->status());
EXPECT_EQ(GCMClientMock::STARTED, GetGCMClient()->status());

// Sending should succeed.
EXPECT_EQ(message.id, send_message_id_);
Expand Down
28 changes: 13 additions & 15 deletions chrome/browser/services/gcm/gcm_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class GCMService::IOWorker : public GCMClient::Delegate {
const std::vector<std::string>& account_ids,
const scoped_refptr<net::URLRequestContextGetter>&
url_request_context_getter);
void Load(const base::WeakPtr<GCMService>& service);
void Start(const base::WeakPtr<GCMService>& service);
void Stop();
void CheckOut();
void Register(const std::string& app_id,
Expand Down Expand Up @@ -304,11 +304,11 @@ void GCMService::IOWorker::OnActivityRecorded() {
GetGCMStatistics(false);
}

void GCMService::IOWorker::Load(const base::WeakPtr<GCMService>& service) {
void GCMService::IOWorker::Start(const base::WeakPtr<GCMService>& service) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));

service_ = service;
gcm_client_->Load();
gcm_client_->Start();
}

void GCMService::IOWorker::Stop() {
Expand Down Expand Up @@ -410,18 +410,17 @@ void GCMService::Initialize(scoped_ptr<GCMClientFactory> gcm_client_factory) {
account_ids,
GetURLRequestContextGetter()));

// Load from the GCM store and initiate the GCM check-in if the rollout signal
// indicates yes.
// Start the GCM service if the rollout signal indicates yes.
if (ShouldStartAutomatically())
EnsureLoaded();
EnsureStarted();

identity_provider_->AddObserver(this);
}

void GCMService::Start() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));

EnsureLoaded();
EnsureStarted();
}

void GCMService::Stop() {
Expand Down Expand Up @@ -667,14 +666,14 @@ void GCMService::SetGCMRecording(GetGCMStatisticsCallback callback,

void GCMService::OnActiveAccountLogin() {
if (ShouldStartAutomatically())
EnsureLoaded();
EnsureStarted();
}

void GCMService::OnActiveAccountLogout() {
CheckOut();
}

void GCMService::EnsureLoaded() {
void GCMService::EnsureStarted() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
const std::string account_id = identity_provider_->GetActiveAccountId();
if (account_id.empty())
Expand All @@ -690,14 +689,12 @@ void GCMService::EnsureLoaded() {
DCHECK(!delayed_task_controller_);
delayed_task_controller_.reset(new DelayedTaskController);

// This will load the data from the gcm store and trigger the check-in if
// the persisted check-in info is not found.
// Note that we need to pass weak pointer again since the existing weak
// pointer in IOWorker might have been invalidated when check-out occurs.
content::BrowserThread::PostTask(
content::BrowserThread::IO,
FROM_HERE,
base::Bind(&GCMService::IOWorker::Load,
base::Bind(&GCMService::IOWorker::Start,
base::Unretained(io_worker_.get()),
weak_ptr_factory_.GetWeakPtr()));
}
Expand Down Expand Up @@ -733,10 +730,11 @@ void GCMService::CheckOut() {

GCMClient::Result GCMService::EnsureAppReady(const std::string& app_id) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
// Ensure that check-in has been done.
EnsureLoaded();

// If the service was not started, bail out.
// Starts the service if not yet.
EnsureStarted();

// If the service cannot be started, bail out.
if (account_id_.empty())
return GCMClient::NOT_SIGNED_IN;

Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/services/gcm/gcm_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ class GCMService : public IdentityProvider::Observer {

typedef std::map<std::string, GCMAppHandler*> GCMAppHandlerMap;

// Ensures that the GCMClient is loaded and the GCM check-in is done if the
// Ensures that the GCMClient is started and the GCM check-in is done if the
// |identity_provider_| is able to supply an account ID.
void EnsureLoaded();
void EnsureStarted();

// Remove cached data when GCM service is stopped.
void RemoveCachedData();
Expand Down
Loading

0 comments on commit fc767e4

Please sign in to comment.