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

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

Issue 330733002: Move IdentityProvider usage from GCMDriverDesktop to GCMProfileService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address feedback Created 6 years, 6 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 | Annotate | Revision Log
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 "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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #else 53 #else
54 GCMProfileService::GCMProfileService( 54 GCMProfileService::GCMProfileService(
55 Profile* profile, 55 Profile* profile,
56 scoped_ptr<GCMClientFactory> gcm_client_factory) 56 scoped_ptr<GCMClientFactory> gcm_client_factory)
57 : profile_(profile), 57 : profile_(profile),
58 push_messaging_service_(this) { 58 push_messaging_service_(this) {
59 DCHECK(!profile->IsOffTheRecord()); 59 DCHECK(!profile->IsOffTheRecord());
60 60
61 driver_ = CreateGCMDriverDesktop( 61 driver_ = CreateGCMDriverDesktop(
62 gcm_client_factory.Pass(), 62 gcm_client_factory.Pass(),
63 scoped_ptr<IdentityProvider>(new ProfileIdentityProvider(
64 SigninManagerFactory::GetForProfile(profile_),
65 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_),
66 LoginUIServiceFactory::GetForProfile(profile_))),
67 profile_->GetPath().Append(chrome::kGCMStoreDirname), 63 profile_->GetPath().Append(chrome::kGCMStoreDirname),
68 profile_->GetRequestContext()); 64 profile_->GetRequestContext());
65
66 identity_provider_.reset(new ProfileIdentityProvider(
67 SigninManagerFactory::GetForProfile(profile_),
68 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_),
69 LoginUIServiceFactory::GetForProfile(profile_)));
70 identity_provider_->AddObserver(this);
71
72 OnActiveAccountLogin();
69 } 73 }
70 #endif // defined(OS_ANDROID) 74 #endif // defined(OS_ANDROID)
71 75
72 GCMProfileService::GCMProfileService() 76 GCMProfileService::GCMProfileService()
73 : profile_(NULL), 77 : profile_(NULL),
74 push_messaging_service_(this) { 78 push_messaging_service_(this) {
75 } 79 }
76 80
77 GCMProfileService::~GCMProfileService() { 81 GCMProfileService::~GCMProfileService() {
78 } 82 }
(...skipping 14 matching lines...) Expand all
93 const GCMDriver::RegisterCallback& callback) { 97 const GCMDriver::RegisterCallback& callback) {
94 if (driver_) 98 if (driver_)
95 driver_->Register(app_id, sender_ids, callback); 99 driver_->Register(app_id, sender_ids, callback);
96 } 100 }
97 101
98 void GCMProfileService::Shutdown() { 102 void GCMProfileService::Shutdown() {
99 if (driver_) { 103 if (driver_) {
100 driver_->Shutdown(); 104 driver_->Shutdown();
101 driver_.reset(); 105 driver_.reset();
102 } 106 }
107
108 #if !defined(OS_ANDROID)
109 if (identity_provider_) {
110 identity_provider_->RemoveObserver(this);
111 identity_provider_.reset();
112 }
113 #endif // !defined(OS_ANDROID)
114 }
115
116 #if !defined(OS_ANDROID)
117 void GCMProfileService::OnActiveAccountLogin() {
118 if (!driver_)
119 return;
120
121 // This might be called multiple times when the password changes.
122 const std::string account_id = identity_provider_->GetActiveAccountId();
123 if (account_id == account_id_)
124 return;
125 account_id_ = account_id;
126
127 driver_->SignIn();
128 }
129
130 void GCMProfileService::OnActiveAccountLogout() {
131 if (driver_)
132 driver_->Purge();
133 }
134 #endif // !defined(OS_ANDROID)
135
136 std::string GCMProfileService::SignedInUserName() const {
137 #if !defined(OS_ANDROID)
138 if (driver_ && driver_->IsStarted())
139 return account_id_;
140 #endif // !defined(OS_ANDROID)
141 return std::string();
103 } 142 }
104 143
105 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { 144 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) {
106 driver_.reset(driver); 145 driver_.reset(driver);
107 } 146 }
108 147
109 } // namespace gcm 148 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698