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

Unified Diff: chrome/browser/chromeos/policy/wildcard_login_checker.cc

Issue 148843002: Make an online wildcard login check for enterprise devices. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix failing test. Created 6 years, 11 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/chromeos/policy/wildcard_login_checker.cc
diff --git a/chrome/browser/chromeos/policy/wildcard_login_checker.cc b/chrome/browser/chromeos/policy/wildcard_login_checker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8ad242f78f63faa1ae507eb9b20b7f26a123f771
--- /dev/null
+++ b/chrome/browser/chromeos/policy/wildcard_login_checker.cc
@@ -0,0 +1,88 @@
+// Copyright (c) 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/chromeos/policy/wildcard_login_checker.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h"
+#include "components/policy/core/browser/browser_policy_connector.h"
+#include "net/url_request/url_request_context_getter.h"
+
+namespace policy {
+
+namespace {
+
+// Presence of this key in the userinfo response indicates whether the user is
+// on a hosted domain.
+const char kHostedDomainKey[] = "hd";
+
+} // namespace
+
+WildcardLoginChecker::WildcardLoginChecker() {}
+
+WildcardLoginChecker::~WildcardLoginChecker() {}
+
+void WildcardLoginChecker::Start(
+ scoped_refptr<net::URLRequestContextGetter> signin_context,
+ const StatusCallback& callback) {
+ CHECK(!token_fetcher_);
+ CHECK(!user_info_fetcher_);
+ callback_ = callback;
+ token_fetcher_.reset(new PolicyOAuth2TokenFetcher(
+ signin_context,
+ g_browser_process->system_request_context(),
+ base::Bind(&WildcardLoginChecker::OnPolicyTokenFetched,
+ base::Unretained(this))));
+ token_fetcher_->Start();
+}
+
+void WildcardLoginChecker::StartWithAccessToken(
+ const std::string& access_token,
+ const StatusCallback& callback) {
+ CHECK(!token_fetcher_);
+ CHECK(!user_info_fetcher_);
+ callback_ = callback;
+
+ StartUserInfoFetcher(access_token);
+}
+
+void WildcardLoginChecker::OnGetUserInfoSuccess(
+ const base::DictionaryValue* response) {
+ OnCheckCompleted(response->HasKey(kHostedDomainKey));
+}
+
+void WildcardLoginChecker::OnGetUserInfoFailure(
+ const GoogleServiceAuthError& error) {
+ LOG(ERROR) << "Failed to fetch policy token " << error.ToString();
xiyuan 2014/01/29 03:45:09 nit: "Failed to get user info " since it's not abo
Mattias Nissler (ping if slow) 2014/01/29 12:12:32 Doh. Done.
+ OnCheckCompleted(false);
+}
+
+void WildcardLoginChecker::OnPolicyTokenFetched(
+ const std::string& access_token,
+ const GoogleServiceAuthError& error) {
+ if (error.state() != GoogleServiceAuthError::NONE) {
+ LOG(ERROR) << "Failed to fetch policy token " << error.ToString();
+ OnCheckCompleted(false);
+ return;
+ }
+
+ token_fetcher_.reset();
+ StartUserInfoFetcher(access_token);
+}
+
+void WildcardLoginChecker::StartUserInfoFetcher(
+ const std::string& access_token) {
+ user_info_fetcher_.reset(
+ new UserInfoFetcher(this, g_browser_process->system_request_context()));
+ user_info_fetcher_->Start(access_token);
+}
+
+void WildcardLoginChecker::OnCheckCompleted(bool result) {
+ if (!callback_.is_null())
+ callback_.Run(result);
+}
+
+} // namespace policy
« no previous file with comments | « chrome/browser/chromeos/policy/wildcard_login_checker.h ('k') | chrome/browser/chromeos/settings/cros_settings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698