Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / app_list / speech_auth_helper.h
blobd5b9094a125faa6a0e4f6ab98bf096db541e56f3
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_
8 #include <string>
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"
14 class Profile;
15 class ProfileOAuth2TokenService;
17 namespace base {
18 class Clock;
21 namespace app_list {
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 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;
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;
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();
53 base::Clock* clock_;
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_