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