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 StartWithSigninContext(
42 scoped_refptr
<net::URLRequestContextGetter
> signin_context
,
43 const StatusCallback
& callback
);
45 // Starts checking with a provided refresh token.
46 void StartWithRefreshToken(const std::string
& refresh_token
,
47 const StatusCallback
& callback
);
49 // Starts checking with a provided access token.
50 void StartWithAccessToken(const std::string
& access_token
,
51 const StatusCallback
& callback
);
53 // UserInfoFetcher::Delegate:
54 void OnGetUserInfoSuccess(const base::DictionaryValue
* response
) override
;
55 void OnGetUserInfoFailure(const GoogleServiceAuthError
& error
) override
;
58 // Starts the check after successful token minting.
59 void OnPolicyTokenFetched(const std::string
& access_token
,
60 const GoogleServiceAuthError
& error
);
62 // Starts the user info fetcher.
63 void StartUserInfoFetcher(const std::string
& access_token
);
65 // Handles the response of the check and calls ReportResult().
66 void OnCheckCompleted(Result result
);
68 StatusCallback callback_
;
70 scoped_ptr
<PolicyOAuth2TokenFetcher
> token_fetcher_
;
71 scoped_ptr
<UserInfoFetcher
> user_info_fetcher_
;
73 base::Time start_timestamp_
;
74 base::Time token_available_timestamp_
;
76 DISALLOW_COPY_AND_ASSIGN(WildcardLoginChecker
);
81 #endif // CHROME_BROWSER_CHROMEOS_POLICY_WILDCARD_LOGIN_CHECKER_H_