1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_
6 #define CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chrome/browser/services/gcm/push_messaging_service_impl.h"
14 // TODO(jianli): include needed for obsolete methods that are going to be
16 #include "components/gcm_driver/gcm_driver.h"
17 #include "components/keyed_service/core/keyed_service.h"
21 namespace user_prefs {
22 class PrefRegistrySyncable;
27 class GCMClientFactory;
30 // Providing GCM service, via GCMDriver, to a profile.
31 class GCMProfileService : public KeyedService {
33 // Returns whether GCM is enabled for |profile|.
34 static bool IsGCMEnabled(Profile* profile);
36 // Register profile-specific prefs for GCM.
37 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
39 #if defined(OS_ANDROID)
40 explicit GCMProfileService(Profile* profile);
42 GCMProfileService(Profile* profile,
43 scoped_ptr<GCMClientFactory> gcm_client_factory);
45 virtual ~GCMProfileService();
47 // TODO(jianli): obsolete methods that are going to be removed soon.
48 void AddAppHandler(const std::string& app_id, GCMAppHandler* handler);
49 void RemoveAppHandler(const std::string& app_id);
50 void Register(const std::string& app_id,
51 const std::vector<std::string>& sender_ids,
52 const GCMDriver::RegisterCallback& callback);
55 virtual void Shutdown() OVERRIDE;
57 // Returns the user name if the profile is signed in or an empty string
59 // TODO(jianli): To be removed when sign-in enforcement is dropped.
60 std::string SignedInUserName() const;
62 // For testing purpose.
63 void SetDriverForTesting(GCMDriver* driver);
65 GCMDriver* driver() const { return driver_.get(); }
67 content::PushMessagingService* push_messaging_service() {
68 return &push_messaging_service_;
72 // Used for constructing fake GCMProfileService for testing purpose.
76 // The profile which owns this object.
79 scoped_ptr<GCMDriver> driver_;
81 // Implementation of content::PushMessagingService using GCMProfileService.
82 PushMessagingServiceImpl push_messaging_service_;
84 // TODO(jianli): To be removed when sign-in enforcement is dropped.
85 #if !defined(OS_ANDROID)
86 class IdentityObserver;
87 scoped_ptr<IdentityObserver> identity_observer_;
89 #if defined(OS_CHROMEOS)
90 scoped_ptr<GCMConnectionObserver> chromeos_connection_observer_;
93 DISALLOW_COPY_AND_ASSIGN(GCMProfileService);
98 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_