| 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 <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "components/pref_registry/pref_registry_syncable.h" | 13 #include "components/pref_registry/pref_registry_syncable.h" |
| 14 | 14 |
| 15 #if defined(OS_ANDROID) | 15 #if defined(OS_ANDROID) |
| 16 #include "components/gcm_driver/gcm_driver_android.h" | 16 #include "components/gcm_driver/gcm_driver_android.h" |
| 17 #else | 17 #else |
| 18 #include "base/bind.h" | 18 #include "base/bind.h" |
| 19 #if defined(OS_CHROMEOS) |
| 20 #include "chrome/browser/services/gcm/chromeos_gcm_app_handler.h" |
| 21 #endif |
| 19 #include "base/files/file_path.h" | 22 #include "base/files/file_path.h" |
| 20 #include "base/memory/weak_ptr.h" | 23 #include "base/memory/weak_ptr.h" |
| 21 #include "chrome/browser/services/gcm/gcm_account_tracker.h" | 24 #include "chrome/browser/services/gcm/gcm_account_tracker.h" |
| 22 #include "chrome/browser/services/gcm/gcm_desktop_utils.h" | 25 #include "chrome/browser/services/gcm/gcm_desktop_utils.h" |
| 23 #include "chrome/browser/signin/profile_identity_provider.h" | 26 #include "chrome/browser/signin/profile_identity_provider.h" |
| 24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 27 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 25 #include "chrome/browser/signin/signin_manager_factory.h" | 28 #include "chrome/browser/signin/signin_manager_factory.h" |
| 26 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 29 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 27 #include "chrome/common/chrome_constants.h" | 30 #include "chrome/common/chrome_constants.h" |
| 28 #include "components/gcm_driver/gcm_client_factory.h" | 31 #include "components/gcm_driver/gcm_client_factory.h" |
| 29 #include "components/gcm_driver/gcm_driver_desktop.h" | 32 #include "components/gcm_driver/gcm_driver_desktop.h" |
| 30 #include "components/signin/core/browser/signin_manager.h" | 33 #include "components/signin/core/browser/signin_manager.h" |
| 31 #include "google_apis/gaia/account_tracker.h" | 34 #include "google_apis/gaia/account_tracker.h" |
| 32 #include "google_apis/gaia/identity_provider.h" | 35 #include "google_apis/gaia/identity_provider.h" |
| 33 #include "net/url_request/url_request_context_getter.h" | 36 #include "net/url_request/url_request_context_getter.h" |
| 34 #endif | 37 #endif |
| 35 | 38 |
| 36 namespace gcm { | 39 namespace gcm { |
| 37 | 40 |
| 41 const char kGCMChromeOSAppHandlerId[] = "com.google.chrome.chromeos"; |
| 42 |
| 38 #if !defined(OS_ANDROID) | 43 #if !defined(OS_ANDROID) |
| 39 // Identity observer only has actual work to do when the user is actually signed | 44 // Identity observer only has actual work to do when the user is actually signed |
| 40 // in. It ensures that account tracker is taking | 45 // in. It ensures that account tracker is taking |
| 41 class GCMProfileService::IdentityObserver : public IdentityProvider::Observer { | 46 class GCMProfileService::IdentityObserver : public IdentityProvider::Observer { |
| 42 public: | 47 public: |
| 43 IdentityObserver(Profile* profile, GCMDriverDesktop* driver); | 48 IdentityObserver(Profile* profile, GCMDriverDesktop* driver); |
| 44 virtual ~IdentityObserver(); | 49 virtual ~IdentityObserver(); |
| 45 | 50 |
| 46 // IdentityProvider::Observer: | 51 // IdentityProvider::Observer: |
| 47 virtual void OnActiveAccountLogin() OVERRIDE; | 52 virtual void OnActiveAccountLogin() OVERRIDE; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 scoped_ptr<GCMClientFactory> gcm_client_factory) | 163 scoped_ptr<GCMClientFactory> gcm_client_factory) |
| 159 : profile_(profile), | 164 : profile_(profile), |
| 160 push_messaging_service_(this, profile) { | 165 push_messaging_service_(this, profile) { |
| 161 DCHECK(!profile->IsOffTheRecord()); | 166 DCHECK(!profile->IsOffTheRecord()); |
| 162 | 167 |
| 163 driver_ = CreateGCMDriverDesktop( | 168 driver_ = CreateGCMDriverDesktop( |
| 164 gcm_client_factory.Pass(), | 169 gcm_client_factory.Pass(), |
| 165 profile_->GetPath().Append(chrome::kGCMStoreDirname), | 170 profile_->GetPath().Append(chrome::kGCMStoreDirname), |
| 166 profile_->GetRequestContext()); | 171 profile_->GetRequestContext()); |
| 167 | 172 |
| 173 #ifdef CHROMEOS |
| 174 chromeos_app_handler_.reset(new gcm::ChromeOSGCMAppHandler); |
| 175 driver_->AddAppHandler(kGCMChromeOSAppHandlerId, chromeos_app_handler_.get()); |
| 176 #endif |
| 177 |
| 168 identity_observer_.reset(new IdentityObserver( | 178 identity_observer_.reset(new IdentityObserver( |
| 169 profile, static_cast<gcm::GCMDriverDesktop*>(driver_.get()))); | 179 profile, static_cast<gcm::GCMDriverDesktop*>(driver_.get()))); |
| 170 } | 180 } |
| 171 #endif // defined(OS_ANDROID) | 181 #endif // defined(OS_ANDROID) |
| 172 | 182 |
| 173 GCMProfileService::GCMProfileService() | 183 GCMProfileService::GCMProfileService() |
| 174 : profile_(NULL), | 184 : profile_(NULL), |
| 175 push_messaging_service_(this, NULL) { | 185 push_messaging_service_(this, NULL) { |
| 176 } | 186 } |
| 177 | 187 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 198 | 208 |
| 199 void GCMProfileService::Shutdown() { | 209 void GCMProfileService::Shutdown() { |
| 200 #if !defined(OS_ANDROID) | 210 #if !defined(OS_ANDROID) |
| 201 identity_observer_.reset(); | 211 identity_observer_.reset(); |
| 202 #endif // !defined(OS_ANDROID) | 212 #endif // !defined(OS_ANDROID) |
| 203 | 213 |
| 204 if (driver_) { | 214 if (driver_) { |
| 205 driver_->Shutdown(); | 215 driver_->Shutdown(); |
| 206 driver_.reset(); | 216 driver_.reset(); |
| 207 } | 217 } |
| 218 #ifdef CHROMEOS |
| 219 driver_->RemoveAppHandler(kGCMChromeOSAppHandlerId); |
| 220 #endif |
| 208 } | 221 } |
| 209 | 222 |
| 210 std::string GCMProfileService::SignedInUserName() const { | 223 std::string GCMProfileService::SignedInUserName() const { |
| 211 #if defined(OS_ANDROID) | 224 #if defined(OS_ANDROID) |
| 212 return std::string(); | 225 return std::string(); |
| 213 #else | 226 #else |
| 214 return identity_observer_ ? identity_observer_->SignedInUserName() | 227 return identity_observer_ ? identity_observer_->SignedInUserName() |
| 215 : std::string(); | 228 : std::string(); |
| 216 #endif // defined(OS_ANDROID) | 229 #endif // defined(OS_ANDROID) |
| 217 } | 230 } |
| 218 | 231 |
| 219 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { | 232 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { |
| 220 driver_.reset(driver); | 233 driver_.reset(driver); |
| 221 } | 234 } |
| 222 | 235 |
| 223 } // namespace gcm | 236 } // namespace gcm |
| OLD | NEW |