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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_WILDCARD_LOGIN_CHECKER_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_WILDCARD_LOGIN_CHECKER_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h"
12 #include "components/policy/core/common/cloud/user_info_fetcher.h"
13 #include "google_apis/gaia/google_service_auth_error.h"
16 class URLRequestContextGetter
;
21 class PolicyOAuth2TokenFetcher
;
23 // Performs online verification whether wildcard login is allowed, i.e. whether
24 // the user is a hosted user. This class performs an asynchronous check and
25 // reports the result via a callback.
26 class WildcardLoginChecker
: public UserInfoFetcher::Delegate
{
28 // Indicates result of the wildcard login check.
30 RESULT_ALLOWED
, // Wildcard check succeeded, login allowed.
31 RESULT_BLOCKED
, // Check completed, but user should be blocked.
32 RESULT_FAILED
, // Failure due to network errors etc.
35 typedef base::Callback
<void(Result
)> StatusCallback
;
37 WildcardLoginChecker();
38 virtual ~WildcardLoginChecker();
40 // Starts checking. The result will be reported via |callback_|.
41 void Start(scoped_refptr
<net::URLRequestContextGetter
> signin_context
,
42 const StatusCallback
& callback
);
44 // Starts checking with a provided access token.
45 void StartWithAccessToken(const std::string
& access_token
,
46 const StatusCallback
& callback
);
48 // UserInfoFetcher::Delegate:
49 void OnGetUserInfoSuccess(const base::DictionaryValue
* response
) override
;
50 void OnGetUserInfoFailure(const GoogleServiceAuthError
& error
) override
;
53 // Starts the check after successful token minting.
54 void OnPolicyTokenFetched(const std::string
& access_token
,
55 const GoogleServiceAuthError
& error
);
57 // Starts the user info fetcher.
58 void StartUserInfoFetcher(const std::string
& access_token
);
60 // Handles the response of the check and calls ReportResult().
61 void OnCheckCompleted(Result result
);
63 StatusCallback callback_
;
65 scoped_ptr
<PolicyOAuth2TokenFetcher
> token_fetcher_
;
66 scoped_ptr
<UserInfoFetcher
> user_info_fetcher_
;
68 base::Time start_timestamp_
;
69 base::Time token_available_timestamp_
;
71 DISALLOW_COPY_AND_ASSIGN(WildcardLoginChecker
);
76 #endif // CHROME_BROWSER_CHROMEOS_POLICY_WILDCARD_LOGIN_CHECKER_H_