Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / services / gcm / gcm_profile_service.h
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.
4
5 #ifndef CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_
6 #define CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_
7
8 #include <string>
9
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
15 // removed soon.
16 #include "components/gcm_driver/gcm_driver.h"
17 #include "components/keyed_service/core/keyed_service.h"
18
19 class Profile;
20
21 namespace user_prefs {
22 class PrefRegistrySyncable;
23 }
24
25 namespace gcm {
26
27 class GCMClientFactory;
28 class GCMDriver;
29
30 // Providing GCM service, via GCMDriver, to a profile.
31 class GCMProfileService : public KeyedService {
32  public:
33   // Returns whether GCM is enabled for |profile|.
34   static bool IsGCMEnabled(Profile* profile);
35
36   // Register profile-specific prefs for GCM.
37   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
38
39 #if defined(OS_ANDROID)
40   explicit GCMProfileService(Profile* profile);
41 #else
42   GCMProfileService(Profile* profile,
43                     scoped_ptr<GCMClientFactory> gcm_client_factory);
44 #endif
45   virtual ~GCMProfileService();
46
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);
53
54   // KeyedService:
55   virtual void Shutdown() OVERRIDE;
56
57   // Returns the user name if the profile is signed in or an empty string
58   // otherwise.
59   // TODO(jianli): To be removed when sign-in enforcement is dropped.
60   std::string SignedInUserName() const;
61
62   // For testing purpose.
63   void SetDriverForTesting(GCMDriver* driver);
64
65   GCMDriver* driver() const { return driver_.get(); }
66
67   content::PushMessagingService* push_messaging_service() {
68     return &push_messaging_service_;
69   }
70
71  protected:
72   // Used for constructing fake GCMProfileService for testing purpose.
73   GCMProfileService();
74
75  private:
76   // The profile which owns this object.
77   Profile* profile_;
78
79   scoped_ptr<GCMDriver> driver_;
80
81   // Implementation of content::PushMessagingService using GCMProfileService.
82   PushMessagingServiceImpl push_messaging_service_;
83
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_;
88 #endif
89 #if defined(OS_CHROMEOS)
90   scoped_ptr<GCMConnectionObserver> chromeos_connection_observer_;
91 #endif
92
93   DISALLOW_COPY_AND_ASSIGN(GCMProfileService);
94 };
95
96 }  // namespace gcm
97
98 #endif  // CHROME_BROWSER_SERVICES_GCM_GCM_PROFILE_SERVICE_H_