Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1118)

Side by Side Diff: chrome/browser/services/gcm/gcm_profile_service.cc

Issue 594383003: [GCM] Passing GCMClient::AccountTokenInfo list to GCMDriver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@account-mapper
Patch Set: Rebased Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
jianli 2014/09/25 20:26:45 Please update this to vector.
fgorski 2014/09/26 22:51:42 Done.
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
(...skipping 18 matching lines...) Expand all
36 #include "net/url_request/url_request_context_getter.h" 36 #include "net/url_request/url_request_context_getter.h"
37 #endif 37 #endif
38 38
39 namespace gcm { 39 namespace gcm {
40 40
41 #if !defined(OS_ANDROID) 41 #if !defined(OS_ANDROID)
42 // Identity observer only has actual work to do when the user is actually signed 42 // Identity observer only has actual work to do when the user is actually signed
43 // in. It ensures that account tracker is taking 43 // in. It ensures that account tracker is taking
44 class GCMProfileService::IdentityObserver : public IdentityProvider::Observer { 44 class GCMProfileService::IdentityObserver : public IdentityProvider::Observer {
45 public: 45 public:
46 IdentityObserver(Profile* profile, GCMDriverDesktop* driver); 46 IdentityObserver(Profile* profile, GCMDriver* driver);
47 virtual ~IdentityObserver(); 47 virtual ~IdentityObserver();
48 48
49 // IdentityProvider::Observer: 49 // IdentityProvider::Observer:
50 virtual void OnActiveAccountLogin() OVERRIDE; 50 virtual void OnActiveAccountLogin() OVERRIDE;
51 virtual void OnActiveAccountLogout() OVERRIDE; 51 virtual void OnActiveAccountLogout() OVERRIDE;
52 52
53 std::string SignedInUserName() const; 53 std::string SignedInUserName() const;
54 54
55 // Called to inform IdentityObserver that a list of accounts was updated. 55 // Called to inform IdentityObserver that a list of accounts was updated.
56 // |account_tokens| maps email addresses to OAuth2 access tokens. 56 // |account_tokens| maps email addresses to OAuth2 access tokens.
jianli 2014/09/25 20:26:45 Please update the comment here.
fgorski 2014/09/26 22:51:42 Done.
57 void AccountsUpdated( 57 void AccountsUpdated(
58 const std::map<std::string, std::string>& account_tokens); 58 const std::vector<GCMClient::AccountTokenInfo>& account_tokens);
59 59
60 private: 60 private:
61 Profile* profile_; 61 Profile* profile_;
62 GCMDriverDesktop* driver_; 62 GCMDriver* driver_;
63 scoped_ptr<IdentityProvider> identity_provider_; 63 scoped_ptr<IdentityProvider> identity_provider_;
64 scoped_ptr<GCMAccountTracker> gcm_account_tracker_; 64 scoped_ptr<GCMAccountTracker> gcm_account_tracker_;
65 65
66 // The account ID that this service is responsible for. Empty when the service 66 // The account ID that this service is responsible for. Empty when the service
67 // is not running. 67 // is not running.
68 std::string account_id_; 68 std::string account_id_;
69 69
70 base::WeakPtrFactory<GCMProfileService::IdentityObserver> weak_ptr_factory_; 70 base::WeakPtrFactory<GCMProfileService::IdentityObserver> weak_ptr_factory_;
71 71
72 DISALLOW_COPY_AND_ASSIGN(IdentityObserver); 72 DISALLOW_COPY_AND_ASSIGN(IdentityObserver);
73 }; 73 };
74 74
75 GCMProfileService::IdentityObserver::IdentityObserver(Profile* profile, 75 GCMProfileService::IdentityObserver::IdentityObserver(Profile* profile,
76 GCMDriverDesktop* driver) 76 GCMDriver* driver)
77 : profile_(profile), driver_(driver), weak_ptr_factory_(this) { 77 : profile_(profile), driver_(driver), weak_ptr_factory_(this) {
78 identity_provider_.reset(new ProfileIdentityProvider( 78 identity_provider_.reset(new ProfileIdentityProvider(
79 SigninManagerFactory::GetForProfile(profile), 79 SigninManagerFactory::GetForProfile(profile),
80 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), 80 ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
81 LoginUIServiceFactory::GetForProfile(profile))); 81 LoginUIServiceFactory::GetForProfile(profile)));
82 identity_provider_->AddObserver(this); 82 identity_provider_->AddObserver(this);
83 83
84 OnActiveAccountLogin(); 84 OnActiveAccountLogin();
85 } 85 }
86 86
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // again. Otherwise, the user sign-out will not affect the existing GCM 124 // again. Otherwise, the user sign-out will not affect the existing GCM
125 // data. 125 // data.
126 driver_->OnSignedOut(); 126 driver_->OnSignedOut();
127 } 127 }
128 128
129 std::string GCMProfileService::IdentityObserver::SignedInUserName() const { 129 std::string GCMProfileService::IdentityObserver::SignedInUserName() const {
130 return driver_->IsStarted() ? account_id_ : std::string(); 130 return driver_->IsStarted() ? account_id_ : std::string();
131 } 131 }
132 132
133 void GCMProfileService::IdentityObserver::AccountsUpdated( 133 void GCMProfileService::IdentityObserver::AccountsUpdated(
134 const std::map<std::string, std::string>& account_tokens) { 134 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) {
135 driver_->SetAccountsForCheckin(account_tokens); 135 driver_->SetAccountTokens(account_tokens);
136 } 136 }
137 #endif // !defined(OS_ANDROID) 137 #endif // !defined(OS_ANDROID)
138 138
139 // static 139 // static
140 bool GCMProfileService::IsGCMEnabled(Profile* profile) { 140 bool GCMProfileService::IsGCMEnabled(Profile* profile) {
141 return profile->GetPrefs()->GetBoolean(prefs::kGCMChannelEnabled); 141 return profile->GetPrefs()->GetBoolean(prefs::kGCMChannelEnabled);
142 } 142 }
143 143
144 // static 144 // static
145 void GCMProfileService::RegisterProfilePrefs( 145 void GCMProfileService::RegisterProfilePrefs(
(...skipping 25 matching lines...) Expand all
171 gcm_client_factory.Pass(), 171 gcm_client_factory.Pass(),
172 profile_->GetPrefs(), 172 profile_->GetPrefs(),
173 profile_->GetPath().Append(chrome::kGCMStoreDirname), 173 profile_->GetPath().Append(chrome::kGCMStoreDirname),
174 profile_->GetRequestContext()); 174 profile_->GetRequestContext());
175 175
176 #if defined(OS_CHROMEOS) 176 #if defined(OS_CHROMEOS)
177 chromeos_connection_observer_.reset(new gcm::ChromeOSGCMConnectionObserver); 177 chromeos_connection_observer_.reset(new gcm::ChromeOSGCMConnectionObserver);
178 driver_->AddConnectionObserver(chromeos_connection_observer_.get()); 178 driver_->AddConnectionObserver(chromeos_connection_observer_.get());
179 #endif 179 #endif
180 180
181 identity_observer_.reset(new IdentityObserver( 181 identity_observer_.reset(new IdentityObserver(profile, driver_.get()));
182 profile, static_cast<gcm::GCMDriverDesktop*>(driver_.get())));
183 } 182 }
184 #endif // defined(OS_ANDROID) 183 #endif // defined(OS_ANDROID)
185 184
186 GCMProfileService::GCMProfileService() 185 GCMProfileService::GCMProfileService()
187 : profile_(NULL), 186 : profile_(NULL),
188 push_messaging_service_(this, NULL) { 187 push_messaging_service_(this, NULL) {
189 } 188 }
190 189
191 GCMProfileService::~GCMProfileService() { 190 GCMProfileService::~GCMProfileService() {
192 } 191 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 return identity_observer_ ? identity_observer_->SignedInUserName() 229 return identity_observer_ ? identity_observer_->SignedInUserName()
231 : std::string(); 230 : std::string();
232 #endif // defined(OS_ANDROID) 231 #endif // defined(OS_ANDROID)
233 } 232 }
234 233
235 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { 234 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) {
236 driver_.reset(driver); 235 driver_.reset(driver);
237 } 236 }
238 237
239 } // namespace gcm 238 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698