Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(854)

Unified Diff: chrome/browser/services/gcm/gcm_service.h

Issue 225403021: Extract Profile-independent GCMService from GCMProfileService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed most comments. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/services/gcm/gcm_service.h
diff --git a/chrome/browser/services/gcm/gcm_profile_service.h b/chrome/browser/services/gcm/gcm_service.h
similarity index 62%
copy from chrome/browser/services/gcm/gcm_profile_service.h
copy to chrome/browser/services/gcm/gcm_service.h
index 3817b0ea8f0f5076c01f1dfd07bed6724cbb2ee8..e1772f8e43483cb8dafc798812eef05b23e632c1 100644
--- a/chrome/browser/services/gcm/gcm_profile_service.h
+++ b/chrome/browser/services/gcm/gcm_service.h
@@ -1,50 +1,40 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_
-#define CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_
+#ifndef CHROME_BROWSER_SERVICES_GCM_GCM_SERVICE_H_
+#define CHROME_BROWSER_SERVICES_GCM_GCM_SERVICE_H_
#include <map>
#include <string>
+#include <vector>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
-#include "base/gtest_prod_util.h"
+#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/services/gcm/default_gcm_app_handler.h"
-#include "components/keyed_service/core/keyed_service.h"
-#include "components/signin/core/browser/signin_manager_base.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
+#include "google_apis/gaia/identity_provider.h"
#include "google_apis/gcm/gcm_client.h"
-class Profile;
-
-namespace base {
-class Value;
-}
-
namespace extensions {
class ExtensionGCMAppHandlerTest;
}
-namespace user_prefs {
-class PrefRegistrySyncable;
+namespace net {
+class URLRequestContextGetter;
}
namespace gcm {
class GCMAppHandler;
class GCMClientFactory;
-class GCMProfileServiceTestConsumer;
-// Acts as a bridge between GCM API and GCMClient layer. It is profile based.
-class GCMProfileService : public KeyedService,
- public content::NotificationObserver,
- public SigninManagerBase::Observer {
+// A bridge between the GCM users in Chrome and the GCMClient layer.
+class GCMService : public IdentityProvider::Observer {
public:
typedef base::Callback<void(const std::string& registration_id,
GCMClient::Result result)> RegisterCallback;
@@ -54,44 +44,24 @@ class GCMProfileService : public KeyedService,
typedef base::Callback<void(const GCMClient::GCMStatistics& stats)>
RequestGCMStatisticsCallback;
- // Any change made to this enum should have corresponding change in the
- // GetGCMEnabledStateString(...) function.
- enum GCMEnabledState {
- // GCM is always enabled. GCMClient will always load and connect with GCM.
- ALWAYS_ENABLED,
- // GCM is only enabled for apps. GCMClient will start to load and connect
- // with GCM only when GCM API is used.
- ENABLED_FOR_APPS,
- // GCM is always disabled. GCMClient will never load and connect with GCM.
- ALWAYS_DISABLED
- };
-
- // Returns the GCM enabled state.
- static GCMEnabledState GetGCMEnabledState(Profile* profile);
-
- // Returns text representation of a GCMEnabledState enum entry.
- static std::string GetGCMEnabledStateString(GCMEnabledState state);
+ explicit GCMService(scoped_ptr<IdentityProvider> identity_provider);
+ virtual ~GCMService();
- // Register profile-specific prefs for GCM.
- static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
-
- explicit GCMProfileService(Profile* profile);
- virtual ~GCMProfileService();
-
- void Initialize(scoped_ptr<GCMClientFactory> gcm_client_factory);
+ virtual void Initialize(scoped_ptr<GCMClientFactory> gcm_client_factory);
void Start();
void Stop();
- // KeyedService implementation.
- virtual void Shutdown() OVERRIDE;
+ // This method must be called before destroying the GCMService. Once it has
+ // been called, no other GCMService methods may be used.
+ virtual void Shutdown();
jianli 2014/04/18 01:49:44 GCMProfileService is inherited from both GCMServic
bartfab (slow) 2014/04/22 17:51:07 Done.
// Adds a handler for a given app.
- virtual void AddAppHandler(const std::string& app_id, GCMAppHandler* handler);
+ void AddAppHandler(const std::string& app_id, GCMAppHandler* handler);
// Remove the handler for a given app.
- virtual void RemoveAppHandler(const std::string& app_id);
+ void RemoveAppHandler(const std::string& app_id);
// Registers |sender_id| for an app. A registration ID will be returned by
// the GCM server.
@@ -123,8 +93,8 @@ class GCMProfileService : public KeyedService,
// For testing purpose.
GCMClient* GetGCMClientForTesting() const;
- // Returns the user name if the profile is signed in.
- std::string SignedInUserName() const;
+ // Returns true if the service was started.
+ bool IsStarted() const;
// Returns true if the gcm client is ready.
bool IsGCMClientReady() const;
@@ -133,8 +103,25 @@ class GCMProfileService : public KeyedService,
// then stats won't be modified.
void RequestGCMStatistics(RequestGCMStatisticsCallback callback);
+ // IdentityProvider::Observer:
+ virtual void OnLogin() OVERRIDE;
+ virtual void OnLogout() OVERRIDE;
Munjal (Google) 2014/04/17 18:51:25 We should remove dependency on login / logout conc
bartfab (slow) 2014/04/22 17:51:07 As commented by Jian, he is working on a design th
+
+ protected:
+ virtual bool StartAutomatically() const = 0;
jianli 2014/04/18 01:49:44 CanStartAutomatically?
bartfab (slow) 2014/04/22 17:51:07 GCM always can start automatically. The question i
+
+ virtual base::FilePath GetStorePath() const = 0;
+
+ virtual scoped_refptr<net::URLRequestContextGetter>
+ GetURLRequestContextGetter() const = 0;
+
+ // Resets the GCMClient instance.
+ void ResetGCMClient();
+
+ scoped_ptr<IdentityProvider> identity_provider_;
+
private:
- friend class GCMProfileServiceTestConsumer;
+ friend class TestGCMServiceWrapper;
friend class extensions::ExtensionGCMAppHandlerTest;
class DelayedTaskController;
@@ -142,31 +129,16 @@ class GCMProfileService : public KeyedService,
typedef std::map<std::string, GCMAppHandler*> GCMAppHandlerMap;
- // Overridden from content::NotificationObserver:
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
-
- // Overridden from SigninManagerBase::Observer:
- virtual void GoogleSigninSucceeded(const std::string& username,
- const std::string& password) OVERRIDE;
- virtual void GoogleSignedOut(const std::string& username) OVERRIDE;
-
- // Ensures that the GCMClient is loaded and the GCM check-in is done when
- // the profile was signed in.
+ // Ensures that the GCMClient is loaded and the GCM check-in is done if the
+ // |identity_provider_| is able to supply an account ID.
void EnsureLoaded();
// Remove cached data when GCM service is stopped.
void RemoveCachedData();
- // Checks out of GCM when the profile has been signed out. This will erase
- // all the cached and persisted data.
+ // Checks out of GCM and erases any cached and persisted data.
void CheckOut();
- // Resets the GCMClient instance. This is called when the profile is being
- // destroyed.
- void ResetGCMClient();
-
// Ensures that the app is ready for GCM functions and events.
GCMClient::Result EnsureAppReady(const std::string& app_id);
@@ -201,21 +173,18 @@ class GCMProfileService : public KeyedService,
void RequestGCMStatisticsFinished(GCMClient::GCMStatistics stats);
- // The profile which owns this object.
- Profile* profile_;
-
// Flag to indicate if GCMClient is ready.
bool gcm_client_ready_;
- // The username of the signed-in profile.
- std::string username_;
-
- content::NotificationRegistrar registrar_;
+ // The account ID that this service is responsible for. Empty when the service
+ // is not running.
+ std::string account_id_;
scoped_ptr<DelayedTaskController> delayed_task_controller_;
- // For all the work occured in IO thread.
- scoped_refptr<IOWorker> io_worker_;
+ // For all the work occurring on the IO thread. Must be destroyed on the IO
+ // thread.
+ scoped_ptr<IOWorker> io_worker_;
// App handler map (from app_id to handler pointer).
// The handler is not owned.
@@ -237,11 +206,11 @@ class GCMProfileService : public KeyedService,
RequestGCMStatisticsCallback request_gcm_statistics_callback_;
// Used to pass a weak pointer to the IO worker.
- base::WeakPtrFactory<GCMProfileService> weak_ptr_factory_;
+ base::WeakPtrFactory<GCMService> weak_ptr_factory_;
- DISALLOW_COPY_AND_ASSIGN(GCMProfileService);
+ DISALLOW_COPY_AND_ASSIGN(GCMService);
};
} // namespace gcm
-#endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_
+#endif // CHROME_BROWSER_SERVICES_GCM_GCM_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698