diff options
Diffstat (limited to 'chrome/browser/google')
17 files changed, 39 insertions, 1013 deletions
diff --git a/chrome/browser/google/chrome_google_url_tracker_client.cc b/chrome/browser/google/chrome_google_url_tracker_client.cc index 85278ab..5f48e00 100644 --- a/chrome/browser/google/chrome_google_url_tracker_client.cc +++ b/chrome/browser/google/chrome_google_url_tracker_client.cc @@ -6,11 +6,12 @@ #include "base/command_line.h" #include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/google/google_url_tracker_navigation_helper_impl.h" +#include "chrome/browser/google/google_util.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_switches.h" +#include "components/google/core/browser/google_url_tracker.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/notification_service.h" @@ -58,6 +59,17 @@ ChromeGoogleURLTrackerClient::GetRequestContext() { return profile_->GetRequestContext(); } +bool ChromeGoogleURLTrackerClient::IsGoogleDomainURL(const GURL& url) { + return google_util::IsGoogleDomainUrl( + url, + google_util::DISALLOW_SUBDOMAIN, + google_util::DISALLOW_NON_STANDARD_PORTS); +} + +GURL ChromeGoogleURLTrackerClient::AppendGoogleLocaleParam(const GURL& url) { + return google_util::AppendGoogleLocaleParam(url); +} + void ChromeGoogleURLTrackerClient::Observe( int type, const content::NotificationSource& source, diff --git a/chrome/browser/google/chrome_google_url_tracker_client.h b/chrome/browser/google/chrome_google_url_tracker_client.h index 08a4e2e..3c166fe 100644 --- a/chrome/browser/google/chrome_google_url_tracker_client.h +++ b/chrome/browser/google/chrome_google_url_tracker_client.h @@ -23,6 +23,8 @@ class ChromeGoogleURLTrackerClient : public GoogleURLTrackerClient, virtual bool IsBackgroundNetworkingEnabled() OVERRIDE; virtual PrefService* GetPrefs() OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; + virtual bool IsGoogleDomainURL(const GURL& url) OVERRIDE; + virtual GURL AppendGoogleLocaleParam(const GURL& url) OVERRIDE; private: // content::NotificationObserver: diff --git a/chrome/browser/google/google_profile_helper.cc b/chrome/browser/google/google_profile_helper.cc index 0098275..3f0b962 100644 --- a/chrome/browser/google/google_profile_helper.cc +++ b/chrome/browser/google/google_profile_helper.cc @@ -4,9 +4,9 @@ #include "chrome/browser/google/google_profile_helper.h" -#include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/google/google_url_tracker_factory.h" #include "chrome/browser/google/google_util.h" +#include "components/google/core/browser/google_url_tracker.h" #include "url/gurl.h" namespace google_profile_helper { diff --git a/chrome/browser/google/google_url_tracker.cc b/chrome/browser/google/google_url_tracker.cc deleted file mode 100644 index 77cdaad..0000000 --- a/chrome/browser/google/google_url_tracker.cc +++ /dev/null @@ -1,407 +0,0 @@ -// Copyright (c) 2012 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_url_tracker.h" - -#include "base/bind.h" -#include "base/command_line.h" -#include "base/prefs/pref_service.h" -#include "base/strings/string_util.h" -#include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/google/google_url_tracker_factory.h" -#include "chrome/browser/google/google_url_tracker_infobar_delegate.h" -#include "chrome/browser/google/google_url_tracker_navigation_helper.h" -#include "chrome/browser/google/google_util.h" -#include "chrome/common/pref_names.h" -#include "components/google/core/browser/google_pref_names.h" -#include "components/google/core/browser/google_switches.h" -#include "components/google/core/browser/google_url_tracker_client.h" -#include "components/infobars/core/infobar.h" -#include "components/infobars/core/infobar_manager.h" -#include "content/public/browser/notification_service.h" -#include "net/base/load_flags.h" -#include "net/base/net_util.h" -#include "net/url_request/url_fetcher.h" -#include "net/url_request/url_request_status.h" - - -const char GoogleURLTracker::kDefaultGoogleHomepage[] = - "http://www.google.com/"; -const char GoogleURLTracker::kSearchDomainCheckURL[] = - "https://www.google.com/searchdomaincheck?format=url&type=chrome"; - -GoogleURLTracker::GoogleURLTracker(scoped_ptr<GoogleURLTrackerClient> client, - Mode mode) - : client_(client.Pass()), - google_url_(mode == UNIT_TEST_MODE ? - kDefaultGoogleHomepage : - client_->GetPrefs()->GetString(prefs::kLastKnownGoogleURL)), - fetcher_id_(0), - in_startup_sleep_(true), - already_fetched_(false), - need_to_fetch_(false), - need_to_prompt_(false), - search_committed_(false), - weak_ptr_factory_(this) { - net::NetworkChangeNotifier::AddIPAddressObserver(this); - client_->set_google_url_tracker(this); - - // Because this function can be called during startup, when kicking off a URL - // fetch can eat up 20 ms of time, we delay five seconds, which is hopefully - // long enough to be after startup, but still get results back quickly. - // Ideally, instead of this timer, we'd do something like "check if the - // browser is starting up, and if so, come back later", but there is currently - // no function to do this. - // - // In UNIT_TEST mode, where we want to explicitly control when the tracker - // "wakes up", we do nothing at all. - if (mode == NORMAL_MODE) { - static const int kStartFetchDelayMS = 5000; - base::MessageLoop::current()->PostDelayedTask(FROM_HERE, - base::Bind(&GoogleURLTracker::FinishSleep, - weak_ptr_factory_.GetWeakPtr()), - base::TimeDelta::FromMilliseconds(kStartFetchDelayMS)); - } -} - -GoogleURLTracker::~GoogleURLTracker() { - // We should only reach here after any tabs and their infobars have been torn - // down. - DCHECK(entry_map_.empty()); -} - -void GoogleURLTracker::RequestServerCheck(bool force) { - // If this instance already has a fetcher, SetNeedToFetch() is unnecessary, - // and changing |already_fetched_| is wrong. - if (!fetcher_) { - if (force) - already_fetched_ = false; - SetNeedToFetch(); - } -} - -void GoogleURLTracker::SearchCommitted() { - if (need_to_prompt_) { - search_committed_ = true; - // These notifications will fire a bit later in the same call chain we're - // currently in. - if (!client_->IsListeningForNavigationStart()) - client_->SetListeningForNavigationStart(true); - } -} - -void GoogleURLTracker::AcceptGoogleURL(bool redo_searches) { - GURL old_google_url = google_url_; - google_url_ = fetched_google_url_; - PrefService* prefs = client_->GetPrefs(); - prefs->SetString(prefs::kLastKnownGoogleURL, google_url_.spec()); - prefs->SetString(prefs::kLastPromptedGoogleURL, google_url_.spec()); - NotifyGoogleURLUpdated(old_google_url, google_url_); - - need_to_prompt_ = false; - CloseAllEntries(redo_searches); -} - -void GoogleURLTracker::CancelGoogleURL() { - client_->GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, - fetched_google_url_.spec()); - need_to_prompt_ = false; - CloseAllEntries(false); -} - -void GoogleURLTracker::OnURLFetchComplete(const net::URLFetcher* source) { - // Delete the fetcher on this function's exit. - scoped_ptr<net::URLFetcher> clean_up_fetcher(fetcher_.release()); - - // Don't update the URL if the request didn't succeed. - if (!source->GetStatus().is_success() || (source->GetResponseCode() != 200)) { - already_fetched_ = false; - return; - } - - // See if the response data was valid. It should be - // "<scheme>://[www.]google.<TLD>/". - std::string url_str; - source->GetResponseAsString(&url_str); - base::TrimWhitespace(url_str, base::TRIM_ALL, &url_str); - GURL url(url_str); - if (!url.is_valid() || (url.path().length() > 1) || url.has_query() || - url.has_ref() || - !google_util::IsGoogleDomainUrl(url, google_util::DISALLOW_SUBDOMAIN, - google_util::DISALLOW_NON_STANDARD_PORTS)) - return; - - std::swap(url, fetched_google_url_); - GURL last_prompted_url( - client_->GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); - - if (last_prompted_url.is_empty()) { - // On the very first run of Chrome, when we've never looked up the URL at - // all, we should just silently switch over to whatever we get immediately. - AcceptGoogleURL(true); // Arg is irrelevant. - return; - } - - base::string16 fetched_host(net::StripWWWFromHost(fetched_google_url_)); - if (fetched_google_url_ == google_url_) { - // Either the user has continually been on this URL, or we prompted for a - // different URL but have now changed back before they responded to any of - // the prompts. In this latter case we want to close any infobars and stop - // prompting. - CancelGoogleURL(); - } else if (fetched_host == net::StripWWWFromHost(google_url_)) { - // Similar to the above case, but this time the new URL differs from the - // existing one, probably due to switching between HTTP and HTTPS searching. - // Like before we want to close any infobars and stop prompting; we also - // want to silently accept the change in scheme. We don't redo open - // searches so as to avoid suddenly changing a page the user might be - // interacting with; it's enough to simply get future searches right. - AcceptGoogleURL(false); - } else if (fetched_host == net::StripWWWFromHost(last_prompted_url)) { - // We've re-fetched a TLD the user previously turned down. Although the new - // URL might have a different scheme than the old, we want to preserve the - // user's decision. Note that it's possible that, like in the above two - // cases, we fetched yet another different URL in the meantime, which we - // have infobars prompting about; in this case, as in those above, we want - // to go ahead and close the infobars and stop prompting, since we've - // switched back away from that URL. - CancelGoogleURL(); - } else { - // We've fetched a URL with a different TLD than the user is currently using - // or was previously prompted about. This means we need to prompt again. - need_to_prompt_ = true; - - // As in all the above cases, there could be infobars prompting about some - // URL. If these URLs have the same TLD (e.g. for scheme changes), we can - // simply leave the existing infobars open as their messages will still be - // accurate. Otherwise we go ahead and close them because we need to - // display a new message. - // Note: |url| is the previous |fetched_google_url_|. - if (url.is_valid() && (fetched_host != net::StripWWWFromHost(url))) - CloseAllEntries(false); - } -} - -void GoogleURLTracker::OnIPAddressChanged() { - already_fetched_ = false; - StartFetchIfDesirable(); -} - -void GoogleURLTracker::Shutdown() { - client_.reset(); - fetcher_.reset(); - weak_ptr_factory_.InvalidateWeakPtrs(); - net::NetworkChangeNotifier::RemoveIPAddressObserver(this); -} - -void GoogleURLTracker::DeleteMapEntryForManager( - const infobars::InfoBarManager* infobar_manager) { - // WARNING: |infobar_manager| may point to a deleted object. Do not - // dereference it! See OnTabClosed(). - EntryMap::iterator i(entry_map_.find(infobar_manager)); - DCHECK(i != entry_map_.end()); - GoogleURLTrackerMapEntry* map_entry = i->second; - - UnregisterForEntrySpecificNotifications(map_entry, false); - entry_map_.erase(i); - delete map_entry; -} - -void GoogleURLTracker::SetNeedToFetch() { - need_to_fetch_ = true; - StartFetchIfDesirable(); -} - -void GoogleURLTracker::FinishSleep() { - in_startup_sleep_ = false; - StartFetchIfDesirable(); -} - -void GoogleURLTracker::StartFetchIfDesirable() { - // Bail if a fetch isn't appropriate right now. This function will be called - // again each time one of the preconditions changes, so we'll fetch - // immediately once all of them are met. - // - // See comments in header on the class, on RequestServerCheck(), and on the - // various members here for more detail on exactly what the conditions are. - if (in_startup_sleep_ || already_fetched_ || !need_to_fetch_) - return; - - // Some switches should disable the Google URL tracker entirely. If we can't - // do background networking, we can't do the necessary fetch, and if the user - // specified a Google base URL manually, we shouldn't bother to look up any - // alternatives or offer to switch to them. - if (!client_->IsBackgroundNetworkingEnabled() || - CommandLine::ForCurrentProcess()->HasSwitch(switches::kGoogleBaseURL)) - return; - - already_fetched_ = true; - fetcher_.reset(net::URLFetcher::Create( - fetcher_id_, GURL(kSearchDomainCheckURL), net::URLFetcher::GET, this)); - ++fetcher_id_; - // We don't want this fetch to set new entries in the cache or cookies, lest - // we alarm the user. - fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE | - net::LOAD_DO_NOT_SAVE_COOKIES); - fetcher_->SetRequestContext(client_->GetRequestContext()); - - // Configure to max_retries at most kMaxRetries times for 5xx errors. - static const int kMaxRetries = 5; - fetcher_->SetMaxRetriesOn5xx(kMaxRetries); - - fetcher_->Start(); -} - -void GoogleURLTracker::OnNavigationPending( - scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper, - infobars::InfoBarManager* infobar_manager, - int pending_id) { - GoogleURLTrackerMapEntry* map_entry = NULL; - - EntryMap::iterator i(entry_map_.find(infobar_manager)); - if (i != entry_map_.end()) - map_entry = i->second; - - if (search_committed_) { - search_committed_ = false; - if (!map_entry) { - // This is a search on a tab that doesn't have one of our infobars, so - // prepare to add one. Note that we only listen for the tab's destruction - // on this path; if there was already a map entry, then either it doesn't - // yet have an infobar and we're already registered for this, or it has an - // infobar and the infobar's owner will handle tearing it down when the - // tab is destroyed. - map_entry = new GoogleURLTrackerMapEntry( - this, infobar_manager, nav_helper.Pass()); - map_entry->navigation_helper()->SetListeningForTabDestruction(true); - entry_map_.insert(std::make_pair(infobar_manager, map_entry)); - } else if (map_entry->infobar_delegate()) { - // This is a new search on a tab where we already have an infobar. - map_entry->infobar_delegate()->set_pending_id(pending_id); - } - - // Whether there's an existing infobar or not, we need to listen for the - // load to commit, so we can show and/or update the infobar when it does. - // (We may already be registered for this if there is an existing infobar - // that had a previous pending search that hasn't yet committed.) - if (!map_entry->navigation_helper()->IsListeningForNavigationCommit()) - map_entry->navigation_helper()->SetListeningForNavigationCommit(true); - } else if (map_entry) { - if (map_entry->has_infobar_delegate()) { - // This is a non-search navigation on a tab with an infobar. If there was - // a previous pending search on this tab, this means it won't commit, so - // undo anything we did in response to seeing that. Note that if there - // was no pending search on this tab, these statements are effectively a - // no-op. - // - // If this navigation actually commits, that will trigger the infobar's - // owner to expire the infobar if need be. If it doesn't commit, then - // simply leaving the infobar as-is will have been the right thing. - UnregisterForEntrySpecificNotifications(map_entry, false); - map_entry->infobar_delegate()->set_pending_id(0); - } else { - // Non-search navigation on a tab with an entry that has not yet created - // an infobar. This means the original search won't commit, so delete the - // entry. - map_entry->Close(false); - } - } else { - // Non-search navigation on a tab without an infobars. This is irrelevant - // to us. - } -} - -void GoogleURLTracker::OnNavigationCommitted( - infobars::InfoBarManager* infobar_manager, - const GURL& search_url) { - EntryMap::iterator i(entry_map_.find(infobar_manager)); - DCHECK(i != entry_map_.end()); - GoogleURLTrackerMapEntry* map_entry = i->second; - DCHECK(search_url.is_valid()); - - UnregisterForEntrySpecificNotifications(map_entry, true); - if (map_entry->has_infobar_delegate()) { - map_entry->infobar_delegate()->Update(search_url); - } else { - infobars::InfoBar* infobar = GoogleURLTrackerInfoBarDelegate::Create( - infobar_manager, this, search_url); - if (infobar) { - map_entry->SetInfoBarDelegate( - static_cast<GoogleURLTrackerInfoBarDelegate*>(infobar->delegate())); - } else { - map_entry->Close(false); - } - } -} - -void GoogleURLTracker::OnTabClosed( - GoogleURLTrackerNavigationHelper* nav_helper) { - // Because InfoBarManager tears itself down on tab destruction, it's possible - // to get a non-NULL InfoBarManager pointer here, depending on which order - // notifications fired in. Likewise, the pointer in |entry_map_| (and in its - // associated MapEntry) may point to deleted memory. Therefore, if we were - // to access the InfoBarManager* we have for this tab, we'd need to ensure we - // just looked at the raw pointer value, and never dereferenced it. This - // function doesn't need to do even that, but others in the call chain from - // here might (and have comments pointing back here). - for (EntryMap::iterator i(entry_map_.begin()); i != entry_map_.end(); ++i) { - if (i->second->navigation_helper() == nav_helper) { - i->second->Close(false); - return; - } - } - NOTREACHED(); -} - -scoped_ptr<GoogleURLTracker::Subscription> GoogleURLTracker::RegisterCallback( - const OnGoogleURLUpdatedCallback& cb) { - return callback_list_.Add(cb); -} - -void GoogleURLTracker::CloseAllEntries(bool redo_searches) { - // Delete all entries, whether they have infobars or not. - while (!entry_map_.empty()) - entry_map_.begin()->second->Close(redo_searches); -} - -void GoogleURLTracker::UnregisterForEntrySpecificNotifications( - GoogleURLTrackerMapEntry* map_entry, - bool must_be_listening_for_commit) { - // For tabs with map entries but no infobars, we should always be listening - // for both these notifications. For tabs with infobars, we may be listening - // for navigation commits if the user has performed a new search on this tab. - if (map_entry->navigation_helper()->IsListeningForNavigationCommit()) { - map_entry->navigation_helper()->SetListeningForNavigationCommit(false); - } else { - DCHECK(!must_be_listening_for_commit); - DCHECK(map_entry->has_infobar_delegate()); - } - const bool registered_for_tab_destruction = - map_entry->navigation_helper()->IsListeningForTabDestruction(); - DCHECK_NE(registered_for_tab_destruction, map_entry->has_infobar_delegate()); - if (registered_for_tab_destruction) { - map_entry->navigation_helper()->SetListeningForTabDestruction(false); - } - - // Our global listeners for these other notifications should be in place iff - // we have any tabs still listening for commits. These tabs either have no - // infobars or have received new pending searches atop existing infobars; in - // either case we want to catch subsequent pending non-search navigations. - // See the various cases inside OnNavigationPending(). - for (EntryMap::const_iterator i(entry_map_.begin()); i != entry_map_.end(); - ++i) { - if (i->second->navigation_helper()->IsListeningForNavigationCommit()) { - DCHECK(client_->IsListeningForNavigationStart()); - return; - } - } - if (client_->IsListeningForNavigationStart()) { - DCHECK(!search_committed_); - client_->SetListeningForNavigationStart(false); - } -} - -void GoogleURLTracker::NotifyGoogleURLUpdated(GURL old_url, GURL new_url) { - callback_list_.Notify(old_url, new_url); -} diff --git a/chrome/browser/google/google_url_tracker.h b/chrome/browser/google/google_url_tracker.h deleted file mode 100644 index c87a83f..0000000 --- a/chrome/browser/google/google_url_tracker.h +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright (c) 2012 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. - -#ifndef CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ -#define CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ - -#include <map> -#include <string> -#include <utility> - -#include "base/callback_forward.h" -#include "base/callback_list.h" -#include "base/gtest_prod_util.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" -#include "chrome/browser/google/google_url_tracker_map_entry.h" -#include "components/keyed_service/core/keyed_service.h" -#include "net/base/network_change_notifier.h" -#include "net/url_request/url_fetcher.h" -#include "net/url_request/url_fetcher_delegate.h" -#include "url/gurl.h" - -class GoogleURLTrackerClient; -class GoogleURLTrackerNavigationHelper; -class PrefService; - -namespace infobars { -class InfoBar; -} - -// This object is responsible for checking the Google URL once per network -// change, and if necessary prompting the user to see if they want to change to -// using it. The current and last prompted values are saved to prefs. -// -// Most consumers should only call google_url(). Consumers who need to be -// notified when things change should register a callback that provides the -// original and updated values via RegisterCallback(). -// -// To protect users' privacy and reduce server load, no updates will be -// performed (ever) unless at least one consumer registers interest by calling -// RequestServerCheck(). -class GoogleURLTracker : public net::URLFetcherDelegate, - public net::NetworkChangeNotifier::IPAddressObserver, - public KeyedService { - public: - // Callback that is called when the Google URL is updated. The arguments are - // the old and new URLs. - typedef base::Callback<void(GURL, GURL)> OnGoogleURLUpdatedCallback; - typedef base::CallbackList<void(GURL, GURL)> CallbackList; - typedef CallbackList::Subscription Subscription; - - // The constructor does different things depending on which of these values - // you pass it. Hopefully these are self-explanatory. - enum Mode { - NORMAL_MODE, - UNIT_TEST_MODE, - }; - - static const char kDefaultGoogleHomepage[]; - - // Only the GoogleURLTrackerFactory and tests should call this. - GoogleURLTracker(scoped_ptr<GoogleURLTrackerClient> client, Mode mode); - - virtual ~GoogleURLTracker(); - - // Returns the current Google homepage URL. - const GURL& google_url() const { return google_url_; } - - // Requests that the tracker perform a server check to update the Google URL - // as necessary. If |force| is false, this will happen at most once per - // network change, not sooner than five seconds after startup (checks - // requested before that time will occur then; checks requested afterwards - // will occur immediately, if no other checks have been made during this run). - // If |force| is true, and the tracker has already performed any requested - // check, it will check again. - void RequestServerCheck(bool force); - - // Notifies the tracker that the user has started a Google search. - // If prompting is necessary, we then listen for the subsequent pending - // navigation to get the appropriate NavigationHelper. When the load - // commits, we'll show the infobar. - void SearchCommitted(); - - // No one but GoogleURLTrackerInfoBarDelegate or test code should call these. - void AcceptGoogleURL(bool redo_searches); - void CancelGoogleURL(); - const GURL& fetched_google_url() const { return fetched_google_url_; } - - // No one but GoogleURLTrackerMapEntry should call this. - void DeleteMapEntryForManager( - const infobars::InfoBarManager* infobar_manager); - - // Called by the client after SearchCommitted() registers listeners, - // to indicate that we've received the "load now pending" notification. - // |nav_helper| is the GoogleURLTrackerNavigationHelper associated with this - // navigation; |infobar_manager| is the InfoBarManager of the associated tab; - // and |pending_id| is the unique ID of the newly pending NavigationEntry. - // If there is already a visible GoogleURLTracker infobar for this tab, this - // function resets its associated pending entry ID to the new ID. Otherwise - // this function creates a map entry for the associated tab. - virtual void OnNavigationPending( - scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper, - infobars::InfoBarManager* infobar_manager, - int pending_id); - - // Called by the navigation observer once a load we're watching commits. - // |infobar_manager| is the same as for OnNavigationPending(); - // |search_url| is guaranteed to be valid. - virtual void OnNavigationCommitted(infobars::InfoBarManager* infobar_manager, - const GURL& search_url); - - // Called by the navigation observer when a tab closes. - virtual void OnTabClosed(GoogleURLTrackerNavigationHelper* nav_helper); - - scoped_ptr<Subscription> RegisterCallback( - const OnGoogleURLUpdatedCallback& cb); - - private: - friend class GoogleURLTrackerTest; - friend class SyncTest; - - typedef std::map<const infobars::InfoBarManager*, GoogleURLTrackerMapEntry*> - EntryMap; - - static const char kSearchDomainCheckURL[]; - - // net::URLFetcherDelegate: - virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; - - // NetworkChangeNotifier::IPAddressObserver: - virtual void OnIPAddressChanged() OVERRIDE; - - // KeyedService: - virtual void Shutdown() OVERRIDE; - - // Registers consumer interest in getting an updated URL from the server. - // Observe chrome::NOTIFICATION_GOOGLE_URL_UPDATED to be notified when the URL - // changes. - void SetNeedToFetch(); - - // Called when the five second startup sleep has finished. Runs any pending - // fetch. - void FinishSleep(); - - // Starts the fetch of the up-to-date Google URL if we actually want to fetch - // it and can currently do so. - void StartFetchIfDesirable(); - - // Closes all map entries. If |redo_searches| is true, this also triggers - // each tab with an infobar to re-perform the user's search, but on the new - // Google TLD. - void CloseAllEntries(bool redo_searches); - - // Unregisters any listeners for the navigation helper in |map_entry|. - // This sanity-DCHECKs that these are registered (or not) in the specific - // cases we expect. (|must_be_listening_for_commit| is used purely for this - // sanity-checking.) This also unregisters the global navigation pending - // listener if there are no remaining listeners for navigation commits, as we - // no longer need them until another search is committed. - void UnregisterForEntrySpecificNotifications( - GoogleURLTrackerMapEntry* map_entry, - bool must_be_listening_for_commit); - - void NotifyGoogleURLUpdated(GURL old_url, GURL new_url); - - CallbackList callback_list_; - - scoped_ptr<GoogleURLTrackerClient> client_; - - GURL google_url_; - GURL fetched_google_url_; - scoped_ptr<net::URLFetcher> fetcher_; - int fetcher_id_; - bool in_startup_sleep_; // True if we're in the five-second "no fetching" - // period that begins at browser start. - bool already_fetched_; // True if we've already fetched a URL once this run; - // we won't fetch again until after a restart. - bool need_to_fetch_; // True if a consumer actually wants us to fetch an - // updated URL. If this is never set, we won't - // bother to fetch anything. - // Consumers should register a callback via - // RegisterCallback(). - bool need_to_prompt_; // True if the last fetched Google URL is not - // matched with current user's default Google URL - // nor the last prompted Google URL. - bool search_committed_; // True when we're expecting a notification of a new - // pending search navigation. - EntryMap entry_map_; - base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; - - DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker); -}; - -#endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_ diff --git a/chrome/browser/google/google_url_tracker_factory.cc b/chrome/browser/google/google_url_tracker_factory.cc index be20187..bc6eb06 100644 --- a/chrome/browser/google/google_url_tracker_factory.cc +++ b/chrome/browser/google/google_url_tracker_factory.cc @@ -6,10 +6,10 @@ #include "base/prefs/pref_service.h" #include "chrome/browser/google/chrome_google_url_tracker_client.h" -#include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/profile.h" #include "components/google/core/browser/google_pref_names.h" +#include "components/google/core/browser/google_url_tracker.h" #include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/pref_registry/pref_registry_syncable.h" diff --git a/chrome/browser/google/google_url_tracker_infobar_delegate.cc b/chrome/browser/google/google_url_tracker_infobar_delegate.cc deleted file mode 100644 index 5fe1eee..0000000 --- a/chrome/browser/google/google_url_tracker_infobar_delegate.cc +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (c) 2012 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_url_tracker_infobar_delegate.h" - -#include "chrome/browser/google/google_url_tracker.h" -#include "chrome/browser/google/google_url_tracker_navigation_helper.h" -#include "chrome/browser/google/google_util.h" -#include "components/infobars/core/infobar.h" -#include "components/infobars/core/infobar_manager.h" -#include "grit/generated_resources.h" -#include "net/base/net_util.h" -#include "ui/base/l10n/l10n_util.h" - - -// static -infobars::InfoBar* GoogleURLTrackerInfoBarDelegate::Create( - infobars::InfoBarManager* infobar_manager, - GoogleURLTracker* google_url_tracker, - const GURL& search_url) { - return infobar_manager->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( - scoped_ptr<ConfirmInfoBarDelegate>(new GoogleURLTrackerInfoBarDelegate( - google_url_tracker, search_url)))); -} - -bool GoogleURLTrackerInfoBarDelegate::Accept() { - google_url_tracker_->AcceptGoogleURL(true); - return false; -} - -bool GoogleURLTrackerInfoBarDelegate::Cancel() { - google_url_tracker_->CancelGoogleURL(); - return false; -} - -void GoogleURLTrackerInfoBarDelegate::Update(const GURL& search_url) { - StoreActiveEntryUniqueID(); - search_url_ = search_url; - pending_id_ = 0; -} - -void GoogleURLTrackerInfoBarDelegate::Close(bool redo_search) { - // Calling OpenURL() will auto-close us asynchronously. It's easier for - // various classes (e.g. GoogleURLTrackerMapEntry) to reason about things if - // the closure always happens synchronously, so we always call RemoveInfoBar() - // directly, then OpenURL() if desirable. (This calling order is safer if - // for some reason in the future OpenURL() were to close us synchronously.) - GURL new_search_url; - if (redo_search) { - // Re-do the user's search on the new domain. - DCHECK(search_url_.is_valid()); - url::Replacements<char> replacements; - const std::string& host(google_url_tracker_->fetched_google_url().host()); - replacements.SetHost(host.data(), url::Component(0, host.length())); - new_search_url = search_url_.ReplaceComponents(replacements); - } - - // Take ownership of |navigation_helper_| in order to ensure that it stays - // alive for the duration of this method. - scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper = - navigation_helper_.Pass(); - infobar()->RemoveSelf(); - // WARNING: |this| may be deleted at this point! Do not access any members! - - if (new_search_url.is_valid()) - navigation_helper->OpenURL(new_search_url, CURRENT_TAB, false); -} - -GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate( - GoogleURLTracker* google_url_tracker, - const GURL& search_url) - : ConfirmInfoBarDelegate(), - google_url_tracker_(google_url_tracker), - navigation_helper_weak_ptr_(NULL), - search_url_(search_url), - pending_id_(0) { -} - -GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() { -} - -base::string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { - return l10n_util::GetStringFUTF16( - IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE, - net::StripWWWFromHost(google_url_tracker_->fetched_google_url()), - net::StripWWWFromHost(google_url_tracker_->google_url())); -} - -base::string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel( - InfoBarButton button) const { - if (button == BUTTON_OK) { - return l10n_util::GetStringFUTF16( - IDS_GOOGLE_URL_TRACKER_INFOBAR_SWITCH, - net::StripWWWFromHost(google_url_tracker_->fetched_google_url())); - } - return l10n_util::GetStringFUTF16( - IDS_GOOGLE_URL_TRACKER_INFOBAR_DONT_SWITCH, - net::StripWWWFromHost(google_url_tracker_->google_url())); -} - -base::string16 GoogleURLTrackerInfoBarDelegate::GetLinkText() const { - return l10n_util::GetStringUTF16(IDS_LEARN_MORE); -} - -bool GoogleURLTrackerInfoBarDelegate::LinkClicked( - WindowOpenDisposition disposition) { - navigation_helper_->OpenURL( - google_util::AppendGoogleLocaleParam(GURL( - "https://www.google.com/support/chrome/bin/answer.py?" - "answer=1618699")), - (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, - true); - return false; -} - -bool GoogleURLTrackerInfoBarDelegate::ShouldExpireInternal( - const NavigationDetails& details) const { - return (details.entry_id != contents_unique_id()) && - (details.entry_id != pending_id_); -} diff --git a/chrome/browser/google/google_url_tracker_infobar_delegate.h b/chrome/browser/google/google_url_tracker_infobar_delegate.h deleted file mode 100644 index 4905e1c..0000000 --- a/chrome/browser/google/google_url_tracker_infobar_delegate.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) 2012 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. - -#ifndef CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_INFOBAR_DELEGATE_H_ -#define CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_INFOBAR_DELEGATE_H_ - -#include "components/infobars/core/confirm_infobar_delegate.h" -#include "url/gurl.h" - -class GoogleURLTracker; -class GoogleURLTrackerNavigationHelper; - -namespace infobars { -class InfoBarManager; -} - -// This infobar is shown by the GoogleURLTracker when the Google base URL has -// changed. -class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate { - public: - // Creates a Google URL tracker infobar and delegate and adds the infobar to - // |infobar_manager|. Returns the infobar if it was successfully added. - static infobars::InfoBar* Create( - infobars::InfoBarManager* infobar_manager, - GoogleURLTracker* google_url_tracker, - const GURL& search_url); - - // ConfirmInfoBarDelegate: - virtual bool Accept() OVERRIDE; - virtual bool Cancel() OVERRIDE; - - GoogleURLTrackerNavigationHelper* navigation_helper() { - return navigation_helper_weak_ptr_; - } - - void set_navigation_helper( - scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper) { - navigation_helper_ = navigation_helper.Pass(); - navigation_helper_weak_ptr_ = navigation_helper_.get(); - } - - // Other than set_pending_id(), these accessors are only used by test code. - const GURL& search_url() const { return search_url_; } - void set_search_url(const GURL& search_url) { search_url_ = search_url; } - int pending_id() const { return pending_id_; } - void set_pending_id(int pending_id) { pending_id_ = pending_id; } - - // These are virtual so test code can override them in a subclass. - virtual void Update(const GURL& search_url); - virtual void Close(bool redo_search); - - protected: - GoogleURLTrackerInfoBarDelegate( - GoogleURLTracker* google_url_tracker, - const GURL& search_url); - virtual ~GoogleURLTrackerInfoBarDelegate(); - - private: - // ConfirmInfoBarDelegate: - virtual base::string16 GetMessageText() const OVERRIDE; - virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; - virtual base::string16 GetLinkText() const OVERRIDE; - virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; - virtual bool ShouldExpireInternal( - const NavigationDetails& details) const OVERRIDE; - - GoogleURLTracker* google_url_tracker_; - scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper_; - - // During Close(), this object gives up ownership of |navigation_helper_|, - // which then outlives this object. Sometimes after this point, other classes - // still attempt to call navigation_helper() to access the (still-valid) - // instance. The NavigationHelper instance is stored as a weak pointer in - // addition to a strong pointer to facilitate this case. - GoogleURLTrackerNavigationHelper* navigation_helper_weak_ptr_; - GURL search_url_; - int pending_id_; - - DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerInfoBarDelegate); -}; - -#endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_INFOBAR_DELEGATE_H_ diff --git a/chrome/browser/google/google_url_tracker_map_entry.cc b/chrome/browser/google/google_url_tracker_map_entry.cc deleted file mode 100644 index f994f29..0000000 --- a/chrome/browser/google/google_url_tracker_map_entry.cc +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2012 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_url_tracker_map_entry.h" - -#include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/google/google_url_tracker.h" -#include "components/infobars/core/infobar.h" - -GoogleURLTrackerMapEntry::GoogleURLTrackerMapEntry( - GoogleURLTracker* google_url_tracker, - infobars::InfoBarManager* infobar_manager, - scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper) - : google_url_tracker_(google_url_tracker), - infobar_manager_(infobar_manager), - infobar_delegate_(NULL), - navigation_helper_(navigation_helper.Pass()), - observing_(false) { - DCHECK(infobar_manager_); -} - -GoogleURLTrackerMapEntry::~GoogleURLTrackerMapEntry() { - if (observing_) - infobar_manager_->RemoveObserver(this); -} - -void GoogleURLTrackerMapEntry::SetInfoBarDelegate( - GoogleURLTrackerInfoBarDelegate* infobar_delegate) { - DCHECK(!infobar_delegate_); - - // Transfer ownership of |navigation_helper_| to the infobar delegate as the - // infobar delegate has need of it after this object has been destroyed in - // the case where the user accepts the new Google URL. - infobar_delegate->set_navigation_helper(navigation_helper_.Pass()); - infobar_delegate_ = infobar_delegate; - infobar_manager_->AddObserver(this); - observing_ = true; -} - -void GoogleURLTrackerMapEntry::Close(bool redo_search) { - if (infobar_delegate_) { - infobar_delegate_->Close(redo_search); - } else { - // WARNING: |infobar_manager_| may point to a deleted object. Do not - // dereference it! See GoogleURLTracker::OnTabClosed(). - google_url_tracker_->DeleteMapEntryForManager(infobar_manager_); - } - // WARNING: At this point |this| has been deleted! -} - -void GoogleURLTrackerMapEntry::OnInfoBarRemoved(infobars::InfoBar* infobar, - bool animate) { - DCHECK(infobar_delegate_); - if (infobar->delegate() == infobar_delegate_) { - google_url_tracker_->DeleteMapEntryForManager(infobar_manager_); - // WARNING: At this point |this| has been deleted! - } -} - -void GoogleURLTrackerMapEntry::OnManagerShuttingDown( - infobars::InfoBarManager* manager) { - DCHECK(observing_); - DCHECK_EQ(infobar_manager_, manager); - manager->RemoveObserver(this); - observing_ = false; -} diff --git a/chrome/browser/google/google_url_tracker_map_entry.h b/chrome/browser/google/google_url_tracker_map_entry.h deleted file mode 100644 index 5cdb2b5..0000000 --- a/chrome/browser/google/google_url_tracker_map_entry.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2012 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. - -#ifndef CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_MAP_ENTRY_H_ -#define CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_MAP_ENTRY_H_ - -#include "base/memory/scoped_ptr.h" -#include "chrome/browser/google/google_url_tracker_infobar_delegate.h" -#include "chrome/browser/google/google_url_tracker_navigation_helper.h" -#include "components/infobars/core/infobar_manager.h" - -class GoogleURLTracker; - -namespace infobars { -class InfoBarManager; -} - -class GoogleURLTrackerMapEntry : public infobars::InfoBarManager::Observer { - public: - GoogleURLTrackerMapEntry( - GoogleURLTracker* google_url_tracker, - infobars::InfoBarManager* infobar_manager, - scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper); - virtual ~GoogleURLTrackerMapEntry(); - - bool has_infobar_delegate() const { return !!infobar_delegate_; } - GoogleURLTrackerInfoBarDelegate* infobar_delegate() { - return infobar_delegate_; - } - void SetInfoBarDelegate(GoogleURLTrackerInfoBarDelegate* infobar_delegate); - - GoogleURLTrackerNavigationHelper* navigation_helper() { - // This object gives ownership of |navigation_helper_| to the infobar - // delegate in SetInfoBarDelegate(). - return has_infobar_delegate() ? - infobar_delegate_->navigation_helper() : navigation_helper_.get(); - } - - const infobars::InfoBarManager* infobar_manager() const { - return infobar_manager_; - } - - void Close(bool redo_search); - - private: - friend class GoogleURLTrackerTest; - - // infobars::InfoBarManager::Observer: - virtual void OnInfoBarRemoved(infobars::InfoBar* infobar, - bool animate) OVERRIDE; - virtual void OnManagerShuttingDown( - infobars::InfoBarManager* manager) OVERRIDE; - - GoogleURLTracker* const google_url_tracker_; - infobars::InfoBarManager* const infobar_manager_; - GoogleURLTrackerInfoBarDelegate* infobar_delegate_; - scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper_; - bool observing_; - - DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerMapEntry); -}; - -#endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_MAP_ENTRY_H_ diff --git a/chrome/browser/google/google_url_tracker_navigation_helper.cc b/chrome/browser/google/google_url_tracker_navigation_helper.cc deleted file mode 100644 index 84a2651..0000000 --- a/chrome/browser/google/google_url_tracker_navigation_helper.cc +++ /dev/null @@ -1,13 +0,0 @@ -// 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_url_tracker_navigation_helper.h" - -GoogleURLTrackerNavigationHelper::GoogleURLTrackerNavigationHelper( - GoogleURLTracker* google_url_tracker) - : google_url_tracker_(google_url_tracker) { -} - -GoogleURLTrackerNavigationHelper::~GoogleURLTrackerNavigationHelper() { -} diff --git a/chrome/browser/google/google_url_tracker_navigation_helper.h b/chrome/browser/google/google_url_tracker_navigation_helper.h deleted file mode 100644 index 98b8b3a..0000000 --- a/chrome/browser/google/google_url_tracker_navigation_helper.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) 2012 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. - -#ifndef CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_NAVIGATION_HELPER_H_ -#define CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_NAVIGATION_HELPER_H_ - -#include "base/macros.h" -#include "ui/base/window_open_disposition.h" - -class GoogleURLTracker; -class GURL; - -// Interface via which GoogleURLTracker communicates with its driver. -// TODO(blundell): Rename this class to GoogleURLTrackerDriver. -// crbug.com/373221 -class GoogleURLTrackerNavigationHelper { - public: - explicit GoogleURLTrackerNavigationHelper( - GoogleURLTracker* google_url_tracker); - virtual ~GoogleURLTrackerNavigationHelper(); - - // Enables or disables listening for navigation commits. - // OnNavigationCommitted will be called for each navigation commit if - // listening is enabled. - virtual void SetListeningForNavigationCommit(bool listen) = 0; - - // Returns whether or not this object is currently listening for navigation - // commits. - virtual bool IsListeningForNavigationCommit() = 0; - - // Enables or disables listening for tab destruction. OnTabClosed will be - // called on tab destruction if listening is enabled. - virtual void SetListeningForTabDestruction(bool listen) = 0; - - // Returns whether or not this object is currently listening for tab - // destruction. - virtual bool IsListeningForTabDestruction() = 0; - - // Opens |url| with the given window disposition. - virtual void OpenURL(GURL url, - WindowOpenDisposition disposition, - bool user_clicked_on_link) = 0; - - protected: - GoogleURLTracker* google_url_tracker() { return google_url_tracker_; } - - private: - GoogleURLTracker* google_url_tracker_; - - DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerNavigationHelper); -}; - -#endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_NAVIGATION_HELPER_H_ diff --git a/chrome/browser/google/google_url_tracker_navigation_helper_impl.cc b/chrome/browser/google/google_url_tracker_navigation_helper_impl.cc index 29bfd58..b61d027 100644 --- a/chrome/browser/google/google_url_tracker_navigation_helper_impl.cc +++ b/chrome/browser/google/google_url_tracker_navigation_helper_impl.cc @@ -5,8 +5,8 @@ #include "chrome/browser/google/google_url_tracker_navigation_helper_impl.h" #include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/infobars/infobar_service.h" +#include "components/google/core/browser/google_url_tracker.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/notification_service.h" diff --git a/chrome/browser/google/google_url_tracker_navigation_helper_impl.h b/chrome/browser/google/google_url_tracker_navigation_helper_impl.h index a86d2d3..f1dba45 100644 --- a/chrome/browser/google/google_url_tracker_navigation_helper_impl.h +++ b/chrome/browser/google/google_url_tracker_navigation_helper_impl.h @@ -5,7 +5,7 @@ #ifndef CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_NAVIGATION_HELPER_IMPL_H_ #define CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_NAVIGATION_HELPER_IMPL_H_ -#include "chrome/browser/google/google_url_tracker_navigation_helper.h" +#include "components/google/core/browser/google_url_tracker_navigation_helper.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "url/gurl.h" diff --git a/chrome/browser/google/google_url_tracker_unittest.cc b/chrome/browser/google/google_url_tracker_unittest.cc index 59ac6c0..f4b5503 100644 --- a/chrome/browser/google/google_url_tracker_unittest.cc +++ b/chrome/browser/google/google_url_tracker_unittest.cc @@ -2,7 +2,7 @@ // 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_url_tracker.h" +#include "components/google/core/browser/google_url_tracker.h" #include <set> #include <string> @@ -11,11 +11,12 @@ #include "base/message_loop/message_loop.h" #include "base/prefs/pref_service.h" #include "chrome/browser/google/google_url_tracker_factory.h" -#include "chrome/browser/google/google_url_tracker_infobar_delegate.h" -#include "chrome/browser/google/google_url_tracker_navigation_helper.h" +#include "chrome/browser/google/google_util.h" #include "chrome/test/base/testing_profile.h" #include "components/google/core/browser/google_pref_names.h" #include "components/google/core/browser/google_url_tracker_client.h" +#include "components/google/core/browser/google_url_tracker_infobar_delegate.h" +#include "components/google/core/browser/google_url_tracker_navigation_helper.h" #include "components/infobars/core/infobar.h" #include "components/infobars/core/infobar_delegate.h" #include "content/public/test/test_browser_thread_bundle.h" @@ -79,6 +80,8 @@ class TestGoogleURLTrackerClient : public GoogleURLTrackerClient { virtual bool IsBackgroundNetworkingEnabled() OVERRIDE; virtual PrefService* GetPrefs() OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; + virtual bool IsGoogleDomainURL(const GURL& url) OVERRIDE; + virtual GURL AppendGoogleLocaleParam(const GURL& url) OVERRIDE; private: Profile* profile_; @@ -115,6 +118,18 @@ net::URLRequestContextGetter* TestGoogleURLTrackerClient::GetRequestContext() { return profile_->GetRequestContext(); } +bool TestGoogleURLTrackerClient::IsGoogleDomainURL(const GURL& url) { + return google_util::IsGoogleDomainUrl( + url, + google_util::DISALLOW_SUBDOMAIN, + google_util::DISALLOW_NON_STANDARD_PORTS); +} + +GURL TestGoogleURLTrackerClient::AppendGoogleLocaleParam(const GURL& url) { + return google_util::AppendGoogleLocaleParam(url); +} + + // TestGoogleURLTrackerNavigationHelper --------------------------------------- class TestGoogleURLTrackerNavigationHelper diff --git a/chrome/browser/google/google_util.cc b/chrome/browser/google/google_util.cc index 9b587dd..dead358 100644 --- a/chrome/browser/google/google_util.cc +++ b/chrome/browser/google/google_util.cc @@ -16,6 +16,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/common/net/url_fixer_upper.h" #include "components/google/core/browser/google_switches.h" +#include "components/google/core/browser/google_url_tracker.h" #include "net/base/registry_controlled_domains/registry_controlled_domain.h" #include "net/base/url_util.h" #include "url/gurl.h" diff --git a/chrome/browser/google/google_util_unittest.cc b/chrome/browser/google/google_util_unittest.cc index 8b8b99b..7ff06bc 100644 --- a/chrome/browser/google/google_util_unittest.cc +++ b/chrome/browser/google/google_util_unittest.cc @@ -3,9 +3,9 @@ // found in the LICENSE file. #include "base/command_line.h" -#include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/google/google_util.h" #include "components/google/core/browser/google_switches.h" +#include "components/google/core/browser/google_url_tracker.h" #include "testing/gtest/include/gtest/gtest.h" using google_util::IsGoogleDomainUrl; |