Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: chrome/browser/ui/app_list/speech_auth_helper.h

Issue 778393002: Add OAuth2 authentication for some voice transcription requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/app_list/speech_auth_helper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/app_list/speech_auth_helper.h
diff --git a/chrome/browser/ui/app_list/speech_auth_helper.h b/chrome/browser/ui/app_list/speech_auth_helper.h
new file mode 100644
index 0000000000000000000000000000000000000000..091002638bdc71ccc36a0fa29968763a8d753a52
--- /dev/null
+++ b/chrome/browser/ui/app_list/speech_auth_helper.h
@@ -0,0 +1,67 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_APP_LIST_SPEECH_AUTH_HELPER_H_
+#define CHROME_BROWSER_UI_APP_LIST_SPEECH_AUTH_HELPER_H_
+
+#include <string>
+
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "components/signin/core/browser/profile_oauth2_token_service.h"
+
+class Profile;
+class ProfileOAuth2TokenService;
+
+namespace base {
+class Clock;
+}
+
+namespace app_list {
+
+// SpeechAuthHelper is a helper class to generate oauth tokens for audio
+// history. This encalsulates generating and refreshing the auth token for a
+// given profile. All functions should be called on the UI thread.
+class SpeechAuthHelper : public OAuth2TokenService::Consumer,
+ public OAuth2TokenService::Observer {
+ public:
+ explicit SpeechAuthHelper(Profile* profile, base::Clock* clock);
+ ~SpeechAuthHelper();
+
+ // Returns the current auth token. If the auth service is not available, or
+ // there was a failure in obtaining a token, return the empty string.
+ std::string GetToken();
+
+ // Returns the OAuth scope associated with the auth token.
+ std::string GetScope();
+
+ private:
+ // Overridden from OAuth2TokenService::Consumer:
+ void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
+ const std::string& access_token,
+ const base::Time& expiration_time) override;
+ void OnGetTokenFailure(const OAuth2TokenService::Request* request,
+ const GoogleServiceAuthError& error) override;
+
+ // Overridden from OAuth2TokenService::Observer:
+ void OnRefreshTokenAvailable(const std::string& account_id) override;
+
+ void ScheduleTokenFetch(const base::TimeDelta& fetch_delay);
+ void FetchAuthToken();
+
+ Profile* profile_;
+ base::Clock* clock_;
+ ProfileOAuth2TokenService* token_service_;
+ std::string authenticated_account_id_;
+ std::string auth_token_;
+ scoped_ptr<OAuth2TokenService::Request> auth_token_request_;
+
+ base::WeakPtrFactory<SpeechAuthHelper> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(SpeechAuthHelper);
+};
+
+} // namespace app_list
+
+#endif // CHROME_BROWSER_UI_APP_LIST_SPEECH_AUTH_HELPER_H_
« no previous file with comments | « no previous file | chrome/browser/ui/app_list/speech_auth_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698