OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/services/gcm/gcm_profile_service.h" | 5 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
11 #include "components/pref_registry/pref_registry_syncable.h" | 11 #include "components/pref_registry/pref_registry_syncable.h" |
12 | 12 |
13 #if defined(OS_ANDROID) | 13 #if defined(OS_ANDROID) |
14 #include "components/gcm_driver/gcm_driver_android.h" | 14 #include "components/gcm_driver/gcm_driver_android.h" |
15 #else | 15 #else |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #if defined(OS_CHROMEOS) | |
18 #include "chrome/browser/services/gcm/chromeos_gcm_app_handler.h" | |
19 #endif | |
17 #include "chrome/browser/services/gcm/gcm_desktop_utils.h" | 20 #include "chrome/browser/services/gcm/gcm_desktop_utils.h" |
18 #include "chrome/browser/signin/profile_identity_provider.h" | 21 #include "chrome/browser/signin/profile_identity_provider.h" |
19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 22 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
20 #include "chrome/browser/signin/signin_manager_factory.h" | 23 #include "chrome/browser/signin/signin_manager_factory.h" |
21 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 24 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
22 #include "chrome/common/chrome_constants.h" | 25 #include "chrome/common/chrome_constants.h" |
23 #include "components/gcm_driver/gcm_client_factory.h" | 26 #include "components/gcm_driver/gcm_client_factory.h" |
24 #include "components/signin/core/browser/signin_manager.h" | 27 #include "components/signin/core/browser/signin_manager.h" |
25 #include "google_apis/gaia/identity_provider.h" | 28 #include "google_apis/gaia/identity_provider.h" |
26 #include "net/url_request/url_request_context_getter.h" | 29 #include "net/url_request/url_request_context_getter.h" |
27 #endif | 30 #endif |
28 | 31 |
29 namespace gcm { | 32 namespace gcm { |
30 | 33 |
fgorski
2014/08/26 22:26:08
const char kGCMChromeOSAppHandlerId = "com.google.
Luigi Semenzato
2014/09/05 18:02:33
Done.
| |
31 #if !defined(OS_ANDROID) | 34 #if !defined(OS_ANDROID) |
32 class GCMProfileService::IdentityObserver : public IdentityProvider::Observer { | 35 class GCMProfileService::IdentityObserver : public IdentityProvider::Observer { |
33 public: | 36 public: |
34 IdentityObserver(Profile* profile, GCMDriver* driver); | 37 IdentityObserver(Profile* profile, GCMDriver* driver); |
35 virtual ~IdentityObserver(); | 38 virtual ~IdentityObserver(); |
36 | 39 |
37 // IdentityProvider::Observer: | 40 // IdentityProvider::Observer: |
38 virtual void OnActiveAccountLogin() OVERRIDE; | 41 virtual void OnActiveAccountLogin() OVERRIDE; |
39 virtual void OnActiveAccountLogout() OVERRIDE; | 42 virtual void OnActiveAccountLogout() OVERRIDE; |
40 | 43 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 scoped_ptr<GCMClientFactory> gcm_client_factory) | 117 scoped_ptr<GCMClientFactory> gcm_client_factory) |
115 : profile_(profile), | 118 : profile_(profile), |
116 push_messaging_service_(this) { | 119 push_messaging_service_(this) { |
117 DCHECK(!profile->IsOffTheRecord()); | 120 DCHECK(!profile->IsOffTheRecord()); |
118 | 121 |
119 driver_ = CreateGCMDriverDesktop( | 122 driver_ = CreateGCMDriverDesktop( |
120 gcm_client_factory.Pass(), | 123 gcm_client_factory.Pass(), |
121 profile_->GetPath().Append(chrome::kGCMStoreDirname), | 124 profile_->GetPath().Append(chrome::kGCMStoreDirname), |
122 profile_->GetRequestContext()); | 125 profile_->GetRequestContext()); |
123 | 126 |
127 #ifdef CHROMEOS | |
128 chromeos_app_handler_ = new gcm::ChromeOSGCMAppHandler(); | |
129 driver_->AddAppHandler("com.google.chrome.chromeos", chromeos_app_handler_); | |
fgorski
2014/08/26 22:26:08
chromeos_app_handler_.reset(new gcm::ChromeOSGCMAp
Luigi Semenzato
2014/09/05 18:02:33
Done.
| |
130 #endif | |
131 | |
124 identity_observer_.reset(new IdentityObserver(profile, driver_.get())); | 132 identity_observer_.reset(new IdentityObserver(profile, driver_.get())); |
125 } | 133 } |
126 #endif // defined(OS_ANDROID) | 134 #endif // defined(OS_ANDROID) |
127 | 135 |
128 GCMProfileService::GCMProfileService() | 136 GCMProfileService::GCMProfileService() |
129 : profile_(NULL), | 137 : profile_(NULL), |
130 push_messaging_service_(this) { | 138 push_messaging_service_(this) { |
131 } | 139 } |
132 | 140 |
133 GCMProfileService::~GCMProfileService() { | 141 GCMProfileService::~GCMProfileService() { |
(...skipping 19 matching lines...) Expand all Loading... | |
153 | 161 |
154 void GCMProfileService::Shutdown() { | 162 void GCMProfileService::Shutdown() { |
155 #if !defined(OS_ANDROID) | 163 #if !defined(OS_ANDROID) |
156 identity_observer_.reset(); | 164 identity_observer_.reset(); |
157 #endif // !defined(OS_ANDROID) | 165 #endif // !defined(OS_ANDROID) |
158 | 166 |
159 if (driver_) { | 167 if (driver_) { |
160 driver_->Shutdown(); | 168 driver_->Shutdown(); |
161 driver_.reset(); | 169 driver_.reset(); |
162 } | 170 } |
171 #ifdef CHROMEOS | |
172 delete chromeos_app_handler_; | |
fgorski
2014/08/26 22:26:08
driver_->RemoveAppHandler(kGCMChromeOSAppHandlerId
Luigi Semenzato
2014/09/05 18:02:33
Done.
| |
173 #endif | |
163 } | 174 } |
164 | 175 |
165 std::string GCMProfileService::SignedInUserName() const { | 176 std::string GCMProfileService::SignedInUserName() const { |
166 #if defined(OS_ANDROID) | 177 #if defined(OS_ANDROID) |
167 return std::string(); | 178 return std::string(); |
168 #else | 179 #else |
169 return identity_observer_ ? identity_observer_->SignedInUserName() | 180 return identity_observer_ ? identity_observer_->SignedInUserName() |
170 : std::string(); | 181 : std::string(); |
171 #endif // defined(OS_ANDROID) | 182 #endif // defined(OS_ANDROID) |
172 } | 183 } |
173 | 184 |
174 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { | 185 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { |
175 driver_.reset(driver); | 186 driver_.reset(driver); |
176 } | 187 } |
177 | 188 |
178 } // namespace gcm | 189 } // namespace gcm |
OLD | NEW |