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

Side by Side Diff: chrome/browser/policy/cloud/user_policy_signin_service_ios.mm

Issue 197313004: Support policy registration using a preobtained access token. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 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 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_ios.h" 5 #include "chrome/browser/policy/cloud/user_policy_signin_service_ios.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/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
17 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
18 #include "components/policy/core/common/cloud/cloud_policy_client_registration_h elper.h" 17 #include "components/policy/core/common/cloud/cloud_policy_client_registration_h elper.h"
19 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h" 18 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h"
20 #include "components/policy/core/common/policy_switches.h" 19 #include "components/policy/core/common/policy_switches.h"
21 #include "components/signin/core/browser/profile_oauth2_token_service.h"
22 #include "components/signin/core/browser/signin_manager.h" 20 #include "components/signin/core/browser/signin_manager.h"
23 #include "net/base/network_change_notifier.h" 21 #include "net/base/network_change_notifier.h"
24 #include "net/url_request/url_request_context_getter.h" 22 #include "net/url_request/url_request_context_getter.h"
25 #include "policy/proto/device_management_backend.pb.h" 23 #include "policy/proto/device_management_backend.pb.h"
26 24
27 namespace policy { 25 namespace policy {
28 26
29 namespace { 27 namespace {
30 28
31 enterprise_management::DeviceRegisterRequest::Type GetRegistrationType() { 29 enterprise_management::DeviceRegisterRequest::Type GetRegistrationType() {
(...skipping 13 matching lines...) Expand all
45 SigninManager* signin_manager, 43 SigninManager* signin_manager,
46 scoped_refptr<net::URLRequestContextGetter> system_request_context, 44 scoped_refptr<net::URLRequestContextGetter> system_request_context,
47 ProfileOAuth2TokenService* token_service) 45 ProfileOAuth2TokenService* token_service)
48 : UserPolicySigninServiceBase(profile, 46 : UserPolicySigninServiceBase(profile,
49 local_state, 47 local_state,
50 device_management_service, 48 device_management_service,
51 policy_manager, 49 policy_manager,
52 signin_manager, 50 signin_manager,
53 system_request_context), 51 system_request_context),
54 weak_factory_(this), 52 weak_factory_(this),
55 oauth2_token_service_(token_service),
56 profile_prefs_(profile->GetPrefs()) {} 53 profile_prefs_(profile->GetPrefs()) {}
57 54
58 UserPolicySigninService::~UserPolicySigninService() {} 55 UserPolicySigninService::~UserPolicySigninService() {}
59 56
60 void UserPolicySigninService::RegisterForPolicy( 57 void UserPolicySigninService::RegisterForPolicy(
61 const std::string& username, 58 const std::string& username,
59 const std::string& access_token,
62 PolicyRegistrationBlockCallback callback) { 60 PolicyRegistrationBlockCallback callback) {
63 // Create a new CloudPolicyClient for fetching the DMToken. 61 // Create a new CloudPolicyClient for fetching the DMToken.
64 scoped_ptr<CloudPolicyClient> policy_client = CreateClientForRegistrationOnly( 62 scoped_ptr<CloudPolicyClient> policy_client = CreateClientForRegistrationOnly(
65 username); 63 username);
66 if (!policy_client) { 64 if (!policy_client) {
67 callback(std::string(), std::string()); 65 callback(std::string(), std::string());
68 return; 66 return;
69 } 67 }
70 68
71 CancelPendingRegistration(); 69 CancelPendingRegistration();
72 70
73 // Fire off the registration process. Callback keeps the CloudPolicyClient 71 // Fire off the registration process. Callback keeps the CloudPolicyClient
74 // alive for the length of the registration process. 72 // alive for the length of the registration process.
75 registration_helper_.reset(new CloudPolicyClientRegistrationHelper( 73 registration_helper_.reset(new CloudPolicyClientRegistrationHelper(
76 policy_client.get(), 74 policy_client.get(),
77 GetRegistrationType())); 75 GetRegistrationType()));
78 registration_helper_->StartRegistration( 76 registration_helper_->StartRegistrationWithAccessToken(
79 oauth2_token_service_, 77 access_token,
80 username, 78 base::Bind(&UserPolicySigninService::CallPolicyRegistrationCallback,
81 base::Bind(&UserPolicySigninService::CallPolicyRegistrationCallback, 79 base::Unretained(this),
82 base::Unretained(this), 80 base::Passed(&policy_client),
83 base::Passed(&policy_client), 81 [callback copy]));
84 [callback copy])); 82 }
83
84 // static
85 std::vector<std::string> UserPolicySigninService::GetScopes() {
86 return CloudPolicyClientRegistrationHelper::GetScopes();
85 } 87 }
86 88
87 void UserPolicySigninService::FetchPolicy( 89 void UserPolicySigninService::FetchPolicy(
88 const std::string& username, 90 const std::string& username,
89 const std::string& dm_token, 91 const std::string& dm_token,
90 const std::string& client_id, 92 const std::string& client_id,
91 scoped_refptr<net::URLRequestContextGetter> profile_request_context, 93 scoped_refptr<net::URLRequestContextGetter> profile_request_context,
92 PolicyFetchBlockCallback callback) { 94 PolicyFetchBlockCallback callback) {
93 FetchPolicyForSignedInUser( 95 FetchPolicyForSignedInUser(
94 username, 96 username,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // Note: we don't register the cloud policy client on iOS if it's not 131 // Note: we don't register the cloud policy client on iOS if it's not
130 // registered at this stage. If there was no policy at sign-in time then 132 // registered at this stage. If there was no policy at sign-in time then
131 // there won't be policy later either. 133 // there won't be policy later either.
132 } 134 }
133 135
134 void UserPolicySigninService::CancelPendingRegistration() { 136 void UserPolicySigninService::CancelPendingRegistration() {
135 weak_factory_.InvalidateWeakPtrs(); 137 weak_factory_.InvalidateWeakPtrs();
136 } 138 }
137 139
138 } // namespace policy 140 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698