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

Side by Side Diff: chrome/browser/policy/cloud/user_policy_signin_service_android.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_android.h" 5 #include "chrome/browser/policy/cloud/user_policy_signin_service_android.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 21 matching lines...) Expand all
32 if (command_line->HasSwitch(switches::kFakeCloudPolicyType)) 32 if (command_line->HasSwitch(switches::kFakeCloudPolicyType))
33 return enterprise_management::DeviceRegisterRequest::BROWSER; 33 return enterprise_management::DeviceRegisterRequest::BROWSER;
34 return enterprise_management::DeviceRegisterRequest::ANDROID_BROWSER; 34 return enterprise_management::DeviceRegisterRequest::ANDROID_BROWSER;
35 } 35 }
36 36
37 } // namespace 37 } // namespace
38 38
39 UserPolicySigninService::UserPolicySigninService( 39 UserPolicySigninService::UserPolicySigninService(
40 Profile* profile, 40 Profile* profile,
41 PrefService* local_state, 41 PrefService* local_state,
42 DeviceManagementService* device_management_service) 42 DeviceManagementService* device_management_service,
43 SigninManager* signin_manager,
44 AndroidProfileOAuth2TokenService* token_service)
43 : UserPolicySigninServiceBase(profile, 45 : UserPolicySigninServiceBase(profile,
44 local_state, 46 local_state,
45 device_management_service), 47 device_management_service,
46 weak_factory_(this) {} 48 signin_manager),
49 weak_factory_(this),
50 oauth2_token_service_(token_service) {}
47 51
48 UserPolicySigninService::~UserPolicySigninService() {} 52 UserPolicySigninService::~UserPolicySigninService() {}
49 53
50 void UserPolicySigninService::RegisterPolicyClient( 54 void UserPolicySigninService::RegisterPolicyClient(
51 const std::string& username, 55 const std::string& username,
52 const PolicyRegistrationCallback& callback) { 56 const PolicyRegistrationCallback& callback) {
53 // Create a new CloudPolicyClient for fetching the DMToken. 57 // Create a new CloudPolicyClient for fetching the DMToken.
54 scoped_ptr<CloudPolicyClient> policy_client = PrepareToRegister(username); 58 scoped_ptr<CloudPolicyClient> policy_client = PrepareToRegister(username);
55 if (!policy_client) { 59 if (!policy_client) {
56 callback.Run(policy_client.Pass()); 60 callback.Run(policy_client.Pass());
57 return; 61 return;
58 } 62 }
59 63
60 CancelPendingRegistration(); 64 CancelPendingRegistration();
61 65
62 // Fire off the registration process. Callback keeps the CloudPolicyClient 66 // Fire off the registration process. Callback keeps the CloudPolicyClient
63 // alive for the length of the registration process. 67 // alive for the length of the registration process.
64 const bool force_load_policy = false; 68 const bool force_load_policy = false;
65 registration_helper_.reset(new CloudPolicyClientRegistrationHelper( 69 registration_helper_.reset(new CloudPolicyClientRegistrationHelper(
66 profile()->GetRequestContext(), 70 profile()->GetRequestContext(),
67 policy_client.get(), 71 policy_client.get(),
68 force_load_policy, 72 force_load_policy,
69 GetRegistrationType())); 73 GetRegistrationType()));
70 registration_helper_->StartRegistration( 74 registration_helper_->StartRegistration(
71 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()), 75 oauth2_token_service_,
72 username, 76 username,
73 base::Bind(&UserPolicySigninService::CallPolicyRegistrationCallback, 77 base::Bind(&UserPolicySigninService::CallPolicyRegistrationCallback,
74 base::Unretained(this), 78 base::Unretained(this),
75 base::Passed(&policy_client), 79 base::Passed(&policy_client),
76 callback)); 80 callback));
77 } 81 }
78 82
79 void UserPolicySigninService::CallPolicyRegistrationCallback( 83 void UserPolicySigninService::CallPolicyRegistrationCallback(
80 scoped_ptr<CloudPolicyClient> client, 84 scoped_ptr<CloudPolicyClient> client,
81 PolicyRegistrationCallback callback) { 85 PolicyRegistrationCallback callback) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 FROM_HERE, 134 FROM_HERE,
131 base::Bind(&UserPolicySigninService::RegisterCloudPolicyService, 135 base::Bind(&UserPolicySigninService::RegisterCloudPolicyService,
132 weak_factory_.GetWeakPtr()), 136 weak_factory_.GetWeakPtr()),
133 try_registration_delay); 137 try_registration_delay);
134 } 138 }
135 139
136 void UserPolicySigninService::RegisterCloudPolicyService() { 140 void UserPolicySigninService::RegisterCloudPolicyService() {
137 // If the user signed-out while this task was waiting then Shutdown() would 141 // If the user signed-out while this task was waiting then Shutdown() would
138 // have been called, which would have invalidated this task. Since we're here 142 // have been called, which would have invalidated this task. Since we're here
139 // then the user must still be signed-in. 143 // then the user must still be signed-in.
140 SigninManager* signin_manager = 144 const std::string& username = signin_manager()->GetAuthenticatedUsername();
141 SigninManagerFactory::GetForProfile(profile());
142 const std::string& username = signin_manager->GetAuthenticatedUsername();
143 DCHECK(!username.empty()); 145 DCHECK(!username.empty());
144 DCHECK(!GetManager()->IsClientRegistered()); 146 DCHECK(!GetManager()->IsClientRegistered());
145 DCHECK(GetManager()->core()->client()); 147 DCHECK(GetManager()->core()->client());
146 148
147 // Persist the current time as the last policy registration attempt time. 149 // Persist the current time as the last policy registration attempt time.
148 profile()->GetPrefs()->SetInt64(prefs::kLastPolicyCheckTime, 150 profile()->GetPrefs()->SetInt64(prefs::kLastPolicyCheckTime,
149 base::Time::Now().ToInternalValue()); 151 base::Time::Now().ToInternalValue());
150 152
151 const bool force_load_policy = false; 153 const bool force_load_policy = false;
152 registration_helper_.reset(new CloudPolicyClientRegistrationHelper( 154 registration_helper_.reset(new CloudPolicyClientRegistrationHelper(
153 profile()->GetRequestContext(), 155 profile()->GetRequestContext(),
154 GetManager()->core()->client(), 156 GetManager()->core()->client(),
155 force_load_policy, 157 force_load_policy,
156 GetRegistrationType())); 158 GetRegistrationType()));
157 registration_helper_->StartRegistration( 159 registration_helper_->StartRegistration(
158 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()), 160 oauth2_token_service_,
159 username, 161 username,
160 base::Bind(&UserPolicySigninService::OnRegistrationDone, 162 base::Bind(&UserPolicySigninService::OnRegistrationDone,
161 base::Unretained(this))); 163 base::Unretained(this)));
162 } 164 }
163 165
164 void UserPolicySigninService::CancelPendingRegistration() { 166 void UserPolicySigninService::CancelPendingRegistration() {
165 weak_factory_.InvalidateWeakPtrs(); 167 weak_factory_.InvalidateWeakPtrs();
166 } 168 }
167 169
168 void UserPolicySigninService::OnRegistrationDone() { 170 void UserPolicySigninService::OnRegistrationDone() {
169 registration_helper_.reset(); 171 registration_helper_.reset();
170 } 172 }
171 173
172 } // namespace policy 174 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698