GCM Checkin implementation with unit tests.

BUG=284553

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243729 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/services/gcm/gcm_client_mock.cc b/chrome/browser/services/gcm/gcm_client_mock.cc
index e060fff..35da43d 100644
--- a/chrome/browser/services/gcm/gcm_client_mock.cc
+++ b/chrome/browser/services/gcm/gcm_client_mock.cc
@@ -47,9 +47,9 @@
   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
 
   // Simulate the android_id and secret by some sort of hashing.
-  CheckInInfo checkin_info;
+  CheckinInfo checkin_info;
   if (!simulate_server_error_)
-    checkin_info = GetCheckInInfoFromUsername(username);
+    checkin_info = GetCheckinInfoFromUsername(username);
 
   base::MessageLoop::current()->PostTask(
       FROM_HERE,
@@ -146,9 +146,9 @@
 }
 
 // static
-GCMClient::CheckInInfo GCMClientMock::GetCheckInInfoFromUsername(
+GCMClient::CheckinInfo GCMClientMock::GetCheckinInfoFromUsername(
     const std::string& username) {
-  CheckInInfo checkin_info;
+  CheckinInfo checkin_info;
   checkin_info.android_id = HashToUInt64(username);
   checkin_info.secret = checkin_info.android_id / 10;
   return checkin_info;
@@ -181,7 +181,7 @@
 }
 
 void GCMClientMock::CheckInFinished(std::string username,
-                                    CheckInInfo checkin_info) {
+                                    CheckinInfo checkin_info) {
   GetDelegate(username)->OnCheckInFinished(
       checkin_info, checkin_info.IsValid() ? SUCCESS : SERVER_ERROR);
 }
diff --git a/chrome/browser/services/gcm/gcm_client_mock.h b/chrome/browser/services/gcm/gcm_client_mock.h
index aeca13a..add87e23 100644
--- a/chrome/browser/services/gcm/gcm_client_mock.h
+++ b/chrome/browser/services/gcm/gcm_client_mock.h
@@ -47,7 +47,7 @@
 
   void SetIsLoading(bool is_loading);
 
-  static CheckInInfo GetCheckInInfoFromUsername(const std::string& username);
+  static CheckinInfo GetCheckinInfoFromUsername(const std::string& username);
   static std::string GetRegistrationIdFromSenderIds(
       const std::vector<std::string>& sender_ids);
 
@@ -55,7 +55,8 @@
   Delegate* GetDelegate(const std::string& username) const;
 
   // Called on IO thread.
-  void CheckInFinished(std::string username, CheckInInfo checkin_info);
+  // TODO(fgorski): Update parameters to const ref.
+  void CheckInFinished(std::string username, CheckinInfo checkin_info);
   void RegisterFinished(std::string username,
                         std::string app_id,
                         std::string registrion_id);
diff --git a/chrome/browser/services/gcm/gcm_profile_service.cc b/chrome/browser/services/gcm/gcm_profile_service.cc
index 478a905..4f0c270 100644
--- a/chrome/browser/services/gcm/gcm_profile_service.cc
+++ b/chrome/browser/services/gcm/gcm_profile_service.cc
@@ -166,7 +166,7 @@
 
   // Overridden from GCMClient::Delegate:
   // Called from IO thread.
-  virtual void OnCheckInFinished(const GCMClient::CheckInInfo& checkin_info,
+  virtual void OnCheckInFinished(const GCMClient::CheckinInfo& checkin_info,
                                  GCMClient::Result result) OVERRIDE;
   virtual void OnRegisterFinished(const std::string& app_id,
                                   const std::string& registration_id,
@@ -181,7 +181,7 @@
   virtual void OnMessageSendError(const std::string& app_id,
                                   const std::string& message_id,
                                   GCMClient::Result result) OVERRIDE;
-  virtual GCMClient::CheckInInfo GetCheckInInfo() const OVERRIDE;
+  virtual GCMClient::CheckinInfo GetCheckinInfo() const OVERRIDE;
   virtual void OnLoadingCompleted() OVERRIDE;
   virtual base::TaskRunner* GetFileTaskRunner() OVERRIDE;
 
@@ -189,7 +189,8 @@
   void SetUser(const std::string& username);
   void RemoveUser(const std::string& username);
   void CheckIn();
-  void SetCheckInInfo(GCMClient::CheckInInfo checkin_info);
+  // TODO(fgorski): Update to pass by const ref.
+  void SetCheckinInfo(GCMClient::CheckinInfo checkin_info);
   void CheckOut();
   void Register(const std::string& app_id,
                 const std::vector<std::string>& sender_ids,
@@ -210,7 +211,7 @@
 
   // The checkin info obtained from the server for the signed in user associated
   // with the profile.
-  GCMClient::CheckInInfo checkin_info_;
+  GCMClient::CheckinInfo checkin_info_;
 };
 
 GCMProfileService::IOWorker::IOWorker(
@@ -222,7 +223,7 @@
 }
 
 void GCMProfileService::IOWorker::OnCheckInFinished(
-    const GCMClient::CheckInInfo& checkin_info,
+    const GCMClient::CheckinInfo& checkin_info,
     GCMClient::Result result) {
   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
 
@@ -310,7 +311,7 @@
                  result));
 }
 
-GCMClient::CheckInInfo GCMProfileService::IOWorker::GetCheckInInfo() const {
+GCMClient::CheckinInfo GCMProfileService::IOWorker::GetCheckinInfo() const {
   return checkin_info_;
 }
 
@@ -360,8 +361,8 @@
   GCMClient::Get()->CheckIn(username_);
 }
 
-void GCMProfileService::IOWorker::SetCheckInInfo(
-    GCMClient::CheckInInfo checkin_info) {
+void GCMProfileService::IOWorker::SetCheckinInfo(
+    GCMClient::CheckinInfo checkin_info) {
   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
 
   checkin_info_ = checkin_info;
@@ -670,13 +671,13 @@
     Encryptor::DecryptString(encrypted_secret, &decrypted_secret);
     uint64 secret = 0;
     if (base::StringToUint64(decrypted_secret, &secret) && secret) {
-      GCMClient::CheckInInfo checkin_info;
+      GCMClient::CheckinInfo checkin_info;
       checkin_info.android_id = android_id;
       checkin_info.secret = secret;
       content::BrowserThread::PostTask(
           content::BrowserThread::IO,
           FROM_HERE,
-          base::Bind(&GCMProfileService::IOWorker::SetCheckInInfo,
+          base::Bind(&GCMProfileService::IOWorker::SetCheckinInfo,
                      io_worker_,
                      checkin_info));
 
@@ -735,7 +736,7 @@
                  app_id));
 }
 
-void GCMProfileService::CheckInFinished(GCMClient::CheckInInfo checkin_info,
+void GCMProfileService::CheckInFinished(GCMClient::CheckinInfo checkin_info,
                                         GCMClient::Result result) {
   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
 
diff --git a/chrome/browser/services/gcm/gcm_profile_service.h b/chrome/browser/services/gcm/gcm_profile_service.h
index 258ff8290..e34c1aa8 100644
--- a/chrome/browser/services/gcm/gcm_profile_service.h
+++ b/chrome/browser/services/gcm/gcm_profile_service.h
@@ -50,7 +50,7 @@
   class TestingDelegate {
    public:
     virtual GCMEventRouter* GetEventRouter() const = 0;
-    virtual void CheckInFinished(const GCMClient::CheckInInfo& checkin_info,
+    virtual void CheckInFinished(const GCMClient::CheckinInfo& checkin_info,
                                  GCMClient::Result result) = 0;
   };
 
@@ -140,7 +140,8 @@
               const GCMClient::OutgoingMessage& message);
 
   // Callbacks posted from IO thread to UI thread.
-  void CheckInFinished(GCMClient::CheckInInfo checkin_info,
+  // TODO(fgorski): Update parameters to be passed by const ref.
+  void CheckInFinished(GCMClient::CheckinInfo checkin_info,
                        GCMClient::Result result);
   void RegisterFinished(std::string app_id,
                         std::string registration_id,
diff --git a/chrome/browser/services/gcm/gcm_profile_service_unittest.cc b/chrome/browser/services/gcm/gcm_profile_service_unittest.cc
index cd01c4a..35daa3f 100644
--- a/chrome/browser/services/gcm/gcm_profile_service_unittest.cc
+++ b/chrome/browser/services/gcm/gcm_profile_service_unittest.cc
@@ -168,7 +168,7 @@
     return gcm_event_router_mock_.get();
   }
 
-  virtual void CheckInFinished(const GCMClient::CheckInInfo& checkin_info,
+  virtual void CheckInFinished(const GCMClient::CheckinInfo& checkin_info,
                                GCMClient::Result result) OVERRIDE {
     checkin_info_ = checkin_info;
     SignalCompleted();
@@ -229,7 +229,7 @@
   ExtensionService* extension_service_;  // Not owned.
   scoped_ptr<base::RunLoop> run_loop_;
   scoped_ptr<GCMEventRouterMock> gcm_event_router_mock_;
-  GCMClient::CheckInInfo checkin_info_;
+  GCMClient::CheckinInfo checkin_info_;
 
 #if defined(OS_CHROMEOS)
   chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
@@ -300,8 +300,8 @@
 TEST_F(GCMProfileServiceTest, CheckIn) {
   EXPECT_TRUE(checkin_info_.IsValid());
 
-  GCMClient::CheckInInfo expected_checkin_info =
-      GCMClientMock::GetCheckInInfoFromUsername(kTestingUsername);
+  GCMClient::CheckinInfo expected_checkin_info =
+      GCMClientMock::GetCheckinInfoFromUsername(kTestingUsername);
   EXPECT_EQ(expected_checkin_info.android_id, checkin_info_.android_id);
   EXPECT_EQ(expected_checkin_info.secret, checkin_info_.secret);
 }
@@ -309,7 +309,7 @@
 TEST_F(GCMProfileServiceTest, CheckInFromPrefsStore) {
   // The first check-in should be successful.
   EXPECT_TRUE(checkin_info_.IsValid());
-  GCMClient::CheckInInfo saved_checkin_info = checkin_info_;
+  GCMClient::CheckinInfo saved_checkin_info = checkin_info_;
   checkin_info_.Reset();
 
   // Check-in should not reach the server. Forcing GCMClient server error should