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_UI_APP_LIST_SPEECH_AUTH_HELPER_H_
6 #define CHROME_BROWSER_UI_APP_LIST_SPEECH_AUTH_HELPER_H_
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"
15 class ProfileOAuth2TokenService
;
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
{
29 SpeechAuthHelper(Profile
* profile
, base::Clock
* clock
);
30 ~SpeechAuthHelper() override
;
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() const;
36 // Returns the OAuth scope associated with the auth token.
37 std::string
GetScope() const;
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
;
47 // Overridden from OAuth2TokenService::Observer:
48 void OnRefreshTokenAvailable(const std::string
& account_id
) override
;
50 void ScheduleTokenFetch(const base::TimeDelta
& fetch_delay
);
51 void FetchAuthToken();
54 ProfileOAuth2TokenService
* token_service_
;
55 std::string authenticated_account_id_
;
56 std::string auth_token_
;
57 scoped_ptr
<OAuth2TokenService::Request
> auth_token_request_
;
59 base::WeakPtrFactory
<SpeechAuthHelper
> weak_factory_
;
61 DISALLOW_COPY_AND_ASSIGN(SpeechAuthHelper
);
64 } // namespace app_list
66 #endif // CHROME_BROWSER_UI_APP_LIST_SPEECH_AUTH_HELPER_H_