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

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

Powered by Google App Engine
This is Rietveld 408576698