OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_APP_LIST_SPEECH_AUTH_HELPER_H_ |
| 6 #define CHROME_BROWSER_UI_APP_LIST_SPEECH_AUTH_HELPER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 13 |
| 14 class Profile; |
| 15 class ProfileOAuth2TokenService; |
| 16 |
| 17 namespace app_list { |
| 18 |
| 19 // SpeechAuthHelper is a helper class to generate oauth tokens for audio |
| 20 // history. This encalsulates generating and refreshing the auth token for a |
| 21 // given profile. All functions should be called on the UI thread. |
| 22 class SpeechAuthHelper : public OAuth2TokenService::Consumer, |
| 23 public OAuth2TokenService::Observer { |
| 24 public: |
| 25 explicit SpeechAuthHelper(Profile* profile); |
| 26 ~SpeechAuthHelper(); |
| 27 |
| 28 // Returns the current auth token. If the auth service is not available, or |
| 29 // there was a failure in obtaining a token, return the empty string. |
| 30 std::string GetToken(); |
| 31 |
| 32 // Returns the OAuth scope associated with the auth token. |
| 33 std::string GetScope(); |
| 34 |
| 35 private: |
| 36 // Overridden from OAuth2TokenService::Consumer: |
| 37 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 38 const std::string& access_token, |
| 39 const base::Time& expiration_time) override; |
| 40 void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 41 const GoogleServiceAuthError& error) override; |
| 42 |
| 43 // Overridden from OAuth2TokenService::Observer: |
| 44 void OnRefreshTokenAvailable(const std::string& account_id) override; |
| 45 |
| 46 void ScheduleTokenFetch(const base::TimeDelta& fetch_delay); |
| 47 void FetchAuthToken(); |
| 48 |
| 49 Profile* profile_; |
| 50 ProfileOAuth2TokenService* token_service_; |
| 51 std::string authenticated_account_id_; |
| 52 std::string auth_token_; |
| 53 scoped_ptr<OAuth2TokenService::Request> auth_token_request_; |
| 54 |
| 55 base::WeakPtrFactory<SpeechAuthHelper> weak_factory_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(SpeechAuthHelper); |
| 58 }; |
| 59 |
| 60 } // namespace app_list |
| 61 |
| 62 #endif // CHROME_BROWSER_UI_APP_LIST_SPEECH_AUTH_HELPER_H_ |
OLD | NEW |