Commit de91a933 authored by pkasting's avatar pkasting Committed by Commit bot

Use UIThreadSearchTermsData to get the Google base URL.

This simplifies the code some by eliminating google_profile_helper entirely, and
ensures that everyone who is trying to construct a "search URL" will correctly
respect things like the command-line Google base URL override switch.

This also moves some related code from URLRequestMockHTTPJob into its lone
caller and stops assuming that the search URL scheme is always HTTP.

BUG=364183
TEST=none

Review URL: https://codereview.chromium.org/896943002

Cr-Commit-Position: refs/heads/master@{#314600}
parent a3873d3d
...@@ -5,11 +5,10 @@ ...@@ -5,11 +5,10 @@
#include "chrome/browser/android/logo_service.h" #include "chrome/browser/android/logo_service.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/browser/google/google_profile_helper.h"
#include "chrome/browser/image_decoder.h" #include "chrome/browser/image_decoder.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/template_url_service_factory.h"
#include "components/google/core/browser/google_util.h" #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/search_engines/template_url_service.h" #include "components/search_engines/template_url_service.h"
#include "components/search_provider_logos/google_logo_api.h" #include "components/search_provider_logos/google_logo_api.h"
...@@ -23,7 +22,6 @@ using search_provider_logos::LogoTracker; ...@@ -23,7 +22,6 @@ using search_provider_logos::LogoTracker;
namespace { namespace {
const char kGoogleDoodleURLPath[] = "async/newtab_mobile";
const char kCachedLogoDirectory[] = "Search Logo"; const char kCachedLogoDirectory[] = "Search Logo";
const int kDecodeLogoTimeoutSeconds = 30; const int kDecodeLogoTimeoutSeconds = 30;
...@@ -31,16 +29,14 @@ const int kDecodeLogoTimeoutSeconds = 30; ...@@ -31,16 +29,14 @@ const int kDecodeLogoTimeoutSeconds = 30;
// https://www.google.com/async/newtab_mobile. This depends on the user's // https://www.google.com/async/newtab_mobile. This depends on the user's
// Google domain. // Google domain.
GURL GetGoogleDoodleURL(Profile* profile) { GURL GetGoogleDoodleURL(Profile* profile) {
// SetPathStr() requires its argument to stay in scope as long as GURL google_base_url(UIThreadSearchTermsData(profile).GoogleBaseURLValue());
// |replacements| is, so a std::string is needed, instead of a char*. const char kGoogleDoodleURLPath[] = "async/newtab_mobile";
std::string path = kGoogleDoodleURLPath; // The string passed to SetPathStr() must stay alive until after
// ReplaceComponents(), so declare it on the stack here instead of inline.
std::string path(kGoogleDoodleURLPath);
GURL::Replacements replacements; GURL::Replacements replacements;
replacements.SetPathStr(path); replacements.SetPathStr(path);
return google_base_url.ReplaceComponents(replacements);
GURL base_url(google_util::CommandLineGoogleBaseURL());
if (!base_url.is_valid())
base_url = google_profile_helper::GetGoogleHomePageURL(profile);
return base_url.ReplaceComponents(replacements);
} }
class LogoDecoderDelegate : public ImageDecoder::Delegate { class LogoDecoderDelegate : public ImageDecoder::Delegate {
......
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h" #include "chrome/browser/browsing_data/browsing_data_helper.h"
#include "chrome/browser/browsing_data/browsing_data_remover.h" #include "chrome/browser/browsing_data/browsing_data_remover.h"
#include "chrome/browser/google/google_profile_helper.h"
#include "chrome/browser/net/url_request_mock_util.h" #include "chrome/browser/net/url_request_mock_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
...@@ -279,10 +279,11 @@ void InstallMockInterceptors( ...@@ -279,10 +279,11 @@ void InstallMockInterceptors(
// Add a mock for the search engine the error page will use. // Add a mock for the search engine the error page will use.
base::FilePath root_http; base::FilePath root_http;
PathService::Get(chrome::DIR_TEST_DATA, &root_http); PathService::Get(chrome::DIR_TEST_DATA, &root_http);
net::URLRequestMockHTTPJob::AddHostnameToFileHandler( net::URLRequestFilter::GetInstance()->AddHostnameInterceptor(
search_url.host(), search_url.scheme(), search_url.host(),
root_http.AppendASCII("title3.html"), net::URLRequestMockHTTPJob::CreateInterceptorForSingleFile(
BrowserThread::GetBlockingPool()); root_http.AppendASCII("title3.html"),
BrowserThread::GetBlockingPool()));
} }
class ErrorPageTest : public InProcessBrowserTest { class ErrorPageTest : public InProcessBrowserTest {
...@@ -412,12 +413,11 @@ class ErrorPageTest : public InProcessBrowserTest { ...@@ -412,12 +413,11 @@ class ErrorPageTest : public InProcessBrowserTest {
// Ownership of the |interceptor_| is passed to an object the IO thread, but // Ownership of the |interceptor_| is passed to an object the IO thread, but
// a pointer is kept in the test fixture. As soon as anything calls // a pointer is kept in the test fixture. As soon as anything calls
// URLRequestFilter::ClearHandlers(), |interceptor_| can become invalid. // URLRequestFilter::ClearHandlers(), |interceptor_| can become invalid.
UIThreadSearchTermsData search_terms_data(browser()->profile());
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
base::Bind(&InstallMockInterceptors, base::Bind(&InstallMockInterceptors,
google_util::GetGoogleSearchURL( GURL(search_terms_data.GoogleBaseURLValue()),
google_profile_helper::GetGoogleHomePageURL(
browser()->profile())),
base::Passed(&owned_interceptor))); base::Passed(&owned_interceptor)));
} }
......
// 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.
#include "chrome/browser/google/google_profile_helper.h"
#include "chrome/browser/google/google_url_tracker_factory.h"
#include "components/google/core/browser/google_url_tracker.h"
#include "components/google/core/browser/google_util.h"
#include "url/gurl.h"
namespace google_profile_helper {
GURL GetGoogleHomePageURL(Profile* profile) {
const GoogleURLTracker* tracker =
GoogleURLTrackerFactory::GetForProfile(profile);
return tracker ?
tracker->google_url() : GURL(GoogleURLTracker::kDefaultGoogleHomepage);
}
} // namespace google_profile_helper
// 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.
//
// Provides Google-related information for a given Profile.
#ifndef CHROME_BROWSER_GOOGLE_GOOGLE_PROFILE_HELPER_H__
#define CHROME_BROWSER_GOOGLE_GOOGLE_PROFILE_HELPER_H__
#include <string>
#include "base/basictypes.h"
class GURL;
class Profile;
namespace google_profile_helper {
// Returns the current Google homepage URL. Guaranteed to synchronously return
// a value at all times (even during startup, in unittest mode or if |profile|
// is NULL).
GURL GetGoogleHomePageURL(Profile* profile);
} // namespace google_profile_helper
#endif // CHROME_BROWSER_GOOGLE_GOOGLE_PROFILE_HELPER_H__
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/google/google_brand.h" #include "chrome/browser/google/google_brand.h"
#include "chrome/browser/google/google_profile_helper.h" #include "chrome/browser/google/google_url_tracker_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/instant_service.h" #include "chrome/browser/search/instant_service.h"
#include "chrome/browser/search/instant_service_factory.h" #include "chrome/browser/search/instant_service_factory.h"
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h" #include "chrome/common/chrome_version_info.h"
#include "components/google/core/browser/google_url_tracker.h"
#include "components/google/core/browser/google_util.h" #include "components/google/core/browser/google_util.h"
#include "components/omnibox/omnibox_field_trial.h" #include "components/omnibox/omnibox_field_trial.h"
#include "components/search/search.h" #include "components/search/search.h"
...@@ -49,9 +50,14 @@ std::string UIThreadSearchTermsData::GoogleBaseURLValue() const { ...@@ -49,9 +50,14 @@ std::string UIThreadSearchTermsData::GoogleBaseURLValue() const {
GURL base_url(google_util::CommandLineGoogleBaseURL()); GURL base_url(google_util::CommandLineGoogleBaseURL());
if (base_url.is_valid()) if (base_url.is_valid())
return base_url.spec(); return base_url.spec();
return profile_ ?
google_profile_helper::GetGoogleHomePageURL(profile_).spec() : if (!profile_)
SearchTermsData::GoogleBaseURLValue(); return SearchTermsData::GoogleBaseURLValue();
const GoogleURLTracker* tracker =
GoogleURLTrackerFactory::GetForProfile(profile_);
return tracker ?
tracker->google_url().spec() : GoogleURLTracker::kDefaultGoogleHomepage;
} }
std::string UIThreadSearchTermsData::GetApplicationLocale() const { std::string UIThreadSearchTermsData::GetApplicationLocale() const {
......
...@@ -14,11 +14,11 @@ ...@@ -14,11 +14,11 @@
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/google/google_profile_helper.h"
#include "chrome/browser/media/media_stream_infobar_delegate.h" #include "chrome/browser/media/media_stream_infobar_delegate.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/hotword_service.h" #include "chrome/browser/search/hotword_service.h"
#include "chrome/browser/search/hotword_service_factory.h" #include "chrome/browser/search/hotword_service_factory.h"
#include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
#include "chrome/browser/ui/app_list/speech_auth_helper.h" #include "chrome/browser/ui/app_list/speech_auth_helper.h"
#include "chrome/browser/ui/app_list/speech_recognizer.h" #include "chrome/browser/ui/app_list/speech_recognizer.h"
#include "chrome/browser/ui/app_list/start_page_observer.h" #include "chrome/browser/ui/app_list/start_page_observer.h"
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "components/google/core/browser/google_util.h"
#include "components/ui/zoom/zoom_controller.h" #include "components/ui/zoom/zoom_controller.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
...@@ -70,14 +69,6 @@ bool InSpeechRecognition(SpeechRecognitionState state) { ...@@ -70,14 +69,6 @@ bool InSpeechRecognition(SpeechRecognitionState state) {
state == SPEECH_RECOGNITION_IN_SPEECH; state == SPEECH_RECOGNITION_IN_SPEECH;
} }
GURL GetGoogleBaseURL(Profile* profile) {
GURL base_url(google_util::CommandLineGoogleBaseURL());
if (!base_url.is_valid())
base_url = google_profile_helper::GetGoogleHomePageURL(profile);
return base_url;
}
} // namespace } // namespace
class StartPageService::ProfileDestroyObserver class StartPageService::ProfileDestroyObserver
...@@ -573,7 +564,8 @@ void StartPageService::FetchDoodleJson() { ...@@ -573,7 +564,8 @@ void StartPageService::FetchDoodleJson() {
GURL::Replacements replacements; GURL::Replacements replacements;
replacements.SetPathStr(path); replacements.SetPathStr(path);
GURL doodle_url = GetGoogleBaseURL(profile_).ReplaceComponents(replacements); GURL google_base_url(UIThreadSearchTermsData(profile_).GoogleBaseURLValue());
GURL doodle_url = google_base_url.ReplaceComponents(replacements);
doodle_fetcher_.reset( doodle_fetcher_.reset(
net::URLFetcher::Create(0, doodle_url, net::URLFetcher::GET, this)); net::URLFetcher::Create(0, doodle_url, net::URLFetcher::GET, this));
doodle_fetcher_->SetRequestContext(profile_->GetRequestContext()); doodle_fetcher_->SetRequestContext(profile_->GetRequestContext());
...@@ -612,7 +604,8 @@ void StartPageService::OnURLFetchComplete(const net::URLFetcher* source) { ...@@ -612,7 +604,8 @@ void StartPageService::OnURLFetchComplete(const net::URLFetcher* source) {
contents_->GetWebUI()->CallJavascriptFunction( contents_->GetWebUI()->CallJavascriptFunction(
"appList.startPage.onAppListDoodleUpdated", *doodle_json, "appList.startPage.onAppListDoodleUpdated", *doodle_json,
base::StringValue(GetGoogleBaseURL(profile_).spec())); base::StringValue(
UIThreadSearchTermsData(profile_).GoogleBaseURLValue()));
} }
// Check for a new doodle. // Check for a new doodle.
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/google/google_profile_helper.h"
#include "chrome/browser/google/google_url_tracker_factory.h" #include "chrome/browser/google/google_url_tracker_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/render_messages.h" #include "chrome/common/render_messages.h"
#include "components/google/core/browser/google_util.h" #include "components/google/core/browser/google_util.h"
...@@ -95,13 +95,12 @@ void NavigationCorrectionTabObserver::OnEnabledChanged() { ...@@ -95,13 +95,12 @@ void NavigationCorrectionTabObserver::OnEnabledChanged() {
void NavigationCorrectionTabObserver::UpdateNavigationCorrectionInfo( void NavigationCorrectionTabObserver::UpdateNavigationCorrectionInfo(
RenderViewHost* rvh) { RenderViewHost* rvh) {
RenderFrameHost* rfh = rvh->GetMainFrame(); RenderFrameHost* rfh = rvh->GetMainFrame();
GURL google_base_url(UIThreadSearchTermsData(profile_).GoogleBaseURLValue());
rfh->Send(new ChromeViewMsg_SetNavigationCorrectionInfo( rfh->Send(new ChromeViewMsg_SetNavigationCorrectionInfo(
rfh->GetRoutingID(), rfh->GetRoutingID(),
GetNavigationCorrectionURL(), GetNavigationCorrectionURL(),
google_util::GetGoogleLocale(g_browser_process->GetApplicationLocale()), google_util::GetGoogleLocale(g_browser_process->GetApplicationLocale()),
google_util::GetGoogleCountryCode( google_util::GetGoogleCountryCode(google_base_url),
google_profile_helper::GetGoogleHomePageURL(profile_)),
google_apis::GetAPIKey(), google_apis::GetAPIKey(),
google_util::GetGoogleSearchURL( google_util::GetGoogleSearchURL(google_base_url)));
google_profile_helper::GetGoogleHomePageURL(profile_))));
} }
...@@ -1476,8 +1476,6 @@ ...@@ -1476,8 +1476,6 @@
'browser/google/google_brand.h', 'browser/google/google_brand.h',
'browser/google/google_brand_chromeos.cc', 'browser/google/google_brand_chromeos.cc',
'browser/google/google_brand_chromeos.h', 'browser/google/google_brand_chromeos.h',
'browser/google/google_profile_helper.cc',
'browser/google/google_profile_helper.h',
'browser/google/google_search_counter.cc', 'browser/google/google_search_counter.cc',
'browser/google/google_search_counter.h', 'browser/google/google_search_counter.h',
'browser/google/google_search_counter_android.cc', 'browser/google/google_search_counter_android.cc',
......
...@@ -121,16 +121,6 @@ void URLRequestMockHTTPJob::AddUrlHandlers( ...@@ -121,16 +121,6 @@ void URLRequestMockHTTPJob::AddUrlHandlers(
CreateInterceptor(base_path, worker_pool)); CreateInterceptor(base_path, worker_pool));
} }
// static
void URLRequestMockHTTPJob::AddHostnameToFileHandler(
const std::string& hostname,
const base::FilePath& file,
const scoped_refptr<base::SequencedWorkerPool>& worker_pool) {
net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance();
filter->AddHostnameInterceptor(
"http", hostname, CreateInterceptorForSingleFile(file, worker_pool));
}
// static // static
GURL URLRequestMockHTTPJob::GetMockUrl(const base::FilePath& path) { GURL URLRequestMockHTTPJob::GetMockUrl(const base::FilePath& path) {
return GetMockUrlForScheme(path, "http"); return GetMockUrlForScheme(path, "http");
......
...@@ -54,13 +54,6 @@ class URLRequestMockHTTPJob : public URLRequestFileJob { ...@@ -54,13 +54,6 @@ class URLRequestMockHTTPJob : public URLRequestFileJob {
const base::FilePath& base_path, const base::FilePath& base_path,
const scoped_refptr<base::SequencedWorkerPool>& worker_pool); const scoped_refptr<base::SequencedWorkerPool>& worker_pool);
// Respond to all HTTP requests of |hostname| with contents of the file
// located at |file_path|.
static void AddHostnameToFileHandler(
const std::string& hostname,
const base::FilePath& file,
const scoped_refptr<base::SequencedWorkerPool>& worker_pool);
// Given the path to a file relative to the path passed to AddUrlHandler(), // Given the path to a file relative to the path passed to AddUrlHandler(),
// construct a mock URL. // construct a mock URL.
static GURL GetMockUrl(const base::FilePath& path); static GURL GetMockUrl(const base::FilePath& path);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment