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" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 } | 51 } |
52 #else | 52 #else |
53 GCMProfileService::GCMProfileService( | 53 GCMProfileService::GCMProfileService( |
54 Profile* profile, | 54 Profile* profile, |
55 scoped_ptr<GCMClientFactory> gcm_client_factory) | 55 scoped_ptr<GCMClientFactory> gcm_client_factory) |
56 : profile_(profile) { | 56 : profile_(profile) { |
57 DCHECK(!profile->IsOffTheRecord()); | 57 DCHECK(!profile->IsOffTheRecord()); |
58 | 58 |
59 driver_ = CreateGCMDriverDesktop( | 59 driver_ = CreateGCMDriverDesktop( |
60 gcm_client_factory.Pass(), | 60 gcm_client_factory.Pass(), |
61 scoped_ptr<IdentityProvider>(new ProfileIdentityProvider( | |
62 SigninManagerFactory::GetForProfile(profile_), | |
63 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), | |
64 LoginUIServiceFactory::GetForProfile(profile_))), | |
65 profile_->GetPath().Append(chrome::kGCMStoreDirname), | 61 profile_->GetPath().Append(chrome::kGCMStoreDirname), |
66 profile_->GetRequestContext()); | 62 profile_->GetRequestContext()); |
63 | |
64 identity_provider_.reset(new ProfileIdentityProvider( | |
65 SigninManagerFactory::GetForProfile(profile_), | |
66 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), | |
67 LoginUIServiceFactory::GetForProfile(profile_))); | |
68 identity_provider_->AddObserver(this); | |
69 | |
70 OnActiveAccountLogin(); | |
67 } | 71 } |
68 #endif // defined(OS_ANDROID) | 72 #endif // defined(OS_ANDROID) |
69 | 73 |
70 GCMProfileService::GCMProfileService() : profile_(NULL) { | 74 GCMProfileService::GCMProfileService() : profile_(NULL) { |
71 } | 75 } |
72 | 76 |
73 GCMProfileService::~GCMProfileService() { | 77 GCMProfileService::~GCMProfileService() { |
74 } | 78 } |
75 | 79 |
76 void GCMProfileService::AddAppHandler(const std::string& app_id, | 80 void GCMProfileService::AddAppHandler(const std::string& app_id, |
(...skipping 12 matching lines...) Expand all Loading... | |
89 const GCMDriver::RegisterCallback& callback) { | 93 const GCMDriver::RegisterCallback& callback) { |
90 if (driver_) | 94 if (driver_) |
91 driver_->Register(app_id, sender_ids, callback); | 95 driver_->Register(app_id, sender_ids, callback); |
92 } | 96 } |
93 | 97 |
94 void GCMProfileService::Shutdown() { | 98 void GCMProfileService::Shutdown() { |
95 if (driver_) { | 99 if (driver_) { |
96 driver_->Shutdown(); | 100 driver_->Shutdown(); |
97 driver_.reset(); | 101 driver_.reset(); |
98 } | 102 } |
103 | |
104 #if !defined(OS_ANDROID) | |
105 if (identity_provider_) { | |
106 identity_provider_->RemoveObserver(this); | |
107 identity_provider_.reset(); | |
108 } | |
109 #endif // !defined(OS_ANDROID) | |
110 } | |
111 | |
112 #if !defined(OS_ANDROID) | |
113 void GCMProfileService::OnActiveAccountLogin() { | |
114 if (!driver_) | |
115 return; | |
116 | |
117 // This might be called multiple times when the password changes. | |
118 std::string account_id = identity_provider_->GetActiveAccountId(); | |
bartfab (slow)
2014/06/13 11:27:21
Nit: const.
jianli
2014/06/13 18:04:48
Done.
| |
119 if (account_id == account_id_) | |
120 return; | |
121 account_id_ = account_id; | |
122 | |
123 driver_->SignIn(); | |
124 } | |
125 | |
126 void GCMProfileService::OnActiveAccountLogout() { | |
127 if (driver_) | |
128 driver_->Purge(); | |
129 } | |
130 #endif // !defined(OS_ANDROID) | |
131 | |
132 std::string GCMProfileService::SignedInUserName() const { | |
133 #if !defined(OS_ANDROID) | |
134 if (driver_.get() && driver_->IsStarted()) | |
bartfab (slow)
2014/06/13 11:27:21
Nit: scoped_ptr is testable. No need for .get():
jianli
2014/06/13 18:04:48
Done.
| |
135 return account_id_; | |
136 #endif // !defined(OS_ANDROID) | |
137 return std::string(); | |
99 } | 138 } |
100 | 139 |
101 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { | 140 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { |
102 driver_.reset(driver); | 141 driver_.reset(driver); |
103 } | 142 } |
104 | 143 |
105 } // namespace gcm | 144 } // namespace gcm |
OLD | NEW |