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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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(Profile* profile) |
77 : GCMDriver(scoped_ptr<IdentityProvider>(new ProfileIdentityProvider( | 79 : profile_(profile) { |
78 SigninManagerFactory::GetForProfile(profile), | |
79 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | |
80 #if defined(OS_ANDROID) | |
81 NULL))), | |
82 #else | |
83 LoginUIServiceFactory::GetForProfile(profile)))), | |
84 #endif | |
85 profile_(profile) { | |
86 DCHECK(!profile->IsOffTheRecord()); | 80 DCHECK(!profile->IsOffTheRecord()); |
87 } | 81 } |
88 | 82 |
89 GCMProfileService::~GCMProfileService() { | 83 GCMProfileService::~GCMProfileService() { |
90 } | 84 } |
91 | 85 |
92 void GCMProfileService::Shutdown() { | 86 void GCMProfileService::Initialize( |
93 ShutdownService(); | 87 scoped_ptr<GCMClientFactory> gcm_client_factory) { |
88 DCHECK(!driver_); | |
89 | |
90 driver_.reset(new GCMDriver( | |
Nicolas Zea
2014/05/19 21:04:06
I wonder if this entire section should be in a if
jianli
2014/05/19 23:03:48
Done.
jianli
2014/05/20 17:37:23
Indeed we still need to create GCMDriver instance
| |
91 gcm_client_factory.Pass(), | |
92 scoped_ptr<IdentityProvider>(new ProfileIdentityProvider( | |
93 SigninManagerFactory::GetForProfile(profile_), | |
94 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), | |
95 #if defined(OS_ANDROID) | |
96 NULL)), | |
97 #else | |
98 LoginUIServiceFactory::GetForProfile(profile_))), | |
99 #endif | |
100 profile_->GetPath().Append(chrome::kGCMStoreDirname), | |
101 profile_->GetRequestContext())); | |
94 } | 102 } |
95 | 103 |
96 std::string GCMProfileService::SignedInUserName() const { | 104 void GCMProfileService::Shutdown() { |
97 if (IsStarted()) | 105 if (driver_) |
98 return identity_provider_->GetActiveUsername(); | 106 driver_->Shutdown(); |
Nicolas Zea
2014/05/19 21:04:06
should we also driver_.reset() here?
jianli
2014/05/19 23:03:48
Done.
| |
99 return std::string(); | |
100 } | 107 } |
101 | 108 |
102 bool GCMProfileService::ShouldStartAutomatically() const { | 109 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { |
103 return GetGCMEnabledState(profile_) == ALWAYS_ENABLED; | 110 driver_.reset(driver); |
104 } | |
105 | |
106 base::FilePath GCMProfileService::GetStorePath() const { | |
107 return profile_->GetPath().Append(chrome::kGCMStoreDirname); | |
108 } | |
109 | |
110 scoped_refptr<net::URLRequestContextGetter> | |
111 GCMProfileService::GetURLRequestContextGetter() const { | |
112 return profile_->GetRequestContext(); | |
113 } | 111 } |
114 | 112 |
115 } // namespace gcm | 113 } // namespace gcm |
OLD | NEW |