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

Unified Diff: chrome/browser/policy/cloud/user_policy_signin_service_mobile.cc

Issue 264043008: Reuse one UserPolicySigninService for Android and iOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix android build 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/cloud/user_policy_signin_service_mobile.cc
diff --git a/chrome/browser/policy/cloud/user_policy_signin_service_android.cc b/chrome/browser/policy/cloud/user_policy_signin_service_mobile.cc
similarity index 76%
rename from chrome/browser/policy/cloud/user_policy_signin_service_android.cc
rename to chrome/browser/policy/cloud/user_policy_signin_service_mobile.cc
index 91e570206fd5357421195f9602be2bd628bb4e4a..7f17fc1c9dfbeea276c9e253182a2b0226710ce6 100644
--- a/chrome/browser/policy/cloud/user_policy_signin_service_android.cc
+++ b/chrome/browser/policy/cloud/user_policy_signin_service_mobile.cc
@@ -1,8 +1,8 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/policy/cloud/user_policy_signin_service_android.h"
+#include "chrome/browser/policy/cloud/user_policy_signin_service_mobile.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
@@ -32,7 +32,13 @@ enterprise_management::DeviceRegisterRequest::Type GetRegistrationType() {
CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kFakeCloudPolicyType))
return enterprise_management::DeviceRegisterRequest::BROWSER;
+#if defined(OS_IOS)
+ return enterprise_management::DeviceRegisterRequest::IOS_BROWSER;
+#elif defined(OS_ANDROID)
return enterprise_management::DeviceRegisterRequest::ANDROID_BROWSER;
+#else
+#error "This file can be built only on OS_IOS or OS_ANDROID."
+#endif
}
} // namespace
@@ -53,13 +59,40 @@ UserPolicySigninService::UserPolicySigninService(
system_request_context),
weak_factory_(this),
oauth2_token_service_(token_service),
- profile_prefs_(profile->GetPrefs()) {}
+ profile_prefs_(profile->GetPrefs()) {
+#if defined(OS_IOS)
+ // iOS doesn't create this service with the Profile; instead it's created
+ // a little bit later. See UserPolicySigninServiceFactory.
+ InitializeOnProfileReady(profile);
+#endif
+}
UserPolicySigninService::~UserPolicySigninService() {}
void UserPolicySigninService::RegisterForPolicy(
const std::string& username,
const PolicyRegistrationCallback& callback) {
+ RegisterForPolicyInternal(username, "", callback);
+}
+
+#if !defined(OS_ANDROID)
+void UserPolicySigninService::RegisterForPolicyWithAccessToken(
+ const std::string& username,
+ const std::string& access_token,
+ const PolicyRegistrationCallback& callback) {
+ RegisterForPolicyInternal(username, access_token, callback);
+}
+
+// static
+std::vector<std::string> UserPolicySigninService::GetScopes() {
+ return CloudPolicyClientRegistrationHelper::GetScopes();
+}
+#endif
+
+void UserPolicySigninService::RegisterForPolicyInternal(
+ const std::string& username,
+ const std::string& access_token,
+ const PolicyRegistrationCallback& callback) {
// Create a new CloudPolicyClient for fetching the DMToken.
scoped_ptr<CloudPolicyClient> policy_client = CreateClientForRegistrationOnly(
username);
@@ -75,13 +108,27 @@ void UserPolicySigninService::RegisterForPolicy(
registration_helper_.reset(new CloudPolicyClientRegistrationHelper(
policy_client.get(),
GetRegistrationType()));
- registration_helper_->StartRegistration(
- oauth2_token_service_,
- username,
- base::Bind(&UserPolicySigninService::CallPolicyRegistrationCallback,
- base::Unretained(this),
- base::Passed(&policy_client),
- callback));
+
+ if (access_token.empty()) {
+ registration_helper_->StartRegistration(
+ oauth2_token_service_,
+ username,
+ base::Bind(&UserPolicySigninService::CallPolicyRegistrationCallback,
+ base::Unretained(this),
+ base::Passed(&policy_client),
+ callback));
+ } else {
+#if defined(OS_ANDROID)
+ NOTREACHED();
+#else
+ registration_helper_->StartRegistrationWithAccessToken(
+ access_token,
+ base::Bind(&UserPolicySigninService::CallPolicyRegistrationCallback,
+ base::Unretained(this),
+ base::Passed(&policy_client),
+ callback));
+#endif
+ }
}
void UserPolicySigninService::CallPolicyRegistrationCallback(
@@ -137,6 +184,11 @@ void UserPolicySigninService::OnInitializationCompleted(
try_registration_delay);
}
+void UserPolicySigninService::ShutdownUserCloudPolicyManager() {
+ CancelPendingRegistration();
+ UserPolicySigninServiceBase::ShutdownUserCloudPolicyManager();
+}
+
void UserPolicySigninService::RegisterCloudPolicyService() {
// If the user signed-out while this task was waiting then Shutdown() would
// have been called, which would have invalidated this task. Since we're here

Powered by Google App Engine
This is Rietveld 408576698