OLD | NEW |
---|---|
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/json/json_string_value_serializer.h" | 11 #include "base/json/json_string_value_serializer.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/metrics/user_metrics.h" | 13 #include "base/metrics/user_metrics.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
18 #include "chrome/browser/media/media_stream_infobar_delegate.h" | 18 #include "chrome/browser/media/media_stream_infobar_delegate.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/search/hotword_service.h" | 20 #include "chrome/browser/search/hotword_service.h" |
21 #include "chrome/browser/search/hotword_service_factory.h" | 21 #include "chrome/browser/search/hotword_service_factory.h" |
22 #include "chrome/browser/search_engines/template_url_service_factory.h" | |
22 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 23 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
23 #include "chrome/browser/ui/app_list/speech_auth_helper.h" | 24 #include "chrome/browser/ui/app_list/speech_auth_helper.h" |
24 #include "chrome/browser/ui/app_list/speech_recognizer.h" | 25 #include "chrome/browser/ui/app_list/speech_recognizer.h" |
25 #include "chrome/browser/ui/app_list/start_page_observer.h" | 26 #include "chrome/browser/ui/app_list/start_page_observer.h" |
26 #include "chrome/browser/ui/app_list/start_page_service_factory.h" | 27 #include "chrome/browser/ui/app_list/start_page_service_factory.h" |
27 #include "chrome/browser/ui/browser_navigator.h" | 28 #include "chrome/browser/ui/browser_navigator.h" |
28 #include "chrome/browser/ui/browser_tabstrip.h" | 29 #include "chrome/browser/ui/browser_tabstrip.h" |
29 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 30 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
30 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
31 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
32 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
34 #include "components/search_engines/template_url_prepopulate_data.h" | |
35 #include "components/search_engines/template_url_service.h" | |
33 #include "components/ui/zoom/zoom_controller.h" | 36 #include "components/ui/zoom/zoom_controller.h" |
34 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
35 #include "content/public/browser/notification_details.h" | 38 #include "content/public/browser/notification_details.h" |
36 #include "content/public/browser/notification_observer.h" | 39 #include "content/public/browser/notification_observer.h" |
37 #include "content/public/browser/notification_registrar.h" | 40 #include "content/public/browser/notification_registrar.h" |
38 #include "content/public/browser/notification_service.h" | 41 #include "content/public/browser/notification_service.h" |
39 #include "content/public/browser/notification_source.h" | 42 #include "content/public/browser/notification_source.h" |
40 #include "content/public/browser/speech_recognition_session_preamble.h" | 43 #include "content/public/browser/speech_recognition_session_preamble.h" |
41 #include "content/public/browser/web_contents.h" | 44 #include "content/public/browser/web_contents.h" |
42 #include "content/public/browser/web_contents_delegate.h" | 45 #include "content/public/browser/web_contents_delegate.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 StartPageService::StartPageService(Profile* profile) | 264 StartPageService::StartPageService(Profile* profile) |
262 : profile_(profile), | 265 : profile_(profile), |
263 profile_destroy_observer_(new ProfileDestroyObserver(this)), | 266 profile_destroy_observer_(new ProfileDestroyObserver(this)), |
264 state_(app_list::SPEECH_RECOGNITION_OFF), | 267 state_(app_list::SPEECH_RECOGNITION_OFF), |
265 speech_button_toggled_manually_(false), | 268 speech_button_toggled_manually_(false), |
266 speech_result_obtained_(false), | 269 speech_result_obtained_(false), |
267 webui_finished_loading_(false), | 270 webui_finished_loading_(false), |
268 speech_auth_helper_(new SpeechAuthHelper(profile, &clock_)), | 271 speech_auth_helper_(new SpeechAuthHelper(profile, &clock_)), |
269 network_available_(true), | 272 network_available_(true), |
270 microphone_available_(true), | 273 microphone_available_(true), |
274 search_engine_is_google_(true), | |
Matt Giuca
2015/02/17 08:07:45
nit: Maybe init this to false? (Doesn't really mat
calamity
2015/02/18 01:42:34
Done.
| |
271 weak_factory_(this) { | 275 weak_factory_(this) { |
272 // If experimental hotwording is enabled, then we're always "ready". | 276 // If experimental hotwording is enabled, then we're always "ready". |
273 // Transitioning into the "hotword recognizing" state is handled by the | 277 // Transitioning into the "hotword recognizing" state is handled by the |
274 // hotword extension. | 278 // hotword extension. |
275 if (HotwordService::IsExperimentalHotwordingEnabled()) { | 279 if (HotwordService::IsExperimentalHotwordingEnabled()) { |
276 state_ = app_list::SPEECH_RECOGNITION_READY; | 280 state_ = app_list::SPEECH_RECOGNITION_READY; |
277 } | 281 } |
278 | 282 |
279 if (app_list::switches::IsExperimentalAppListEnabled()) | 283 if (app_list::switches::IsExperimentalAppListEnabled()) |
280 LoadContents(); | 284 LoadContents(); |
281 | 285 |
286 TemplateURLService* template_url_service = | |
287 TemplateURLServiceFactory::GetForProfile(profile_); | |
288 const TemplateURL* default_provider = | |
289 template_url_service->GetDefaultSearchProvider(); | |
290 search_engine_is_google_ = | |
291 TemplateURLPrepopulateData::GetEngineType( | |
292 *default_provider, template_url_service->search_terms_data()) == | |
293 SEARCH_ENGINE_GOOGLE; | |
294 | |
282 network_change_observer_.reset(new NetworkChangeObserver(this)); | 295 network_change_observer_.reset(new NetworkChangeObserver(this)); |
283 } | 296 } |
284 | 297 |
285 StartPageService::~StartPageService() {} | 298 StartPageService::~StartPageService() { |
299 } | |
286 | 300 |
287 void StartPageService::AddObserver(StartPageObserver* observer) { | 301 void StartPageService::AddObserver(StartPageObserver* observer) { |
288 observers_.AddObserver(observer); | 302 observers_.AddObserver(observer); |
289 } | 303 } |
290 | 304 |
291 void StartPageService::RemoveObserver(StartPageObserver* observer) { | 305 void StartPageService::RemoveObserver(StartPageObserver* observer) { |
292 observers_.RemoveObserver(observer); | 306 observers_.RemoveObserver(observer); |
293 } | 307 } |
294 | 308 |
295 void StartPageService::OnMicrophoneChanged(bool available) { | 309 void StartPageService::OnMicrophoneChanged(bool available) { |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 566 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
553 std::string()); | 567 std::string()); |
554 } | 568 } |
555 | 569 |
556 void StartPageService::UnloadContents() { | 570 void StartPageService::UnloadContents() { |
557 contents_.reset(); | 571 contents_.reset(); |
558 webui_finished_loading_ = false; | 572 webui_finished_loading_ = false; |
559 } | 573 } |
560 | 574 |
561 void StartPageService::FetchDoodleJson() { | 575 void StartPageService::FetchDoodleJson() { |
576 if (!search_engine_is_google_) | |
577 return; | |
578 | |
562 GURL::Replacements replacements; | 579 GURL::Replacements replacements; |
563 replacements.SetPathStr(kDoodleJsonPath); | 580 replacements.SetPathStr(kDoodleJsonPath); |
564 | 581 |
565 GURL google_base_url(UIThreadSearchTermsData(profile_).GoogleBaseURLValue()); | 582 GURL google_base_url(UIThreadSearchTermsData(profile_).GoogleBaseURLValue()); |
566 GURL doodle_url = google_base_url.ReplaceComponents(replacements); | 583 GURL doodle_url = google_base_url.ReplaceComponents(replacements); |
567 doodle_fetcher_.reset( | 584 doodle_fetcher_.reset( |
568 net::URLFetcher::Create(0, doodle_url, net::URLFetcher::GET, this)); | 585 net::URLFetcher::Create(0, doodle_url, net::URLFetcher::GET, this)); |
569 doodle_fetcher_->SetRequestContext(profile_->GetRequestContext()); | 586 doodle_fetcher_->SetRequestContext(profile_->GetRequestContext()); |
570 doodle_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); | 587 doodle_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); |
571 doodle_fetcher_->Start(); | 588 doodle_fetcher_->Start(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
609 | 626 |
610 // Check for a new doodle. | 627 // Check for a new doodle. |
611 content::BrowserThread::PostDelayedTask( | 628 content::BrowserThread::PostDelayedTask( |
612 content::BrowserThread::UI, FROM_HERE, | 629 content::BrowserThread::UI, FROM_HERE, |
613 base::Bind(&StartPageService::FetchDoodleJson, | 630 base::Bind(&StartPageService::FetchDoodleJson, |
614 weak_factory_.GetWeakPtr()), | 631 weak_factory_.GetWeakPtr()), |
615 recheck_delay); | 632 recheck_delay); |
616 } | 633 } |
617 | 634 |
618 } // namespace app_list | 635 } // namespace app_list |
OLD | NEW |