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

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

Issue 2953253002: [DICE] Enable sync for an account that is already present in the token service. (Closed)
Patch Set: Address code review Created 3 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_mobile.h" 5 #include "chrome/browser/policy/cloud/user_policy_signin_service_mobile.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/location.h" 10 #include "base/location.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 policy_manager, 55 policy_manager,
56 signin_manager, 56 signin_manager,
57 system_request_context), 57 system_request_context),
58 oauth2_token_service_(token_service), 58 oauth2_token_service_(token_service),
59 profile_prefs_(profile->GetPrefs()), 59 profile_prefs_(profile->GetPrefs()),
60 weak_factory_(this) { 60 weak_factory_(this) {
61 } 61 }
62 62
63 UserPolicySigninService::~UserPolicySigninService() {} 63 UserPolicySigninService::~UserPolicySigninService() {}
64 64
65 void UserPolicySigninService::RegisterForPolicy(
66 const std::string& username,
67 const std::string& account_id,
68 const PolicyRegistrationCallback& callback) {
69 RegisterForPolicyInternal(username, account_id, "", callback);
70 }
71
72 #if !defined(OS_ANDROID)
73 void UserPolicySigninService::RegisterForPolicyWithAccessToken(
74 const std::string& username,
75 const std::string& access_token,
76 const PolicyRegistrationCallback& callback) {
77 RegisterForPolicyInternal(username, "", access_token, callback);
78 }
79
80 // static
81 std::vector<std::string> UserPolicySigninService::GetScopes() {
82 return CloudPolicyClientRegistrationHelper::GetScopes();
83 }
84 #endif
85
86 void UserPolicySigninService::ShutdownUserCloudPolicyManager() { 65 void UserPolicySigninService::ShutdownUserCloudPolicyManager() {
87 CancelPendingRegistration(); 66 CancelPendingRegistration();
88 UserPolicySigninServiceBase::ShutdownUserCloudPolicyManager(); 67 UserPolicySigninServiceBase::ShutdownUserCloudPolicyManager();
89 } 68 }
90 69
91 void UserPolicySigninService::RegisterForPolicyInternal( 70 void UserPolicySigninService::RegisterForPolicyWithAccountId(
92 const std::string& username, 71 const std::string& username,
93 const std::string& account_id, 72 const std::string& account_id,
94 const std::string& access_token,
95 const PolicyRegistrationCallback& callback) { 73 const PolicyRegistrationCallback& callback) {
96 // Create a new CloudPolicyClient for fetching the DMToken. 74 // Create a new CloudPolicyClient for fetching the DMToken.
97 std::unique_ptr<CloudPolicyClient> policy_client = 75 std::unique_ptr<CloudPolicyClient> policy_client =
98 CreateClientForRegistrationOnly(username); 76 CreateClientForRegistrationOnly(username);
99 if (!policy_client) { 77 if (!policy_client) {
100 callback.Run(std::string(), std::string()); 78 callback.Run(std::string(), std::string());
101 return; 79 return;
102 } 80 }
103 81
104 CancelPendingRegistration(); 82 CancelPendingRegistration();
105 83
106 // Fire off the registration process. Callback keeps the CloudPolicyClient 84 // Fire off the registration process. Callback keeps the CloudPolicyClient
107 // alive for the length of the registration process. 85 // alive for the length of the registration process.
108 registration_helper_.reset(new CloudPolicyClientRegistrationHelper( 86 registration_helper_.reset(new CloudPolicyClientRegistrationHelper(
109 policy_client.get(), 87 policy_client.get(),
110 kCloudPolicyRegistrationType)); 88 kCloudPolicyRegistrationType));
111 89
112 // Using a raw pointer to |this| is okay, because we own the 90 // Using a raw pointer to |this| is okay, because we own the
113 // |registration_helper_|. 91 // |registration_helper_|.
114 auto registration_callback = base::Bind( 92 auto registration_callback = base::Bind(
115 &UserPolicySigninService::CallPolicyRegistrationCallback, 93 &UserPolicySigninService::CallPolicyRegistrationCallback,
116 base::Unretained(this), base::Passed(&policy_client), callback); 94 base::Unretained(this), base::Passed(&policy_client), callback);
117 if (access_token.empty()) { 95 registration_helper_->StartRegistration(oauth2_token_service_, account_id,
118 registration_helper_->StartRegistration( 96 registration_callback);
119 oauth2_token_service_, account_id, registration_callback);
120 } else {
121 #if defined(OS_ANDROID)
122 NOTREACHED();
123 #else
124 registration_helper_->StartRegistrationWithAccessToken(
125 access_token, registration_callback);
126 #endif
127 }
128 } 97 }
129 98
130 void UserPolicySigninService::CallPolicyRegistrationCallback( 99 void UserPolicySigninService::CallPolicyRegistrationCallback(
131 std::unique_ptr<CloudPolicyClient> client, 100 std::unique_ptr<CloudPolicyClient> client,
132 PolicyRegistrationCallback callback) { 101 PolicyRegistrationCallback callback) {
133 registration_helper_.reset(); 102 registration_helper_.reset();
134 callback.Run(client->dm_token(), client->client_id()); 103 callback.Run(client->dm_token(), client->client_id());
135 } 104 }
136 105
137 void UserPolicySigninService::Shutdown() { 106 void UserPolicySigninService::Shutdown() {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 void UserPolicySigninService::CancelPendingRegistration() { 173 void UserPolicySigninService::CancelPendingRegistration() {
205 weak_factory_.InvalidateWeakPtrs(); 174 weak_factory_.InvalidateWeakPtrs();
206 registration_helper_.reset(); 175 registration_helper_.reset();
207 } 176 }
208 177
209 void UserPolicySigninService::OnRegistrationDone() { 178 void UserPolicySigninService::OnRegistrationDone() {
210 registration_helper_.reset(); 179 registration_helper_.reset();
211 } 180 }
212 181
213 } // namespace policy 182 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698