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/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/services/gcm/gcm_driver.h" |
12 #include "chrome/browser/signin/profile_identity_provider.h" | 13 #include "chrome/browser/signin/profile_identity_provider.h" |
13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
14 #include "chrome/browser/signin/signin_manager_factory.h" | 15 #include "chrome/browser/signin/signin_manager_factory.h" |
15 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
16 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 #include "components/gcm_driver/gcm_client_factory.h" |
18 #include "components/pref_registry/pref_registry_syncable.h" | 20 #include "components/pref_registry/pref_registry_syncable.h" |
19 #include "components/signin/core/browser/signin_manager.h" | 21 #include "components/signin/core/browser/signin_manager.h" |
20 #include "google_apis/gaia/identity_provider.h" | 22 #include "google_apis/gaia/identity_provider.h" |
21 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
22 | 24 |
23 #if !defined(OS_ANDROID) | 25 #if !defined(OS_ANDROID) |
24 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 26 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
25 #endif | 27 #endif |
26 | 28 |
27 namespace gcm { | 29 namespace gcm { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 channel == chrome::VersionInfo::CHANNEL_CANARY || | 68 channel == chrome::VersionInfo::CHANNEL_CANARY || |
67 channel == chrome::VersionInfo::CHANNEL_DEV) { | 69 channel == chrome::VersionInfo::CHANNEL_DEV) { |
68 on_by_default = true; | 70 on_by_default = true; |
69 } | 71 } |
70 registry->RegisterBooleanPref( | 72 registry->RegisterBooleanPref( |
71 prefs::kGCMChannelEnabled, | 73 prefs::kGCMChannelEnabled, |
72 on_by_default, | 74 on_by_default, |
73 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 75 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
74 } | 76 } |
75 | 77 |
76 GCMProfileService::GCMProfileService(Profile* profile) | 78 GCMProfileService::GCMProfileService( |
77 : GCMDriver(scoped_ptr<IdentityProvider>(new ProfileIdentityProvider( | 79 Profile* profile, |
78 SigninManagerFactory::GetForProfile(profile), | 80 scoped_ptr<GCMClientFactory> gcm_client_factory) |
79 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | 81 : profile_(profile) { |
| 82 DCHECK(!profile->IsOffTheRecord()); |
| 83 |
80 #if defined(OS_ANDROID) | 84 #if defined(OS_ANDROID) |
81 NULL))), | 85 LoginUIService* login_ui_service = NULL; |
82 #else | 86 #else |
83 LoginUIServiceFactory::GetForProfile(profile)))), | 87 LoginUIService* login_ui_service = |
| 88 LoginUIServiceFactory::GetForProfile(profile_); |
84 #endif | 89 #endif |
85 profile_(profile) { | 90 driver_.reset(new GCMDriver( |
86 DCHECK(!profile->IsOffTheRecord()); | 91 gcm_client_factory.Pass(), |
| 92 scoped_ptr<IdentityProvider>(new ProfileIdentityProvider( |
| 93 SigninManagerFactory::GetForProfile(profile_), |
| 94 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), |
| 95 login_ui_service)), |
| 96 profile_->GetPath().Append(chrome::kGCMStoreDirname), |
| 97 profile_->GetRequestContext())); |
| 98 } |
| 99 |
| 100 GCMProfileService::GCMProfileService() : profile_(NULL) { |
87 } | 101 } |
88 | 102 |
89 GCMProfileService::~GCMProfileService() { | 103 GCMProfileService::~GCMProfileService() { |
90 } | 104 } |
91 | 105 |
92 void GCMProfileService::Shutdown() { | 106 void GCMProfileService::AddAppHandler(const std::string& app_id, |
93 ShutdownService(); | 107 GCMAppHandler* handler) { |
| 108 if (driver_) |
| 109 driver_->AddAppHandler(app_id, handler); |
94 } | 110 } |
95 | 111 |
96 std::string GCMProfileService::SignedInUserName() const { | 112 void GCMProfileService::RemoveAppHandler(const std::string& app_id) { |
97 if (IsStarted()) | 113 if (driver_) |
98 return identity_provider_->GetActiveUsername(); | 114 driver_->RemoveAppHandler(app_id); |
99 return std::string(); | |
100 } | 115 } |
101 | 116 |
102 bool GCMProfileService::ShouldStartAutomatically() const { | 117 void GCMProfileService::Register(const std::string& app_id, |
103 return GetGCMEnabledState(profile_) == ALWAYS_ENABLED; | 118 const std::vector<std::string>& sender_ids, |
| 119 const GCMDriver::RegisterCallback& callback) { |
| 120 if (driver_) |
| 121 driver_->Register(app_id, sender_ids, callback); |
104 } | 122 } |
105 | 123 |
106 base::FilePath GCMProfileService::GetStorePath() const { | 124 void GCMProfileService::Shutdown() { |
107 return profile_->GetPath().Append(chrome::kGCMStoreDirname); | 125 if (driver_) { |
| 126 driver_->Shutdown(); |
| 127 driver_.reset(); |
| 128 } |
108 } | 129 } |
109 | 130 |
110 scoped_refptr<net::URLRequestContextGetter> | 131 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { |
111 GCMProfileService::GetURLRequestContextGetter() const { | 132 driver_.reset(driver); |
112 return profile_->GetRequestContext(); | |
113 } | 133 } |
114 | 134 |
115 } // namespace gcm | 135 } // namespace gcm |
OLD | NEW |