diff options
author | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-08 00:27:43 +0000 |
---|---|---|
committer | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-08 00:27:43 +0000 |
commit | bf849e3910054e8ebf7502d77106ffea03bd2727 (patch) | |
tree | 0a9f0b9edccf0d24f00f25da06bd043a83bc68ee /google_apis/gcm | |
parent | 7d83967257a293224326221507c4304cff6bd9bc (diff) | |
download | chromium_src-bf849e3910054e8ebf7502d77106ffea03bd2727.zip chromium_src-bf849e3910054e8ebf7502d77106ffea03bd2727.tar.gz chromium_src-bf849e3910054e8ebf7502d77106ffea03bd2727.tar.bz2 |
Revert 262242 "Adding basic G-services handling"
Looks like it's failing on various Mac bots:
http://build.chromium.org/p/chromium.mac/builders/Mac%2010.7%20Tests%20(dbg)(4)/builds/22407
in range
http://build.chromium.org/f/chromium/perf/dashboard/ui/changelog.html?url=%2Ftrunk%2Fsrc&range=262232%3A262247&mode=html
> Adding basic G-services handling
>
> * extracting CheckinRequest::RequestInfo to better manage checkin parameters
> * adding G-services settings digest to RequestInfo of the checkin (will be sent with checkin request)
> * extracting G-services settings from checkin response
> * storing and loading of the G-services settings in GCM Store
>
> BUG=359254
>
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=261912
>
> Review URL: https://codereview.chromium.org/215363007
TBR=fgorski@chromium.org
Review URL: https://codereview.chromium.org/227413010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262266 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis/gcm')
-rw-r--r-- | google_apis/gcm/engine/checkin_request.cc | 42 | ||||
-rw-r--r-- | google_apis/gcm/engine/checkin_request.h | 45 | ||||
-rw-r--r-- | google_apis/gcm/engine/checkin_request_unittest.cc | 37 | ||||
-rw-r--r-- | google_apis/gcm/engine/gcm_store.h | 10 | ||||
-rw-r--r-- | google_apis/gcm/engine/gcm_store_impl.cc | 108 | ||||
-rw-r--r-- | google_apis/gcm/engine/gcm_store_impl.h | 6 | ||||
-rw-r--r-- | google_apis/gcm/engine/gcm_store_impl_unittest.cc | 50 | ||||
-rw-r--r-- | google_apis/gcm/gcm_client_impl.cc | 33 | ||||
-rw-r--r-- | google_apis/gcm/gcm_client_impl.h | 15 | ||||
-rw-r--r-- | google_apis/gcm/tools/mcs_probe.cc | 31 |
10 files changed, 79 insertions, 298 deletions
diff --git a/google_apis/gcm/engine/checkin_request.cc b/google_apis/gcm/engine/checkin_request.cc index 7addbeb..94a6fc9 100644 --- a/google_apis/gcm/engine/checkin_request.cc +++ b/google_apis/gcm/engine/checkin_request.cc @@ -46,30 +46,21 @@ void RecordCheckinStatusToUMA(CheckinRequestStatus status) { } // namespace -CheckinRequest::RequestInfo::RequestInfo( +CheckinRequest::CheckinRequest( + const CheckinRequestCallback& callback, + const net::BackoffEntry::Policy& backoff_policy, + const checkin_proto::ChromeBuildProto& chrome_build_proto, uint64 android_id, uint64 security_token, - const std::string& settings_digest, const std::vector<std::string>& account_ids, - const checkin_proto::ChromeBuildProto& chrome_build_proto) - : android_id(android_id), - security_token(security_token), - settings_digest(settings_digest), - account_ids(account_ids), - chrome_build_proto(chrome_build_proto) { -} - -CheckinRequest::RequestInfo::~RequestInfo() {} - -CheckinRequest::CheckinRequest( - const RequestInfo& request_info, - const net::BackoffEntry::Policy& backoff_policy, - const CheckinRequestCallback& callback, net::URLRequestContextGetter* request_context_getter) : request_context_getter_(request_context_getter), callback_(callback), backoff_entry_(&backoff_policy), - request_info_(request_info), + chrome_build_proto_(chrome_build_proto), + android_id_(android_id), + security_token_(security_token), + account_ids_(account_ids), weak_ptr_factory_(this) { } @@ -79,24 +70,21 @@ void CheckinRequest::Start() { DCHECK(!url_fetcher_.get()); checkin_proto::AndroidCheckinRequest request; - request.set_id(request_info_.android_id); - request.set_security_token(request_info_.security_token); + request.set_id(android_id_); + request.set_security_token(security_token_); request.set_user_serial_number(kDefaultUserSerialNumber); request.set_version(kRequestVersionValue); - if (!request_info_.settings_digest.empty()) - request.set_digest(request_info_.settings_digest); checkin_proto::AndroidCheckinProto* checkin = request.mutable_checkin(); - checkin->mutable_chrome_build()->CopyFrom(request_info_.chrome_build_proto); + checkin->mutable_chrome_build()->CopyFrom(chrome_build_proto_); #if defined(CHROME_OS) checkin->set_type(checkin_proto::DEVICE_CHROME_OS); #else checkin->set_type(checkin_proto::DEVICE_CHROME_BROWSER); #endif - for (std::vector<std::string>::const_iterator iter = - request_info_.account_ids.begin(); - iter != request_info_.account_ids.end(); + for (std::vector<std::string>::const_iterator iter = account_ids_.begin(); + iter != account_ids_.end(); ++iter) { request.add_account_cookie("[" + *iter + "]"); } @@ -153,7 +141,7 @@ void CheckinRequest::OnURLFetchComplete(const net::URLFetcher* source) { << response_status << ". Checkin failed."; RecordCheckinStatusToUMA(response_status == net::HTTP_BAD_REQUEST ? HTTP_BAD_REQUEST : HTTP_UNAUTHORIZED); - callback_.Run(response_proto); + callback_.Run(0,0); return; } @@ -179,7 +167,7 @@ void CheckinRequest::OnURLFetchComplete(const net::URLFetcher* source) { } RecordCheckinStatusToUMA(SUCCESS); - callback_.Run(response_proto); + callback_.Run(response_proto.android_id(), response_proto.security_token()); } } // namespace gcm diff --git a/google_apis/gcm/engine/checkin_request.h b/google_apis/gcm/engine/checkin_request.h index 1d706a7..e11089a 100644 --- a/google_apis/gcm/engine/checkin_request.h +++ b/google_apis/gcm/engine/checkin_request.h @@ -12,7 +12,7 @@ #include "base/callback.h" #include "base/memory/weak_ptr.h" #include "google_apis/gcm/base/gcm_export.h" -#include "google_apis/gcm/protocol/checkin.pb.h" +#include "google_apis/gcm/protocol/android_checkin.pb.h" #include "net/base/backoff_entry.h" #include "net/url_request/url_fetcher_delegate.h" @@ -28,35 +28,17 @@ namespace gcm { // check-ins. class GCM_EXPORT CheckinRequest : public net::URLFetcherDelegate { public: - // A callback function for the checkin request, accepting |checkin_response| - // protobuf. - typedef base::Callback<void(const checkin_proto::AndroidCheckinResponse& - checkin_response)> CheckinRequestCallback; - - // Checkin request details. - struct GCM_EXPORT RequestInfo { - RequestInfo(uint64 android_id, - uint64 security_token, - const std::string& settings_digest, - const std::vector<std::string>& account_ids, - const checkin_proto::ChromeBuildProto& chrome_build_proto); - ~RequestInfo(); - - // Android ID of the device. - uint64 android_id; - // Security token of the device. - uint64 security_token; - // Digest of GServices settings on the device. - std::string settings_digest; - // Account IDs of GAIA accounts related to this device. - std::vector<std::string> account_ids; - // Information of the Chrome build of this device. - checkin_proto::ChromeBuildProto chrome_build_proto; - }; - - CheckinRequest(const RequestInfo& request_info, + // A callback function for the checkin request, accepting |android_id| and + // |security_token|. + typedef base::Callback<void(uint64 android_id, uint64 security_token)> + CheckinRequestCallback; + + CheckinRequest(const CheckinRequestCallback& callback, const net::BackoffEntry::Policy& backoff_policy, - const CheckinRequestCallback& callback, + const checkin_proto::ChromeBuildProto& chrome_build_proto, + uint64 android_id, + uint64 security_token, + const std::vector<std::string>& account_ids, net::URLRequestContextGetter* request_context_getter); virtual ~CheckinRequest(); @@ -75,7 +57,10 @@ class GCM_EXPORT CheckinRequest : public net::URLFetcherDelegate { net::BackoffEntry backoff_entry_; scoped_ptr<net::URLFetcher> url_fetcher_; - const RequestInfo request_info_; + const checkin_proto::ChromeBuildProto chrome_build_proto_; + const uint64 android_id_; + const uint64 security_token_; + const std::vector<std::string> account_ids_; base::WeakPtrFactory<CheckinRequest> weak_ptr_factory_; diff --git a/google_apis/gcm/engine/checkin_request_unittest.cc b/google_apis/gcm/engine/checkin_request_unittest.cc index e750df0..0142e0c 100644 --- a/google_apis/gcm/engine/checkin_request_unittest.cc +++ b/google_apis/gcm/engine/checkin_request_unittest.cc @@ -51,7 +51,6 @@ const uint64 kBlankAndroidId = 999999UL; const uint64 kBlankSecurityToken = 999999UL; const char kChromeVersion[] = "Version String"; const uint64 kSecurityToken = 77; -const char kSettingsDigest[] = "settings_digest"; class CheckinRequestTest : public testing::Test { public: @@ -66,8 +65,7 @@ class CheckinRequestTest : public testing::Test { CheckinRequestTest(); virtual ~CheckinRequestTest(); - void FetcherCallback( - const checkin_proto::AndroidCheckinResponse& response); + void FetcherCallback(uint64 android_id, uint64 security_token); void CreateRequest(uint64 android_id, uint64 security_token); @@ -104,13 +102,11 @@ CheckinRequestTest::CheckinRequestTest() CheckinRequestTest::~CheckinRequestTest() {} -void CheckinRequestTest::FetcherCallback( - const checkin_proto::AndroidCheckinResponse& checkin_response) { +void CheckinRequestTest::FetcherCallback(uint64 android_id, + uint64 security_token) { callback_called_ = true; - if (checkin_response.has_android_id()) - android_id_ = checkin_response.android_id(); - if (checkin_response.has_security_token()) - security_token_ = checkin_response.security_token(); + android_id_ = android_id; + security_token_ = security_token; } void CheckinRequestTest::CreateRequest(uint64 android_id, @@ -121,19 +117,15 @@ void CheckinRequestTest::CreateRequest(uint64 android_id, chrome_build_proto_.set_channel( checkin_proto::ChromeBuildProto::CHANNEL_CANARY); chrome_build_proto_.set_chrome_version(kChromeVersion); - - CheckinRequest::RequestInfo request_info( - android_id, - security_token, - kSettingsDigest, - account_ids_, - chrome_build_proto_); // Then create a request with that protobuf and specified android_id, // security_token. request_.reset(new CheckinRequest( - request_info, - kDefaultBackoffPolicy, base::Bind(&CheckinRequestTest::FetcherCallback, base::Unretained(this)), + kDefaultBackoffPolicy, + chrome_build_proto_, + android_id, + security_token, + account_ids_, url_request_context_getter_.get())); // Setting android_id_ and security_token_ to blank value, not used elsewhere @@ -206,7 +198,6 @@ TEST_F(CheckinRequestTest, FetcherData) { request_proto.checkin().type()); #endif - EXPECT_EQ(kSettingsDigest, request_proto.digest()); EXPECT_EQ(1, request_proto.account_cookie_size()); EXPECT_EQ("[account_id]", request_proto.account_cookie(0)); } @@ -253,8 +244,8 @@ TEST_F(CheckinRequestTest, ResponseHttpStatusUnauthorized) { CompleteFetch(); EXPECT_TRUE(callback_called_); - EXPECT_EQ(kBlankAndroidId, android_id_); - EXPECT_EQ(kBlankSecurityToken, security_token_); + EXPECT_EQ(0u, android_id_); + EXPECT_EQ(0u, security_token_); } TEST_F(CheckinRequestTest, ResponseHttpStatusBadRequest) { @@ -265,8 +256,8 @@ TEST_F(CheckinRequestTest, ResponseHttpStatusBadRequest) { CompleteFetch(); EXPECT_TRUE(callback_called_); - EXPECT_EQ(kBlankAndroidId, android_id_); - EXPECT_EQ(kBlankSecurityToken, security_token_); + EXPECT_EQ(0u, android_id_); + EXPECT_EQ(0u, security_token_); } TEST_F(CheckinRequestTest, ResponseHttpStatusNotOK) { diff --git a/google_apis/gcm/engine/gcm_store.h b/google_apis/gcm/engine/gcm_store.h index 1b15e56b..ccf480b 100644 --- a/google_apis/gcm/engine/gcm_store.h +++ b/google_apis/gcm/engine/gcm_store.h @@ -48,8 +48,6 @@ class GCM_EXPORT GCMStore { RegistrationInfoMap registrations; std::vector<std::string> incoming_messages; OutgoingMessageMap outgoing_messages; - std::map<std::string, std::string> gservices_settings; - std::string gservices_digest; base::Time last_checkin_time; }; @@ -109,14 +107,6 @@ class GCM_EXPORT GCMStore { virtual void SetLastCheckinTime(const base::Time& last_checkin_time, const UpdateCallback& callback) = 0; - // G-service settings handling. - // Persists |settings| and |settings_digest|. It completely replaces the - // existing data. - virtual void SetGServicesSettings( - const std::map<std::string, std::string>& settings, - const std::string& settings_digest, - const UpdateCallback& callback) = 0; - private: DISALLOW_COPY_AND_ASSIGN(GCMStore); }; diff --git a/google_apis/gcm/engine/gcm_store_impl.cc b/google_apis/gcm/engine/gcm_store_impl.cc index 5393fd1..9bd562d 100644 --- a/google_apis/gcm/engine/gcm_store_impl.cc +++ b/google_apis/gcm/engine/gcm_store_impl.cc @@ -16,14 +16,12 @@ #include "base/stl_util.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_piece.h" -#include "base/time/time.h" #include "base/tracked_objects.h" #include "components/os_crypt/os_crypt.h" #include "google_apis/gcm/base/mcs_message.h" #include "google_apis/gcm/base/mcs_util.h" #include "google_apis/gcm/protocol/mcs.pb.h" #include "third_party/leveldatabase/src/include/leveldb/db.h" -#include "third_party/leveldatabase/src/include/leveldb/write_batch.h" namespace gcm { @@ -55,14 +53,6 @@ const char kOutgoingMsgKeyStart[] = "outgoing1-"; // Key guaranteed to be higher than all outgoing message keys. // Used for limiting iteration. const char kOutgoingMsgKeyEnd[] = "outgoing2-"; -// Lowest lexicographically ordered G-service settings key. -// Used for prefixing G-services settings. -const char kGServiceSettingKeyStart[] = "gservice1-"; -// Key guaranteed to be higher than all G-services settings keys. -// Used for limiting iteration. -const char kGServiceSettingKeyEnd[] = "gservice2-"; -// Key for digest of the last G-services settings update. -const char kGServiceSettingsDigestKey[] = "gservices_digest"; // Key used to timestamp last checkin (marked with G services settings update). const char kLastCheckinTimeKey[] = "last_checkin_time"; @@ -86,14 +76,6 @@ std::string ParseOutgoingKey(const std::string& key) { return key.substr(arraysize(kOutgoingMsgKeyStart) - 1); } -std::string MakeGServiceSettingKey(const std::string& setting_name) { - return kGServiceSettingKeyStart + setting_name; -} - -std::string ParseGServiceSettingKey(const std::string& key) { - return key.substr(arraysize(kGServiceSettingKeyStart) - 1); -} - // Note: leveldb::Slice keeps a pointer to the data in |s|, which must therefore // outlive the slice. // For example: MakeSlice(MakeOutgoingKey(x)) is invalid. @@ -139,10 +121,6 @@ class GCMStoreImpl::Backend const UpdateCallback& callback); void SetLastCheckinTime(const base::Time& last_checkin_time, const UpdateCallback& callback); - void SetGServicesSettings( - const std::map<std::string, std::string>& settings, - const std::string& digest, - const UpdateCallback& callback); private: friend class base::RefCountedThreadSafe<Backend>; @@ -153,8 +131,6 @@ class GCMStoreImpl::Backend bool LoadIncomingMessages(std::vector<std::string>* incoming_messages); bool LoadOutgoingMessages(OutgoingMessageMap* outgoing_messages); bool LoadLastCheckinTime(base::Time* last_checkin_time); - bool LoadGServicesSettings(std::map<std::string, std::string>* settings, - std::string* digest); const base::FilePath path_; scoped_refptr<base::SequencedTaskRunner> foreground_task_runner_; @@ -200,16 +176,12 @@ void GCMStoreImpl::Backend::Load(const LoadCallback& callback) { !LoadRegistrations(&result->registrations) || !LoadIncomingMessages(&result->incoming_messages) || !LoadOutgoingMessages(&result->outgoing_messages) || - !LoadLastCheckinTime(&result->last_checkin_time) || - !LoadGServicesSettings(&result->gservices_settings, - &result->gservices_digest)) { + !LoadLastCheckinTime(&result->last_checkin_time)) { result->device_android_id = 0; result->device_security_token = 0; result->registrations.clear(); result->incoming_messages.clear(); result->outgoing_messages.clear(); - result->gservices_settings.clear(); - result->gservices_digest.clear(); result->last_checkin_time = base::Time::FromInternalValue(0LL); foreground_task_runner_->PostTask(FROM_HERE, base::Bind(callback, @@ -493,44 +465,7 @@ void GCMStoreImpl::Backend::SetLastCheckinTime( if (!s.ok()) LOG(ERROR) << "LevelDB set last checkin time failed: " << s.ToString(); - foreground_task_runner_->PostTask(FROM_HERE, base::Bind(callback, s.ok())); -} - -void GCMStoreImpl::Backend::SetGServicesSettings( - const std::map<std::string, std::string>& settings, - const std::string& settings_digest, - const UpdateCallback& callback) { - leveldb::WriteBatch write_batch; - - // Remove all existing settings. - leveldb::ReadOptions read_options; - read_options.verify_checksums = true; - scoped_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); - for (iter->Seek(MakeSlice(kGServiceSettingKeyStart)); - iter->Valid() && iter->key().ToString() < kGServiceSettingKeyEnd; - iter->Next()) { - write_batch.Delete(iter->key()); - } - - // Add the new settings. - for (std::map<std::string, std::string>::const_iterator iter = - settings.begin(); - iter != settings.end(); ++iter) { - write_batch.Put(MakeSlice(MakeGServiceSettingKey(iter->first)), - MakeSlice(iter->second)); - } - - // Update the settings digest. - write_batch.Put(MakeSlice(kGServiceSettingsDigestKey), - MakeSlice(settings_digest)); - - // Write it all in a batch. - leveldb::WriteOptions write_options; - write_options.sync = true; - leveldb::Status s = db_->Write(write_options, &write_batch); - if (!s.ok()) - LOG(ERROR) << "LevelDB GService Settings update failed: " << s.ToString(); foreground_task_runner_->PostTask(FROM_HERE, base::Bind(callback, s.ok())); } @@ -669,34 +604,6 @@ bool GCMStoreImpl::Backend::LoadLastCheckinTime( return true; } -bool GCMStoreImpl::Backend::LoadGServicesSettings( - std::map<std::string, std::string>* settings, - std::string* digest) { - leveldb::ReadOptions read_options; - read_options.verify_checksums = true; - - // Load all of the GServices settings. - scoped_ptr<leveldb::Iterator> iter(db_->NewIterator(read_options)); - for (iter->Seek(MakeSlice(kGServiceSettingKeyStart)); - iter->Valid() && iter->key().ToString() < kGServiceSettingKeyEnd; - iter->Next()) { - std::string value = iter->value().ToString(); - if (value.empty()) { - LOG(ERROR) << "Error reading GService Settings " << value; - return false; - } - std::string id = ParseGServiceSettingKey(iter->key().ToString()); - (*settings)[id] = value; - DVLOG(1) << "Found G Service setting with key: " << id - << ", and value: " << value; - } - - // Load the settings digest. It's ok if it is empty. - db_->Get(read_options, MakeSlice(kGServiceSettingsDigestKey), digest); - - return true; -} - GCMStoreImpl::GCMStoreImpl( const base::FilePath& path, scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) @@ -876,19 +783,6 @@ void GCMStoreImpl::SetLastCheckinTime(const base::Time& last_checkin_time, callback)); } -void GCMStoreImpl::SetGServicesSettings( - const std::map<std::string, std::string>& settings, - const std::string& digest, - const UpdateCallback& callback) { - blocking_task_runner_->PostTask( - FROM_HERE, - base::Bind(&GCMStoreImpl::Backend::SetGServicesSettings, - backend_, - settings, - digest, - callback)); -} - void GCMStoreImpl::LoadContinuation(const LoadCallback& callback, scoped_ptr<LoadResult> result) { if (!result->success) { diff --git a/google_apis/gcm/engine/gcm_store_impl.h b/google_apis/gcm/engine/gcm_store_impl.h index e46c503..a1eeff6 100644 --- a/google_apis/gcm/engine/gcm_store_impl.h +++ b/google_apis/gcm/engine/gcm_store_impl.h @@ -77,12 +77,6 @@ class GCM_EXPORT GCMStoreImpl : public GCMStore { virtual void SetLastCheckinTime(const base::Time& last_checkin_time, const UpdateCallback& callback) OVERRIDE; - // G-service settings handling. - virtual void SetGServicesSettings( - const std::map<std::string, std::string>& settings, - const std::string& settings_digest, - const UpdateCallback& callback) OVERRIDE; - private: typedef std::map<std::string, int> AppIdToMessageCountMap; diff --git a/google_apis/gcm/engine/gcm_store_impl_unittest.cc b/google_apis/gcm/engine/gcm_store_impl_unittest.cc index f0f9019..41bb427 100644 --- a/google_apis/gcm/engine/gcm_store_impl_unittest.cc +++ b/google_apis/gcm/engine/gcm_store_impl_unittest.cc @@ -111,7 +111,6 @@ TEST_F(GCMStoreImplTest, LoadNew) { EXPECT_EQ(0U, load_result->device_security_token); EXPECT_TRUE(load_result->incoming_messages.empty()); EXPECT_TRUE(load_result->outgoing_messages.empty()); - EXPECT_TRUE(load_result->gservices_settings.empty()); EXPECT_EQ(base::Time::FromInternalValue(0LL), load_result->last_checkin_time); } @@ -155,55 +154,8 @@ TEST_F(GCMStoreImplTest, LastCheckinTime) { gcm_store->Load(base::Bind( &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result)); PumpLoop(); - ASSERT_EQ(last_checkin_time, load_result->last_checkin_time); -} - -TEST_F(GCMStoreImplTest, GServicesSettings_ProtocolV2) { - scoped_ptr<GCMStore> gcm_store(BuildGCMStore()); - scoped_ptr<GCMStore::LoadResult> load_result; - gcm_store->Load(base::Bind( - &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result)); - PumpLoop(); - - std::map<std::string, std::string> settings; - settings["checkin_interval"] = "12345"; - settings["mcs_port"] = "438"; - settings["checkin_url"] = "http://checkin.google.com"; - std::string digest = "digest1"; - - gcm_store->SetGServicesSettings( - settings, - digest, - base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this))); - PumpLoop(); - - gcm_store = BuildGCMStore().Pass(); - gcm_store->Load(base::Bind( - &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result)); - PumpLoop(); - - ASSERT_EQ(settings, load_result->gservices_settings); - ASSERT_EQ(digest, load_result->gservices_digest); - - // Remove some, and add some. - settings.clear(); - settings["checkin_interval"] = "54321"; - settings["registration_url"] = "http://registration.google.com"; - digest = "digest2"; - - gcm_store->SetGServicesSettings( - settings, - digest, - base::Bind(&GCMStoreImplTest::UpdateCallback, base::Unretained(this))); - PumpLoop(); - gcm_store = BuildGCMStore().Pass(); - gcm_store->Load(base::Bind( - &GCMStoreImplTest::LoadCallback, base::Unretained(this), &load_result)); - PumpLoop(); - - ASSERT_EQ(settings, load_result->gservices_settings); - ASSERT_EQ(digest, load_result->gservices_digest); + ASSERT_EQ(last_checkin_time, load_result->last_checkin_time); } TEST_F(GCMStoreImplTest, Registrations) { diff --git a/google_apis/gcm/gcm_client_impl.cc b/google_apis/gcm/gcm_client_impl.cc index ecb4b27..568e740 100644 --- a/google_apis/gcm/gcm_client_impl.cc +++ b/google_apis/gcm/gcm_client_impl.cc @@ -11,7 +11,6 @@ #include "base/message_loop/message_loop.h" #include "base/metrics/histogram.h" #include "base/sequenced_task_runner.h" -#include "base/strings/string_number_conversions.h" #include "base/time/default_clock.h" #include "google_apis/gcm/base/mcs_message.h" #include "google_apis/gcm/base/mcs_util.h" @@ -294,36 +293,32 @@ void GCMClientImpl::ResetState() { } void GCMClientImpl::StartCheckin() { - CheckinRequest::RequestInfo request_info( - device_checkin_info_.android_id, - device_checkin_info_.secret, - std::string(), - account_ids_, - chrome_build_proto_); checkin_request_.reset( - new CheckinRequest(request_info, - kDefaultBackoffPolicy, - base::Bind(&GCMClientImpl::OnCheckinCompleted, + new CheckinRequest(base::Bind(&GCMClientImpl::OnCheckinCompleted, weak_ptr_factory_.GetWeakPtr()), + kDefaultBackoffPolicy, + chrome_build_proto_, + device_checkin_info_.android_id, + device_checkin_info_.secret, + account_ids_, url_request_context_getter_)); checkin_request_->Start(); } -void GCMClientImpl::OnCheckinCompleted( - const checkin_proto::AndroidCheckinResponse& checkin_response) { +void GCMClientImpl::OnCheckinCompleted(uint64 android_id, + uint64 security_token) { checkin_request_.reset(); - if (!checkin_response.has_android_id() || - !checkin_response.has_security_token()) { - // TODO(fgorski): I don't think a retry here will help, we should probably + CheckinInfo checkin_info; + checkin_info.android_id = android_id; + checkin_info.secret = security_token; + + if (!checkin_info.IsValid()) { + // TODO(fgorski): I don't think a retry here will help, we should probalby // start over. By checking in with (0, 0). return; } - CheckinInfo checkin_info; - checkin_info.android_id = checkin_response.android_id(); - checkin_info.secret = checkin_response.security_token(); - if (state_ == INITIAL_DEVICE_CHECKIN) { OnFirstTimeDeviceCheckinCompleted(checkin_info); } else { diff --git a/google_apis/gcm/gcm_client_impl.h b/google_apis/gcm/gcm_client_impl.h index 9f3f53a..51ca7be 100644 --- a/google_apis/gcm/gcm_client_impl.h +++ b/google_apis/gcm/gcm_client_impl.h @@ -19,7 +19,7 @@ #include "google_apis/gcm/engine/registration_request.h" #include "google_apis/gcm/engine/unregistration_request.h" #include "google_apis/gcm/gcm_client.h" -#include "google_apis/gcm/protocol/checkin.pb.h" +#include "google_apis/gcm/protocol/android_checkin.pb.h" #include "net/base/net_log.h" #include "net/url_request/url_request_context_getter.h" @@ -167,12 +167,13 @@ class GCM_EXPORT GCMClientImpl : public GCMClient { // Starts a first time device checkin. void StartCheckin(); - // Completes the device checkin request by parsing the |checkin_response|. - // Function also cleans up the pending checkin. - void OnCheckinCompleted( - const checkin_proto::AndroidCheckinResponse& checkin_response); - // Schedules next device checkin, based on |last_checkin_time| and - // checkin_interval specified in GServices settings. + // Completes the device checkin request. + // |android_id| and |security_token| are expected to be non-zero or an error + // is triggered. Function also cleans up the pending checkin. + void OnCheckinCompleted(uint64 android_id, + uint64 security_token); + // Schedules next device checkin, based on |last_checkin_time| and default + // checkin interval. void SchedulePeriodicCheckin(const base::Time& last_checkin_time); // Callback for setting last checkin time in the |gcm_store_|. void SetLastCheckinTimeCallback(bool success); diff --git a/google_apis/gcm/tools/mcs_probe.cc b/google_apis/gcm/tools/mcs_probe.cc index 038f3af..6d9a7d5 100644 --- a/google_apis/gcm/tools/mcs_probe.cc +++ b/google_apis/gcm/tools/mcs_probe.cc @@ -210,8 +210,7 @@ class MCSProbe { void LoadCallback(scoped_ptr<GCMStore::LoadResult> load_result); void UpdateCallback(bool success); void ErrorCallback(); - void OnCheckInCompleted( - const checkin_proto::AndroidCheckinResponse& checkin_response); + void OnCheckInCompleted(uint64 android_id, uint64 secret); void StartMCSLogin(); base::DefaultClock clock_; @@ -424,32 +423,24 @@ void MCSProbe::CheckIn() { chrome_build_proto.set_channel( checkin_proto::ChromeBuildProto::CHANNEL_CANARY); chrome_build_proto.set_chrome_version(kChromeVersion); - - CheckinRequest::RequestInfo request_info( - 0, 0, std::string(), std::vector<std::string>(), chrome_build_proto); - checkin_request_.reset(new CheckinRequest( - request_info, - kDefaultBackoffPolicy, base::Bind(&MCSProbe::OnCheckInCompleted, base::Unretained(this)), + kDefaultBackoffPolicy, + chrome_build_proto, + 0, + 0, + std::vector<std::string>(), url_request_context_getter_.get())); checkin_request_->Start(); } -void MCSProbe::OnCheckInCompleted( - const checkin_proto::AndroidCheckinResponse& checkin_response) { - bool success = checkin_response.has_android_id() && - checkin_response.android_id() != 0UL && - checkin_response.has_security_token() && - checkin_response.security_token() != 0UL; +void MCSProbe::OnCheckInCompleted(uint64 android_id, uint64 secret) { LOG(INFO) << "Check-in request completion " - << (success ? "success!" : "failure!"); - - if (!success) + << (android_id ? "success!" : "failure!"); + if (!android_id || !secret) return; - - android_id_ = checkin_response.android_id(); - secret_ = checkin_response.security_token(); + android_id_ = android_id; + secret_ = secret; gcm_store_->SetDeviceCredentials(android_id_, secret_, |