Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / signin / token_handle_fetcher.h
blobe63394ddcf9632a2e7ce9eb02561d44679942a69
1 // Copyright 2015 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_LOGIN_SIGNIN_TOKEN_HANDLE_FETCHER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_TOKEN_HANDLE_FETCHER_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/containers/scoped_ptr_hash_map.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/time/time.h"
15 #include "components/user_manager/user_id.h"
16 #include "google_apis/gaia/gaia_oauth_client.h"
17 #include "google_apis/gaia/oauth2_token_service.h"
19 class TokenHandleUtil;
20 class Profile;
22 // This class is resposible for obtaining new token handle for user.
23 // It can be used in two ways. When user have just used GAIA signin there is
24 // an OAuth2 token available. If there is profile already loaded, then
25 // minting additional access token might be required.
27 class TokenHandleFetcher : public gaia::GaiaOAuthClient::Delegate,
28 public OAuth2TokenService::Consumer,
29 public OAuth2TokenService::Observer {
30 public:
31 TokenHandleFetcher(TokenHandleUtil* util,
32 const user_manager::UserID& user_id);
33 ~TokenHandleFetcher() override;
35 typedef base::Callback<void(const user_manager::UserID&, bool success)>
36 TokenFetchingCallback;
38 // Get token handle for user who have just signed in via GAIA. This
39 // request will be performed using signin profile.
40 void FillForNewUser(const std::string& access_token,
41 const TokenFetchingCallback& callback);
43 // Get token handle for existing user.
44 void BackfillToken(Profile* profile, const TokenFetchingCallback& callback);
46 private:
47 // OAuth2TokenService::Observer override:
48 void OnRefreshTokenAvailable(const std::string& account_id) override;
50 // OAuth2TokenService::Consumer overrides:
51 void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
52 const std::string& access_token,
53 const base::Time& expiration_time) override;
54 void OnGetTokenFailure(const OAuth2TokenService::Request* request,
55 const GoogleServiceAuthError& error) override;
57 // GaiaOAuthClient::Delegate overrides:
58 void OnOAuthError() override;
59 void OnNetworkError(int response_code) override;
60 void OnGetTokenInfoResponse(
61 scoped_ptr<base::DictionaryValue> token_info) override;
63 void RequestAccessToken(const std::string& account_id);
64 void FillForAccessToken(const std::string& access_token);
66 TokenHandleUtil* token_handle_util_;
67 user_manager::UserID user_id_;
68 OAuth2TokenService* token_service_;
70 bool waiting_for_refresh_token_;
71 std::string account_without_token_;
72 Profile* profile_;
73 base::TimeTicks tokeninfo_response_start_time_;
74 TokenFetchingCallback callback_;
75 scoped_ptr<gaia::GaiaOAuthClient> gaia_client_;
76 scoped_ptr<OAuth2TokenService::Request> oauth2_access_token_request_;
78 DISALLOW_COPY_AND_ASSIGN(TokenHandleFetcher);
81 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_TOKEN_HANDLE_FETCHER_H_