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

Side by Side Diff: chrome/browser/policy/cloud/user_policy_signin_service_base.cc

Issue 23068005: Convert UserPolicySigninService to use OAuth2TokenService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT Created 7 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/policy/cloud/user_policy_signin_service_base.h" 5 #include "chrome/browser/policy/cloud/user_policy_signin_service_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // Now initiate a policy fetch. 65 // Now initiate a policy fetch.
66 manager->core()->service()->RefreshPolicy(callback); 66 manager->core()->service()->RefreshPolicy(callback);
67 } 67 }
68 68
69 void UserPolicySigninServiceBase::Observe( 69 void UserPolicySigninServiceBase::Observe(
70 int type, 70 int type,
71 const content::NotificationSource& source, 71 const content::NotificationSource& source,
72 const content::NotificationDetails& details) { 72 const content::NotificationDetails& details) {
73 // If using a TestingProfile with no SigninManager or UserCloudPolicyManager, 73 // If using a TestingProfile with no SigninManager or UserCloudPolicyManager,
74 // skip initialization. 74 // skip initialization.
75 if (!GetManager() || !SigninManagerFactory::GetForProfile(profile_)) { 75 if (!GetManager() || !GetSigninManager()) {
76 DVLOG(1) << "Skipping initialization for tests due to missing components."; 76 DVLOG(1) << "Skipping initialization for tests due to missing components.";
77 return; 77 return;
78 } 78 }
79 79
80 switch (type) { 80 switch (type) {
81 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT: 81 case chrome::NOTIFICATION_GOOGLE_SIGNED_OUT:
82 ShutdownUserCloudPolicyManager(); 82 ShutdownUserCloudPolicyManager();
83 break; 83 break;
84 case chrome::NOTIFICATION_PROFILE_ADDED: 84 case chrome::NOTIFICATION_PROFILE_ADDED:
85 // A new profile has been loaded - if it's signed in, then initialize the 85 // A new profile has been loaded - if it's signed in, then initialize the
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 base::Bind( 126 base::Bind(
127 &UserPolicySigninServiceBase::ShutdownUserCloudPolicyManager, 127 &UserPolicySigninServiceBase::ShutdownUserCloudPolicyManager,
128 weak_factory_.GetWeakPtr())); 128 weak_factory_.GetWeakPtr()));
129 } else { 129 } else {
130 DVLOG(1) << "Error fetching policy: " << client->status(); 130 DVLOG(1) << "Error fetching policy: " << client->status();
131 } 131 }
132 } 132 }
133 } 133 }
134 134
135 void UserPolicySigninServiceBase::Shutdown() { 135 void UserPolicySigninServiceBase::Shutdown() {
136 PrepareForUserCloudPolicyManagerShutdown();
137 }
138
139 void UserPolicySigninServiceBase::PrepareForUserCloudPolicyManagerShutdown() {
136 UserCloudPolicyManager* manager = GetManager(); 140 UserCloudPolicyManager* manager = GetManager();
137 if (manager && manager->core()->client()) 141 if (manager && manager->core()->client())
138 manager->core()->client()->RemoveObserver(this); 142 manager->core()->client()->RemoveObserver(this);
139 if (manager && manager->core()->service()) 143 if (manager && manager->core()->service())
140 manager->core()->service()->RemoveObserver(this); 144 manager->core()->service()->RemoveObserver(this);
141 } 145 }
142 146
143 // static 147 // static
144 bool UserPolicySigninServiceBase::ShouldForceLoadPolicy() { 148 bool UserPolicySigninServiceBase::ShouldForceLoadPolicy() {
145 return CommandLine::ForCurrentProcess()->HasSwitch( 149 return CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 28 matching lines...) Expand all
174 if (username.empty()) 178 if (username.empty())
175 return false; // Not signed in. 179 return false; // Not signed in.
176 180
177 if (ShouldForceLoadPolicy()) 181 if (ShouldForceLoadPolicy())
178 return true; 182 return true;
179 183
180 return !BrowserPolicyConnector::IsNonEnterpriseUser(username); 184 return !BrowserPolicyConnector::IsNonEnterpriseUser(username);
181 } 185 }
182 186
183 void UserPolicySigninServiceBase::InitializeOnProfileReady() { 187 void UserPolicySigninServiceBase::InitializeOnProfileReady() {
184 SigninManager* signin_manager = 188 std::string username = GetSigninManager()->GetAuthenticatedUsername();
185 SigninManagerFactory::GetForProfile(profile_);
186 std::string username = signin_manager->GetAuthenticatedUsername();
187 if (username.empty()) 189 if (username.empty())
188 ShutdownUserCloudPolicyManager(); 190 ShutdownUserCloudPolicyManager();
189 else 191 else
190 InitializeForSignedInUser(username); 192 InitializeForSignedInUser(username);
191 } 193 }
192 194
193 void UserPolicySigninServiceBase::InitializeForSignedInUser( 195 void UserPolicySigninServiceBase::InitializeForSignedInUser(
194 const std::string& username) { 196 const std::string& username) {
195 DCHECK(!username.empty()); 197 DCHECK(!username.empty());
196 if (!ShouldLoadPolicyForUser(username)) { 198 if (!ShouldLoadPolicyForUser(username)) {
(...skipping 26 matching lines...) Expand all
223 manager->Connect(local_state_, client.Pass()); 225 manager->Connect(local_state_, client.Pass());
224 DCHECK(manager->core()->service()); 226 DCHECK(manager->core()->service());
225 227
226 // Observe the client to detect errors fetching policy. 228 // Observe the client to detect errors fetching policy.
227 manager->core()->client()->AddObserver(this); 229 manager->core()->client()->AddObserver(this);
228 // Observe the service to determine when it's initialized. 230 // Observe the service to determine when it's initialized.
229 manager->core()->service()->AddObserver(this); 231 manager->core()->service()->AddObserver(this);
230 } 232 }
231 233
232 void UserPolicySigninServiceBase::ShutdownUserCloudPolicyManager() { 234 void UserPolicySigninServiceBase::ShutdownUserCloudPolicyManager() {
233 Shutdown(); 235 PrepareForUserCloudPolicyManagerShutdown();
234 UserCloudPolicyManager* manager = GetManager(); 236 UserCloudPolicyManager* manager = GetManager();
235 if (manager) 237 if (manager)
236 manager->DisconnectAndRemovePolicy(); 238 manager->DisconnectAndRemovePolicy();
237 } 239 }
238 240
239 UserCloudPolicyManager* UserPolicySigninServiceBase::GetManager() { 241 UserCloudPolicyManager* UserPolicySigninServiceBase::GetManager() {
240 return UserCloudPolicyManagerFactory::GetForProfile(profile_); 242 return UserCloudPolicyManagerFactory::GetForProfile(profile_);
241 } 243 }
242 244
245 SigninManager* UserPolicySigninServiceBase::GetSigninManager() {
246 return SigninManagerFactory::GetForProfile(profile_);
247 }
248
243 } // namespace policy 249 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698