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

Side by Side Diff: chrome/browser/ui/app_list/start_page_service.cc

Issue 778393002: Add OAuth2 authentication for some voice transcription requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/start_page_service.h" 5 #include "chrome/browser/ui/app_list/start_page_service.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/memory/singleton.h" 11 #include "base/memory/singleton.h"
12 #include "base/metrics/user_metrics.h" 12 #include "base/metrics/user_metrics.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/media/media_stream_infobar_delegate.h" 16 #include "chrome/browser/media/media_stream_infobar_delegate.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/search/hotword_service.h" 18 #include "chrome/browser/search/hotword_service.h"
19 #include "chrome/browser/search/hotword_service_factory.h" 19 #include "chrome/browser/search/hotword_service_factory.h"
20 #include "chrome/browser/ui/app_list/recommended_apps.h" 20 #include "chrome/browser/ui/app_list/recommended_apps.h"
21 #include "chrome/browser/ui/app_list/speech_auth_helper.h"
21 #include "chrome/browser/ui/app_list/speech_recognizer.h" 22 #include "chrome/browser/ui/app_list/speech_recognizer.h"
22 #include "chrome/browser/ui/app_list/start_page_observer.h" 23 #include "chrome/browser/ui/app_list/start_page_observer.h"
23 #include "chrome/browser/ui/app_list/start_page_service_factory.h" 24 #include "chrome/browser/ui/app_list/start_page_service_factory.h"
24 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
26 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
27 #include "content/public/browser/notification_details.h" 28 #include "content/public/browser/notification_details.h"
28 #include "content/public/browser/notification_observer.h" 29 #include "content/public/browser/notification_observer.h"
29 #include "content/public/browser/notification_registrar.h" 30 #include "content/public/browser/notification_registrar.h"
30 #include "content/public/browser/notification_service.h" 31 #include "content/public/browser/notification_service.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 155 }
155 156
156 StartPageService::StartPageService(Profile* profile) 157 StartPageService::StartPageService(Profile* profile)
157 : profile_(profile), 158 : profile_(profile),
158 profile_destroy_observer_(new ProfileDestroyObserver(this)), 159 profile_destroy_observer_(new ProfileDestroyObserver(this)),
159 recommended_apps_(new RecommendedApps(profile)), 160 recommended_apps_(new RecommendedApps(profile)),
160 state_(app_list::SPEECH_RECOGNITION_OFF), 161 state_(app_list::SPEECH_RECOGNITION_OFF),
161 speech_button_toggled_manually_(false), 162 speech_button_toggled_manually_(false),
162 speech_result_obtained_(false), 163 speech_result_obtained_(false),
163 webui_finished_loading_(false), 164 webui_finished_loading_(false),
165 speech_auth_helper_(new SpeechAuthHelper(profile)),
164 weak_factory_(this) { 166 weak_factory_(this) {
165 // If experimental hotwording is enabled, then we're always "ready". 167 // If experimental hotwording is enabled, then we're always "ready".
166 // Transitioning into the "hotword recognizing" state is handled by the 168 // Transitioning into the "hotword recognizing" state is handled by the
167 // hotword extension. 169 // hotword extension.
168 if (HotwordService::IsExperimentalHotwordingEnabled()) { 170 if (HotwordService::IsExperimentalHotwordingEnabled()) {
169 state_ = app_list::SPEECH_RECOGNITION_READY; 171 state_ = app_list::SPEECH_RECOGNITION_READY;
170 } 172 }
171 173
172 if (app_list::switches::IsExperimentalAppListEnabled()) 174 if (app_list::switches::IsExperimentalAppListEnabled())
173 LoadContents(); 175 LoadContents();
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 state_ = new_state; 339 state_ = new_state;
338 FOR_EACH_OBSERVER(StartPageObserver, 340 FOR_EACH_OBSERVER(StartPageObserver,
339 observers_, 341 observers_,
340 OnSpeechRecognitionStateChanged(new_state)); 342 OnSpeechRecognitionStateChanged(new_state));
341 } 343 }
342 344
343 content::WebContents* StartPageService::GetSpeechContents() { 345 content::WebContents* StartPageService::GetSpeechContents() {
344 return GetSpeechRecognitionContents(); 346 return GetSpeechRecognitionContents();
345 } 347 }
346 348
349 void StartPageService::GetSpeechAuthParameters(std::string* auth_scope,
350 std::string* auth_token) {
351 if (HotwordService::IsExperimentalHotwordingEnabled()) {
352 HotwordService* service = HotwordServiceFactory::GetForProfile(profile_);
353 if (service &&
354 service->IsOptedIntoAudioLogging() &&
355 !speech_auth_helper_->GetToken().empty()) {
356 *auth_scope = speech_auth_helper_->GetScope();
357 *auth_token = speech_auth_helper_->GetToken();
358 }
359 }
360 }
361
347 void StartPageService::Shutdown() { 362 void StartPageService::Shutdown() {
348 UnloadContents(); 363 UnloadContents();
349 #if defined(OS_CHROMEOS) 364 #if defined(OS_CHROMEOS)
350 audio_status_.reset(); 365 audio_status_.reset();
351 #endif 366 #endif
367
368 speech_auth_helper_.reset();
352 } 369 }
353 370
354 void StartPageService::WebUILoaded() { 371 void StartPageService::WebUILoaded() {
355 // There's a race condition between the WebUI loading, and calling its JS 372 // There's a race condition between the WebUI loading, and calling its JS
356 // functions. Specifically, calling LoadContents() doesn't mean that the page 373 // functions. Specifically, calling LoadContents() doesn't mean that the page
357 // has loaded, but several code paths make this assumption. This function 374 // has loaded, but several code paths make this assumption. This function
358 // allows us to defer calling JS functions until after the page has finished 375 // allows us to defer calling JS functions until after the page has finished
359 // loading. 376 // loading.
360 webui_finished_loading_ = true; 377 webui_finished_loading_ = true;
361 for (const auto& cb : pending_webui_callbacks_) 378 for (const auto& cb : pending_webui_callbacks_)
(...skipping 13 matching lines...) Expand all
375 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, 392 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
376 std::string()); 393 std::string());
377 } 394 }
378 395
379 void StartPageService::UnloadContents() { 396 void StartPageService::UnloadContents() {
380 contents_.reset(); 397 contents_.reset();
381 webui_finished_loading_ = false; 398 webui_finished_loading_ = false;
382 } 399 }
383 400
384 } // namespace app_list 401 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698