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

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

Issue 896943002: Use UIThreadSearchTermsData to get the Google base URL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Compile fixes Created 5 years, 10 months 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/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 "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/google/google_profile_helper.h"
18 #include "chrome/browser/media/media_stream_infobar_delegate.h" 17 #include "chrome/browser/media/media_stream_infobar_delegate.h"
19 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/search/hotword_service.h" 19 #include "chrome/browser/search/hotword_service.h"
21 #include "chrome/browser/search/hotword_service_factory.h" 20 #include "chrome/browser/search/hotword_service_factory.h"
21 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
22 #include "chrome/browser/ui/app_list/speech_auth_helper.h" 22 #include "chrome/browser/ui/app_list/speech_auth_helper.h"
23 #include "chrome/browser/ui/app_list/speech_recognizer.h" 23 #include "chrome/browser/ui/app_list/speech_recognizer.h"
24 #include "chrome/browser/ui/app_list/start_page_observer.h" 24 #include "chrome/browser/ui/app_list/start_page_observer.h"
25 #include "chrome/browser/ui/app_list/start_page_service_factory.h" 25 #include "chrome/browser/ui/app_list/start_page_service_factory.h"
26 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
28 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
29 #include "components/google/core/browser/google_util.h"
30 #include "components/ui/zoom/zoom_controller.h" 29 #include "components/ui/zoom/zoom_controller.h"
31 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/notification_details.h" 31 #include "content/public/browser/notification_details.h"
33 #include "content/public/browser/notification_observer.h" 32 #include "content/public/browser/notification_observer.h"
34 #include "content/public/browser/notification_registrar.h" 33 #include "content/public/browser/notification_registrar.h"
35 #include "content/public/browser/notification_service.h" 34 #include "content/public/browser/notification_service.h"
36 #include "content/public/browser/notification_source.h" 35 #include "content/public/browser/notification_source.h"
37 #include "content/public/browser/speech_recognition_session_preamble.h" 36 #include "content/public/browser/speech_recognition_session_preamble.h"
38 #include "content/public/browser/web_contents.h" 37 #include "content/public/browser/web_contents.h"
39 #include "content/public/browser/web_contents_delegate.h" 38 #include "content/public/browser/web_contents_delegate.h"
(...skipping 20 matching lines...) Expand all
60 const char kDoodleJsonPath[] = "async/ddljson"; 59 const char kDoodleJsonPath[] = "async/ddljson";
61 60
62 // Delay between checking for a new doodle when no doodle is found. 61 // Delay between checking for a new doodle when no doodle is found.
63 const int kDefaultDoodleRecheckDelayMinutes = 30; 62 const int kDefaultDoodleRecheckDelayMinutes = 30;
64 63
65 bool InSpeechRecognition(SpeechRecognitionState state) { 64 bool InSpeechRecognition(SpeechRecognitionState state) {
66 return state == SPEECH_RECOGNITION_RECOGNIZING || 65 return state == SPEECH_RECOGNITION_RECOGNIZING ||
67 state == SPEECH_RECOGNITION_IN_SPEECH; 66 state == SPEECH_RECOGNITION_IN_SPEECH;
68 } 67 }
69 68
70 GURL GetGoogleBaseURL(Profile* profile) {
71 GURL base_url(google_util::CommandLineGoogleBaseURL());
72 if (!base_url.is_valid())
73 base_url = google_profile_helper::GetGoogleHomePageURL(profile);
74
75 return base_url;
76 }
77
78 } // namespace 69 } // namespace
79 70
80 class StartPageService::ProfileDestroyObserver 71 class StartPageService::ProfileDestroyObserver
81 : public content::NotificationObserver { 72 : public content::NotificationObserver {
82 public: 73 public:
83 explicit ProfileDestroyObserver(StartPageService* service) 74 explicit ProfileDestroyObserver(StartPageService* service)
84 : service_(service) { 75 : service_(service) {
85 registrar_.Add(this, 76 registrar_.Add(this,
86 chrome::NOTIFICATION_PROFILE_DESTROYED, 77 chrome::NOTIFICATION_PROFILE_DESTROYED,
87 content::Source<Profile>(service_->profile())); 78 content::Source<Profile>(service_->profile()));
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 webui_finished_loading_ = false; 510 webui_finished_loading_ = false;
520 } 511 }
521 512
522 void StartPageService::FetchDoodleJson() { 513 void StartPageService::FetchDoodleJson() {
523 // SetPathStr() requires its argument to stay in scope as long as 514 // SetPathStr() requires its argument to stay in scope as long as
524 // |replacements| is, so a std::string is needed, instead of a char*. 515 // |replacements| is, so a std::string is needed, instead of a char*.
525 std::string path = kDoodleJsonPath; 516 std::string path = kDoodleJsonPath;
526 GURL::Replacements replacements; 517 GURL::Replacements replacements;
527 replacements.SetPathStr(path); 518 replacements.SetPathStr(path);
528 519
529 GURL doodle_url = GetGoogleBaseURL(profile_).ReplaceComponents(replacements); 520 GURL google_base_url(UIThreadSearchTermsData(profile_).GoogleBaseURLValue());
521 GURL doodle_url = google_base_url.ReplaceComponents(replacements);
530 doodle_fetcher_.reset( 522 doodle_fetcher_.reset(
531 net::URLFetcher::Create(0, doodle_url, net::URLFetcher::GET, this)); 523 net::URLFetcher::Create(0, doodle_url, net::URLFetcher::GET, this));
532 doodle_fetcher_->SetRequestContext(profile_->GetRequestContext()); 524 doodle_fetcher_->SetRequestContext(profile_->GetRequestContext());
533 doodle_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); 525 doodle_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES);
534 doodle_fetcher_->Start(); 526 doodle_fetcher_->Start();
535 } 527 }
536 528
537 void StartPageService::OnURLFetchComplete(const net::URLFetcher* source) { 529 void StartPageService::OnURLFetchComplete(const net::URLFetcher* source) {
538 std::string json_data; 530 std::string json_data;
539 source->GetResponseAsString(&json_data); 531 source->GetResponseAsString(&json_data);
(...skipping 18 matching lines...) Expand all
558 if (doodle_json->GetAsDictionary(&doodle_dictionary)) { 550 if (doodle_json->GetAsDictionary(&doodle_dictionary)) {
559 int time_to_live = 0; 551 int time_to_live = 0;
560 if (doodle_dictionary->GetInteger("ddljson.time_to_live_ms", 552 if (doodle_dictionary->GetInteger("ddljson.time_to_live_ms",
561 &time_to_live)) { 553 &time_to_live)) {
562 recheck_delay = base::TimeDelta::FromMilliseconds(time_to_live); 554 recheck_delay = base::TimeDelta::FromMilliseconds(time_to_live);
563 } 555 }
564 } 556 }
565 557
566 contents_->GetWebUI()->CallJavascriptFunction( 558 contents_->GetWebUI()->CallJavascriptFunction(
567 "appList.startPage.onAppListDoodleUpdated", *doodle_json, 559 "appList.startPage.onAppListDoodleUpdated", *doodle_json,
568 base::StringValue(GetGoogleBaseURL(profile_).spec())); 560 base::StringValue(
561 UIThreadSearchTermsData(profile_).GoogleBaseURLValue()));
569 } 562 }
570 563
571 // Check for a new doodle. 564 // Check for a new doodle.
572 content::BrowserThread::PostDelayedTask( 565 content::BrowserThread::PostDelayedTask(
573 content::BrowserThread::UI, FROM_HERE, 566 content::BrowserThread::UI, FROM_HERE,
574 base::Bind(&StartPageService::FetchDoodleJson, 567 base::Bind(&StartPageService::FetchDoodleJson,
575 weak_factory_.GetWeakPtr()), 568 weak_factory_.GetWeakPtr()),
576 recheck_delay); 569 recheck_delay);
577 } 570 }
578 571
579 } // namespace app_list 572 } // namespace app_list
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/ui_thread_search_terms_data.cc ('k') | chrome/browser/ui/navigation_correction_tab_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698