OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/app_list/speech_auth_helper.h" | 5 #include "chrome/browser/ui/app_list/speech_auth_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/time/clock.h" | 10 #include "base/time/clock.h" |
11 #include "chrome/browser/profiles/profile.h" | |
12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
13 #include "chrome/browser/signin/signin_manager_factory.h" | 12 #include "chrome/browser/signin/signin_manager_factory.h" |
14 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 13 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
15 #include "components/signin/core/browser/signin_manager.h" | 14 #include "components/signin/core/browser/signin_manager.h" |
16 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
17 | 16 |
18 namespace app_list { | 17 namespace app_list { |
19 | 18 |
20 static const char* kAuthScope = | 19 static const char* kAuthScope = |
21 "https://www.googleapis.com/auth/webhistory"; | 20 "https://www.googleapis.com/auth/webhistory"; |
22 static const int kMinTokenRefreshDelaySeconds = 300; // 5 minutes | 21 static const int kMinTokenRefreshDelaySeconds = 300; // 5 minutes |
23 | 22 |
24 | 23 |
25 SpeechAuthHelper::SpeechAuthHelper(Profile* profile, base::Clock* clock) | 24 SpeechAuthHelper::SpeechAuthHelper(Profile* profile, base::Clock* clock) |
26 : OAuth2TokenService::Consumer(kAuthScope), | 25 : OAuth2TokenService::Consumer(kAuthScope), |
27 profile_(profile), | |
28 clock_(clock), | 26 clock_(clock), |
29 token_service_(ProfileOAuth2TokenServiceFactory::GetForProfile(profile)), | 27 token_service_(ProfileOAuth2TokenServiceFactory::GetForProfile(profile)), |
30 weak_factory_(this) { | 28 weak_factory_(this) { |
31 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 29 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
32 | 30 |
33 // If token_service_ is NULL, we can't do anything. This might be NULL if the | 31 // If token_service_ is NULL, we can't do anything. This might be NULL if the |
34 // profile is a guest user. | 32 // profile is a guest user. |
35 if (!token_service_) | 33 if (!token_service_) |
36 return; | 34 return; |
37 | 35 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // guaranteed to be valid at this point. | 105 // guaranteed to be valid at this point. |
108 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 106 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
109 OAuth2TokenService::ScopeSet scopes; | 107 OAuth2TokenService::ScopeSet scopes; |
110 scopes.insert(kAuthScope); | 108 scopes.insert(kAuthScope); |
111 auth_token_request_ = token_service_->StartRequest( | 109 auth_token_request_ = token_service_->StartRequest( |
112 authenticated_account_id_, | 110 authenticated_account_id_, |
113 scopes, | 111 scopes, |
114 this); | 112 this); |
115 } | 113 } |
116 | 114 |
117 std::string SpeechAuthHelper::GetToken() { | 115 std::string SpeechAuthHelper::GetToken() const { |
118 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 116 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
119 return auth_token_; | 117 return auth_token_; |
120 } | 118 } |
121 | 119 |
122 std::string SpeechAuthHelper::GetScope() { | 120 std::string SpeechAuthHelper::GetScope() const { |
123 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 121 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
124 return kAuthScope; | 122 return kAuthScope; |
125 } | 123 } |
126 | 124 |
127 } // namespace app_list | 125 } // namespace app_list |
OLD | NEW |