From a7b8e43d208e137c79db1a33929b37336d9bfc98 Mon Sep 17 00:00:00 2001 From: "samarth@chromium.org" Date: Mon, 18 Mar 2013 18:52:43 +0000 Subject: Move c/b/instant -> c/b/search. BUG=179184 Review URL: https://chromiumcodereview.appspot.com/12496012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188781 0039d316-1c4b-4281-b951-d872f2087c98 --- .../browser/autocomplete/history_quick_provider.cc | 2 +- chrome/browser/autocomplete/search_provider.cc | 2 +- .../autocomplete/search_provider_unittest.cc | 2 +- chrome/browser/chrome_content_browser_client.cc | 6 +- chrome/browser/favicon/DEPS | 2 +- chrome/browser/favicon/favicon_tab_helper.cc | 2 +- chrome/browser/instant/OWNERS | 3 - chrome/browser/instant/instant_io_context.cc | 151 ------ chrome/browser/instant/instant_io_context.h | 100 ---- chrome/browser/instant/instant_service.cc | 249 ---------- chrome/browser/instant/instant_service.h | 104 ---- chrome/browser/instant/instant_service_factory.cc | 37 -- chrome/browser/instant/instant_service_factory.h | 39 -- .../browser/instant/local_omnibox_popup_source.cc | 77 --- .../browser/instant/local_omnibox_popup_source.h | 34 -- chrome/browser/instant/search.cc | 550 --------------------- chrome/browser/instant/search.h | 159 ------ chrome/browser/instant/search_unittest.cc | 317 ------------ chrome/browser/policy/policy_browsertest.cc | 6 +- chrome/browser/prefs/browser_prefs.cc | 2 +- chrome/browser/search/OWNERS | 3 + chrome/browser/search/instant_io_context.cc | 151 ++++++ chrome/browser/search/instant_io_context.h | 100 ++++ chrome/browser/search/instant_service.cc | 249 ++++++++++ chrome/browser/search/instant_service.h | 104 ++++ chrome/browser/search/instant_service_factory.cc | 37 ++ chrome/browser/search/instant_service_factory.h | 39 ++ .../browser/search/local_omnibox_popup_source.cc | 77 +++ chrome/browser/search/local_omnibox_popup_source.h | 34 ++ chrome/browser/search/search.cc | 550 +++++++++++++++++++++ chrome/browser/search/search.h | 159 ++++++ chrome/browser/search/search_unittest.cc | 317 ++++++++++++ chrome/browser/search_engines/search_terms_data.cc | 2 +- chrome/browser/sessions/session_types.cc | 2 +- chrome/browser/sessions/session_types_unittest.cc | 2 +- .../bookmarks/bookmark_context_menu_controller.cc | 2 +- chrome/browser/ui/bookmarks/bookmark_tab_helper.cc | 2 +- chrome/browser/ui/bookmarks/bookmark_unittest.cc | 2 +- chrome/browser/ui/browser.cc | 2 +- chrome/browser/ui/browser_instant_controller.cc | 2 +- .../ui/cocoa/bookmarks/bookmark_bar_controller.mm | 2 +- .../cocoa/bookmarks/bookmark_bar_toolbar_view.mm | 2 +- .../cocoa/browser_window_controller_browsertest.mm | 4 +- .../ui/cocoa/omnibox/omnibox_popup_view_mac.mm | 2 +- .../browser/ui/cocoa/omnibox/omnibox_view_mac.mm | 2 +- .../ui/cocoa/omnibox/omnibox_view_mac_unittest.mm | 2 +- .../wrench_menu/wrench_menu_controller_unittest.mm | 8 +- chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc | 2 +- chrome/browser/ui/omnibox/omnibox_edit_model.cc | 2 +- chrome/browser/ui/search/instant_browsertest.cc | 4 +- chrome/browser/ui/search/instant_controller.cc | 6 +- .../ui/search/instant_extended_browsertest.cc | 6 +- .../search/instant_extended_manual_browsertest.cc | 2 +- chrome/browser/ui/search/instant_overlay.cc | 2 +- .../browser/ui/search/search_delegate_unittest.cc | 2 +- chrome/browser/ui/search/search_model.cc | 2 +- chrome/browser/ui/search/search_tab_helper.cc | 2 +- chrome/browser/ui/toolbar/toolbar_model_impl.cc | 2 +- .../browser/ui/toolbar/toolbar_model_unittest.cc | 6 +- chrome/browser/ui/toolbar/wrench_menu_model.cc | 2 +- .../ui/views/bookmarks/bookmark_bar_view.cc | 2 +- .../views/bookmarks/bookmark_bar_view_unittest.cc | 2 +- .../bookmark_context_menu_controller_views.cc | 2 +- chrome/browser/ui/views/frame/browser_view.cc | 2 +- .../views/omnibox/omnibox_popup_contents_view.cc | 2 +- .../browser/ui/views/omnibox/omnibox_view_views.cc | 2 +- .../browser/ui/views/omnibox/omnibox_view_win.cc | 2 +- chrome/browser/ui/views/reload_button.cc | 2 +- chrome/browser/ui/views/wrench_menu.cc | 2 +- chrome/browser/ui/webui/favicon_source.cc | 6 +- chrome/browser/ui/webui/history_ui.cc | 2 +- chrome/browser/ui/webui/ntp/ntp_resource_cache.cc | 2 +- chrome/browser/ui/webui/ntp/thumbnail_source.cc | 10 +- .../browser/ui/webui/omnibox/omnibox_ui_handler.cc | 2 +- .../ui/webui/options/browser_options_handler.cc | 2 +- chrome/browser/ui/webui/theme_source.cc | 2 +- chrome/chrome_browser.gypi | 24 +- chrome/chrome_tests_unit.gypi | 4 +- 78 files changed, 1907 insertions(+), 1907 deletions(-) delete mode 100644 chrome/browser/instant/OWNERS delete mode 100644 chrome/browser/instant/instant_io_context.cc delete mode 100644 chrome/browser/instant/instant_io_context.h delete mode 100644 chrome/browser/instant/instant_service.cc delete mode 100644 chrome/browser/instant/instant_service.h delete mode 100644 chrome/browser/instant/instant_service_factory.cc delete mode 100644 chrome/browser/instant/instant_service_factory.h delete mode 100644 chrome/browser/instant/local_omnibox_popup_source.cc delete mode 100644 chrome/browser/instant/local_omnibox_popup_source.h delete mode 100644 chrome/browser/instant/search.cc delete mode 100644 chrome/browser/instant/search.h delete mode 100644 chrome/browser/instant/search_unittest.cc create mode 100644 chrome/browser/search/OWNERS create mode 100644 chrome/browser/search/instant_io_context.cc create mode 100644 chrome/browser/search/instant_io_context.h create mode 100644 chrome/browser/search/instant_service.cc create mode 100644 chrome/browser/search/instant_service.h create mode 100644 chrome/browser/search/instant_service_factory.cc create mode 100644 chrome/browser/search/instant_service_factory.h create mode 100644 chrome/browser/search/local_omnibox_popup_source.cc create mode 100644 chrome/browser/search/local_omnibox_popup_source.h create mode 100644 chrome/browser/search/search.cc create mode 100644 chrome/browser/search/search.h create mode 100644 chrome/browser/search/search_unittest.cc (limited to 'chrome') diff --git a/chrome/browser/autocomplete/history_quick_provider.cc b/chrome/browser/autocomplete/history_quick_provider.cc index 0011fd4..20db550 100644 --- a/chrome/browser/autocomplete/history_quick_provider.cc +++ b/chrome/browser/autocomplete/history_quick_provider.cc @@ -25,10 +25,10 @@ #include "chrome/browser/history/in_memory_url_index.h" #include "chrome/browser/history/in_memory_url_index_types.h" #include "chrome/browser/history/scored_history_match.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/omnibox/omnibox_field_trial.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc index d6a4880..d5a5945 100644 --- a/chrome/browser/autocomplete/search_provider.cc +++ b/chrome/browser/autocomplete/search_provider.cc @@ -29,11 +29,11 @@ #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/in_memory_database.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/metrics/variations/variations_http_header_provider.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/omnibox/omnibox_field_trial.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/search_engines/search_engine_type.h" #include "chrome/browser/search_engines/template_url_prepopulate_data.h" #include "chrome/browser/search_engines/template_url_service.h" diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc index 909e43bf6..88db2fe 100644 --- a/chrome/browser/autocomplete/search_provider_unittest.cc +++ b/chrome/browser/autocomplete/search_provider_unittest.cc @@ -20,8 +20,8 @@ #include "chrome/browser/autocomplete/history_url_provider.h" #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/omnibox/omnibox_field_trial.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index f3a3a3e..0b5e807 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -41,9 +41,6 @@ #include "chrome/browser/extensions/suggest_permission_util.h" #include "chrome/browser/geolocation/chrome_access_token_store.h" #include "chrome/browser/google/google_util.h" -#include "chrome/browser/instant/instant_service.h" -#include "chrome/browser/instant/instant_service_factory.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/media/media_capture_devices_dispatcher.h" #include "chrome/browser/nacl_host/nacl_process_host.h" #include "chrome/browser/net/chrome_net_log.h" @@ -63,6 +60,9 @@ #include "chrome/browser/renderer_host/chrome_render_message_filter.h" #include "chrome/browser/renderer_host/chrome_render_view_host_observer.h" #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h" +#include "chrome/browser/search/instant_service.h" +#include "chrome/browser/search/instant_service_factory.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h" #include "chrome/browser/signin/signin_manager.h" #include "chrome/browser/signin/signin_manager_factory.h" diff --git a/chrome/browser/favicon/DEPS b/chrome/browser/favicon/DEPS index a5fd7b5..1c9912b 100644 --- a/chrome/browser/favicon/DEPS +++ b/chrome/browser/favicon/DEPS @@ -9,7 +9,7 @@ # Permanently-allowed DEPS beyond the standard Browser # Components-like DEPS above go here. - "+chrome/browser/instant/search.h", + "+chrome/browser/search/search.h", "+third_party/skia/include/core/SkBitmap.h", # TODO(caitkp): Bring this list to zero. diff --git a/chrome/browser/favicon/favicon_tab_helper.cc b/chrome/browser/favicon/favicon_tab_helper.cc index 6a9a00c..9163926 100644 --- a/chrome/browser/favicon/favicon_tab_helper.cc +++ b/chrome/browser/favicon/favicon_tab_helper.cc @@ -9,8 +9,8 @@ #include "chrome/browser/favicon/favicon_util.h" #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_notification_types.h" #include "content/public/browser/favicon_status.h" diff --git a/chrome/browser/instant/OWNERS b/chrome/browser/instant/OWNERS deleted file mode 100644 index 8514380..0000000 --- a/chrome/browser/instant/OWNERS +++ /dev/null @@ -1,3 +0,0 @@ -dhollowa@chromium.org -sky@chromium.org -sreeram@chromium.org diff --git a/chrome/browser/instant/instant_io_context.cc b/chrome/browser/instant/instant_io_context.cc deleted file mode 100644 index e2199d6..0000000 --- a/chrome/browser/instant/instant_io_context.cc +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright 2013 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/instant/instant_io_context.h" - -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/resource_context.h" -#include "content/public/browser/resource_request_info.h" -#include "googleurl/src/gurl.h" -#include "net/url_request/url_request.h" - -using content::BrowserThread; - -namespace { - -// Retrieves the Instant data from the |context|'s named user-data. -InstantIOContext* GetDataForResourceContext( - content::ResourceContext* context) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - return base::UserDataAdapter::Get( - context, InstantIOContext::kInstantIOContextKeyName); -} - -InstantIOContext* GetDataForRequest(const net::URLRequest* request) { - const content::ResourceRequestInfo* info = - content::ResourceRequestInfo::ForRequest(request); - if (!info) - return NULL; - - return GetDataForResourceContext(info->GetContext()); -} - -} // namespace - -const char InstantIOContext::kInstantIOContextKeyName[] = "instant_io_context"; - -InstantIOContext::InstantIOContext() { - // The InstantIOContext is created on the UI thread but is accessed - // on the IO thread. - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); -} - -InstantIOContext::~InstantIOContext() { -} - -// static -void InstantIOContext::SetUserDataOnIO( - content::ResourceContext* resource_context, - scoped_refptr instant_io_context) { - resource_context->SetUserData( - InstantIOContext::kInstantIOContextKeyName, - new base::UserDataAdapter(instant_io_context)); -} - -// static -void InstantIOContext::AddInstantProcessOnIO( - scoped_refptr instant_io_context, int process_id) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - instant_io_context->process_ids_.insert(process_id); -} - -// static -void InstantIOContext::RemoveInstantProcessOnIO( - scoped_refptr instant_io_context, int process_id) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - instant_io_context->process_ids_.erase(process_id); -} - -// static -void InstantIOContext::ClearInstantProcessesOnIO( - scoped_refptr instant_io_context) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - instant_io_context->process_ids_.clear(); -} - -// static -void InstantIOContext::AddMostVisitedItemIDOnIO( - scoped_refptr instant_io_context, - uint64 most_visited_item_id, const GURL& url) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - instant_io_context->most_visited_item_id_to_url_map_[most_visited_item_id] = - url; -} - -// static -void InstantIOContext::DeleteMostVisitedURLsOnIO( - scoped_refptr instant_io_context, - std::vector deleted_ids, bool all_history) { - if (all_history) { - instant_io_context->most_visited_item_id_to_url_map_.clear(); - return; - } - - for (size_t i = 0; i < deleted_ids.size(); ++i) { - instant_io_context->most_visited_item_id_to_url_map_.erase( - instant_io_context->most_visited_item_id_to_url_map_.find( - deleted_ids[i])); - } -} - -// static -bool InstantIOContext::ShouldServiceRequest(const net::URLRequest* request) { - const content::ResourceRequestInfo* info = - content::ResourceRequestInfo::ForRequest(request); - if (!info) - return false; - - InstantIOContext* instant_io_context = GetDataForRequest(request); - if (!instant_io_context) - return false; - - int process_id = -1; - int render_view_id = -1; - if (info->GetAssociatedRenderView(&process_id, &render_view_id) && - instant_io_context->IsInstantProcess(process_id)) - return true; - return false; -} - -// static -bool InstantIOContext::GetURLForMostVisitedItemId( - const net::URLRequest* request, - uint64 most_visited_item_id, - GURL* url) { - InstantIOContext* instant_io_context = GetDataForRequest(request); - if (!instant_io_context) { - *url = GURL(); - return false; - } - - return instant_io_context->GetURLForMostVisitedItemId(most_visited_item_id, - url); -} - -bool InstantIOContext::IsInstantProcess(int process_id) const { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - return process_ids_.count(process_id) != 0; -} - -bool InstantIOContext::GetURLForMostVisitedItemId(uint64 most_visited_item_id, - GURL* url) { - std::map::iterator it = - most_visited_item_id_to_url_map_.find(most_visited_item_id); - if (it != most_visited_item_id_to_url_map_.end()) { - *url = it->second; - return true; - } - *url = GURL(); - return false; -} diff --git a/chrome/browser/instant/instant_io_context.h b/chrome/browser/instant/instant_io_context.h deleted file mode 100644 index 99b805c..0000000 --- a/chrome/browser/instant/instant_io_context.h +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2013 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_INSTANT_INSTANT_IO_CONTEXT_ -#define CHROME_BROWSER_INSTANT_INSTANT_IO_CONTEXT_ - -#include -#include -#include - -#include "base/basictypes.h" -#include "base/memory/ref_counted.h" - -class GURL; - -namespace content { -class ResourceContext; -} - -namespace net { -class URLRequest; -} - -// IO thread data held for Instant. This reflects the data held in -// InstantService for use on the IO thread. Owned by ResourceContext -// as user data. -class InstantIOContext : public base::RefCountedThreadSafe { - public: - InstantIOContext(); - - // Key name for context UserData. UserData is created by InstantService - // but accessed by InstantIOContext. - static const char kInstantIOContextKeyName[]; - - // Installs the |instant_io_context| into the UserData of the - // |resource_context|. - static void SetUserDataOnIO( - content::ResourceContext* resource_context, - scoped_refptr instant_io_context); - - // Add and remove RenderProcessHost IDs that are associated with Instant - // processes. Used to keep process IDs in sync with InstantService. - static void AddInstantProcessOnIO( - scoped_refptr instant_io_context, - int process_id); - static void RemoveInstantProcessOnIO( - scoped_refptr instant_io_context, - int process_id); - static void ClearInstantProcessesOnIO( - scoped_refptr instant_io_context); - - // Associates the |most_visited_item_id| with the |url|. - static void AddMostVisitedItemIDOnIO( - scoped_refptr instant_io_context, - uint64 most_visited_item_id, const GURL& url); - - // Deletes the Most Visited item IDs contained in |deleted_ids| from the url - // mapping. If |all_history| is true, then ignores |deleted_ids| and - // deletes all mappings. - static void DeleteMostVisitedURLsOnIO( - scoped_refptr instant_io_context, - std::vector deleted_ids, bool all_history); - - // Determine if this chrome-search: request is coming from an Instant render - // process. - static bool ShouldServiceRequest(const net::URLRequest* request); - - // Returns true if the |most_visited_item_id| is known, and |url| is set. - // Returns false otherwise. - static bool GetURLForMostVisitedItemId( - const net::URLRequest* request, - uint64 most_visited_item_id, GURL* url); - - protected: - virtual ~InstantIOContext(); - - private: - friend class base::RefCountedThreadSafe; - - // Check that |process_id| is in the known set of Instant processes, ie. - // |process_ids_|. - bool IsInstantProcess(int process_id) const; - - bool GetURLForMostVisitedItemId(uint64 most_visited_item_id, GURL* url); - - // The process IDs associated with Instant processes. Mirror of the process - // IDs in InstantService. Duplicated here for synchronous access on the IO - // thread. - std::set process_ids_; - - // The Most Visited item IDs map associated with Instant processes. Mirror of - // the Most Visited item ID map in InstantService. Duplicated here for - // synchronous access on the IO thread. - std::map most_visited_item_id_to_url_map_; - - DISALLOW_COPY_AND_ASSIGN(InstantIOContext); -}; - -#endif // CHROME_BROWSER_INSTANT_INSTANT_IO_CONTEXT_ diff --git a/chrome/browser/instant/instant_service.cc b/chrome/browser/instant/instant_service.cc deleted file mode 100644 index e94639e..0000000 --- a/chrome/browser/instant/instant_service.cc +++ /dev/null @@ -1,249 +0,0 @@ -// Copyright 2013 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/instant/instant_service.h" - -#include "base/strings/string_number_conversions.h" -#include "chrome/browser/history/history_notifications.h" -#include "chrome/browser/instant/instant_io_context.h" -#include "chrome/browser/instant/instant_service_factory.h" -#include "chrome/browser/instant/local_omnibox_popup_source.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/webui/favicon_source.h" -#include "chrome/browser/ui/webui/ntp/thumbnail_source.h" -#include "chrome/browser/ui/webui/theme_source.h" -#include "chrome/common/chrome_notification_types.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/notification_service.h" -#include "content/public/browser/notification_types.h" -#include "content/public/browser/render_process_host.h" -#include "content/public/browser/url_data_source.h" -#include "googleurl/src/gurl.h" -#include "net/url_request/url_request.h" - -using content::BrowserThread; - -namespace { - -// Copies deleted urls out of the history data structure |details| into a -// straight vector of GURLs. -void HistoryDetailsToDeletedURLs(const history::URLsDeletedDetails& details, - std::vector* deleted_urls) { - for (history::URLRows::const_iterator it = details.rows.begin(); - it != details.rows.end(); - ++it) { - deleted_urls->push_back(it->url()); - } -} - -} // namespace - -InstantService::InstantService(Profile* profile) - : profile_(profile), - last_most_visited_item_id_(0) { - // Stub for unit tests. - if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) - return; - - registrar_.Add(this, - content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, - content::NotificationService::AllSources()); - registrar_.Add(this, - chrome::NOTIFICATION_HISTORY_URLS_DELETED, - content::NotificationService::AllSources()); - - instant_io_context_ = new InstantIOContext(); - - if (profile_ && profile_->GetResourceContext()) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&InstantIOContext::SetUserDataOnIO, - profile->GetResourceContext(), instant_io_context_)); - } - - // Set up the data sources that Instant uses on the NTP. -#if defined(ENABLE_THEMES) - content::URLDataSource::Add(profile, new ThemeSource(profile)); -#endif - content::URLDataSource::Add(profile, new ThumbnailSource(profile)); - content::URLDataSource::Add(profile, new FaviconSource( - profile, FaviconSource::FAVICON)); - content::URLDataSource::Add(profile, new LocalOmniboxPopupSource()); -} - -InstantService::~InstantService() { -} - -// static -const std::string InstantService::MaybeTranslateInstantPathOnUI( - Profile* profile, const std::string& path) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - InstantService* instant_service = - InstantServiceFactory::GetForProfile(profile); - if (!instant_service) - return path; - - uint64 most_visited_item_id = 0; - if (base::StringToUint64(path, &most_visited_item_id)) { - GURL url; - if (instant_service->GetURLForMostVisitedItemId(most_visited_item_id, &url)) - return url.spec(); - } - return path; -} - -const std::string InstantService::MaybeTranslateInstantPathOnIO( - const net::URLRequest* request, const std::string& path) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - uint64 most_visited_item_id = 0; - if (base::StringToUint64(path, &most_visited_item_id)) { - GURL url; - if (InstantIOContext::GetURLForMostVisitedItemId(request, - most_visited_item_id, - &url)) - return url.spec(); - } - return path; -} - -// static -bool InstantService::IsInstantPath(const GURL& url) { - // Strip leading slash. - std::string path = url.path().substr(1); - - // Check that path is of Most Visited item ID form. - uint64 dummy = 0; - return base::StringToUint64(path, &dummy); -} - -void InstantService::AddInstantProcess(int process_id) { - process_ids_.insert(process_id); - - if (instant_io_context_) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&InstantIOContext::AddInstantProcessOnIO, - instant_io_context_, process_id)); - } -} - -bool InstantService::IsInstantProcess(int process_id) const { - return process_ids_.find(process_id) != process_ids_.end(); -} - -uint64 InstantService::AddURL(const GURL& url) { - uint64 id = 0; - if (GetMostVisitedItemIDForURL(url, &id)) - return id; - - last_most_visited_item_id_++; - most_visited_item_id_to_url_map_[last_most_visited_item_id_] = url; - url_to_most_visited_item_id_map_[url] = last_most_visited_item_id_; - - if (instant_io_context_) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&InstantIOContext::AddMostVisitedItemIDOnIO, - instant_io_context_, last_most_visited_item_id_, url)); - } - - return last_most_visited_item_id_; -} - -bool InstantService::GetMostVisitedItemIDForURL( - const GURL& url, - uint64 *most_visited_item_id) { - std::map::iterator it = - url_to_most_visited_item_id_map_.find(url); - if (it != url_to_most_visited_item_id_map_.end()) { - *most_visited_item_id = it->second; - return true; - } - *most_visited_item_id = 0; - return false; -} - -bool InstantService::GetURLForMostVisitedItemId(uint64 most_visited_item_id, - GURL* url) { - std::map::iterator it = - most_visited_item_id_to_url_map_.find(most_visited_item_id); - if (it != most_visited_item_id_to_url_map_.end()) { - *url = it->second; - return true; - } - *url = GURL(); - return false; -} - -void InstantService::Shutdown() { - process_ids_.clear(); - - if (instant_io_context_) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&InstantIOContext::ClearInstantProcessesOnIO, - instant_io_context_)); - } - instant_io_context_ = NULL; -} - -void InstantService::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - switch (type) { - case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { - int process_id = - content::Source(source)->GetID(); - process_ids_.erase(process_id); - - if (instant_io_context_) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&InstantIOContext::RemoveInstantProcessOnIO, - instant_io_context_, process_id)); - } - break; - } - case chrome::NOTIFICATION_HISTORY_URLS_DELETED: { - content::Details det(details); - std::vector deleted_urls; - HistoryDetailsToDeletedURLs(*det.ptr(), &deleted_urls); - - std::vector deleted_ids; - if (det->all_history) { - url_to_most_visited_item_id_map_.clear(); - most_visited_item_id_to_url_map_.clear(); - } else { - DeleteHistoryURLs(deleted_urls, &deleted_ids); - } - - if (instant_io_context_) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&InstantIOContext::DeleteMostVisitedURLsOnIO, - instant_io_context_, deleted_ids, det->all_history)); - } - break; - } - default: - NOTREACHED() << "Unexpected notification type in InstantService."; - } -} - -void InstantService::DeleteHistoryURLs(const std::vector& deleted_urls, - std::vector* deleted_ids) { - for (std::vector::const_iterator it = deleted_urls.begin(); - it != deleted_urls.end(); - ++it) { - std::map::iterator item = - url_to_most_visited_item_id_map_.find(*it); - if (item != url_to_most_visited_item_id_map_.end()) { - uint64 most_visited_item_id = item->second; - url_to_most_visited_item_id_map_.erase(item); - most_visited_item_id_to_url_map_.erase( - most_visited_item_id_to_url_map_.find(most_visited_item_id)); - deleted_ids->push_back(most_visited_item_id); - } - } -} diff --git a/chrome/browser/instant/instant_service.h b/chrome/browser/instant/instant_service.h deleted file mode 100644 index bdb8a35..0000000 --- a/chrome/browser/instant/instant_service.h +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2013 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_INSTANT_INSTANT_SERVICE_H_ -#define CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ - -#include -#include -#include - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/ref_counted.h" -#include "chrome/browser/profiles/profile_keyed_service.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" - -class GURL; -class InstantIOContext; -class Profile; - -namespace net { -class URLRequest; -} - -// Tracks render process host IDs that are associated with Instant. -class InstantService : public ProfileKeyedService, - public content::NotificationObserver { - public: - explicit InstantService(Profile* profile); - virtual ~InstantService(); - - // A utility to translate an Instant path if it is of Most Visited item ID - // form. If path is a Most Visited item ID and we have a URL for it, then - // this URL is returned in string form. The |path| is a URL fragment - // corresponding to the path of url with the leading slash ("/") stripped. - // For example, chrome-search://favicon/72 would yield a |path| value of "72", - // and since 72 is a valid uint64 the path is translated to a valid url, - // "http://bingo.com/", say. - static const std::string MaybeTranslateInstantPathOnUI( - Profile* profile, const std::string& path); - static const std::string MaybeTranslateInstantPathOnIO( - const net::URLRequest* request, const std::string& path); - static bool IsInstantPath(const GURL& url); - - // Add, remove, and query RenderProcessHost IDs that are associated with - // Instant processes. - void AddInstantProcess(int process_id); - bool IsInstantProcess(int process_id) const; - -#if defined(UNIT_TEST) - int GetInstantProcessCount() const { - return process_ids_.size(); - } -#endif - - // If |url| is known the existing Most Visited item ID is returned. Otherwise - // a new Most Visited item ID is associated with the |url| and returned. - uint64 AddURL(const GURL& url); - - // If there is a mapping for the |url|, sets |most_visited_item_id| and - // returns true. - bool GetMostVisitedItemIDForURL(const GURL& url, - uint64* most_visited_item_id); - - // If there is a mapping for the |most_visited_item_id|, sets |url| and - // returns true. - bool GetURLForMostVisitedItemId(uint64 most_visited_item_id, GURL* url); - - private: - // Overridden from ProfileKeyedService: - virtual void Shutdown() OVERRIDE; - - // Overridden from content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - - // Removes entries of each url in |deleted_urls| from the ID maps. Or all - // IDs if |all_history| is true. |deleted_ids| is filled with the newly - // deleted Most Visited item IDs. - void DeleteHistoryURLs(const std::vector& deleted_urls, - std::vector* deleted_ids); - - Profile* const profile_; - - // The process ids associated with Instant processes. - std::set process_ids_; - - // A mapping of Most Visited IDs to URLs. Used to hide Most Visited and - // Favicon URLs from the Instant search provider. - uint64 last_most_visited_item_id_; - std::map most_visited_item_id_to_url_map_; - std::map url_to_most_visited_item_id_map_; - - content::NotificationRegistrar registrar_; - - scoped_refptr instant_io_context_; - - DISALLOW_COPY_AND_ASSIGN(InstantService); -}; - -#endif // CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_ diff --git a/chrome/browser/instant/instant_service_factory.cc b/chrome/browser/instant/instant_service_factory.cc deleted file mode 100644 index 585e0c2..0000000 --- a/chrome/browser/instant/instant_service_factory.cc +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2013 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/instant/instant_service_factory.h" - -#include "chrome/browser/instant/instant_service.h" -#include "chrome/browser/profiles/profile_dependency_manager.h" - -// static -InstantService* InstantServiceFactory::GetForProfile(Profile* profile) { - return static_cast( - GetInstance()->GetServiceForProfile(profile, true)); -} - -// static -InstantServiceFactory* InstantServiceFactory::GetInstance() { - return Singleton::get(); -} - -InstantServiceFactory::InstantServiceFactory() - : ProfileKeyedServiceFactory("InstantService", - ProfileDependencyManager::GetInstance()) { - // No dependencies. -} - -InstantServiceFactory::~InstantServiceFactory() { -} - -bool InstantServiceFactory::ServiceHasOwnInstanceInIncognito() const { - return true; -} - -ProfileKeyedService* InstantServiceFactory::BuildServiceInstanceFor( - Profile* profile) const { - return new InstantService(profile); -} diff --git a/chrome/browser/instant/instant_service_factory.h b/chrome/browser/instant/instant_service_factory.h deleted file mode 100644 index 80e26ab..0000000 --- a/chrome/browser/instant/instant_service_factory.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2013 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_INSTANT_INSTANT_SERVICE_FACTORY_H_ -#define CHROME_BROWSER_INSTANT_INSTANT_SERVICE_FACTORY_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/singleton.h" -#include "chrome/browser/profiles/profile_keyed_service_factory.h" - -class InstantService; -class Profile; -class ProfileKeyedService; - -// Singleton that owns all InstantServices and associates them with Profiles. -class InstantServiceFactory : public ProfileKeyedServiceFactory { - public: - // Returns the InstantService for |profile|. - static InstantService* GetForProfile(Profile* profile); - - static InstantServiceFactory* GetInstance(); - - private: - friend struct DefaultSingletonTraits; - - InstantServiceFactory(); - virtual ~InstantServiceFactory(); - - // Overridden from ProfileKeyedServiceFactory: - virtual bool ServiceHasOwnInstanceInIncognito() const OVERRIDE; - virtual ProfileKeyedService* BuildServiceInstanceFor( - Profile* profile) const OVERRIDE; - - DISALLOW_COPY_AND_ASSIGN(InstantServiceFactory); -}; - -#endif // CHROME_BROWSER_INSTANT_INSTANT_SERVICE_FACTORY_H_ diff --git a/chrome/browser/instant/local_omnibox_popup_source.cc b/chrome/browser/instant/local_omnibox_popup_source.cc deleted file mode 100644 index 1b64fe9..0000000 --- a/chrome/browser/instant/local_omnibox_popup_source.cc +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2013 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/instant/local_omnibox_popup_source.h" - -#include "base/logging.h" -#include "base/memory/ref_counted_memory.h" -#include "base/string_util.h" -#include "chrome/common/url_constants.h" -#include "content/public/common/content_client.h" -#include "googleurl/src/gurl.h" -#include "grit/browser_resources.h" -#include "net/url_request/url_request.h" - -namespace { - -const char kHTMLFilename[] = "local-omnibox-popup.html"; -const char kJsFilename[] = "local-omnibox-popup.js"; -const char kCSSFilename[] = "local-omnibox-popup.css"; - -} // namespace - -LocalOmniboxPopupSource::LocalOmniboxPopupSource() { -} - -LocalOmniboxPopupSource::~LocalOmniboxPopupSource() { -} - -std::string LocalOmniboxPopupSource::GetSource() { - return chrome::kChromeSearchLocalOmniboxPopupHost; -} - -void LocalOmniboxPopupSource::StartDataRequest( - const std::string& path, - bool is_incognito, - const content::URLDataSource::GotDataCallback& callback) { - int identifier = -1; - if (path == kHTMLFilename) { - identifier = IDR_LOCAL_OMNIBOX_POPUP_HTML; - } else if (path == kJsFilename) { - identifier = IDR_LOCAL_OMNIBOX_POPUP_JS; - } else if (path == kCSSFilename) { - identifier = IDR_LOCAL_OMNIBOX_POPUP_CSS; - } else { - callback.Run(NULL); - return; - } - - scoped_refptr response( - content::GetContentClient()->GetDataResourceBytes(identifier)); - callback.Run(response); -} - -std::string LocalOmniboxPopupSource::GetMimeType( - const std::string& path) const { - if (path == kHTMLFilename) - return "text/html"; - if (path == kJsFilename) - return "application/javascript"; - if (path == kCSSFilename) - return "text/css"; - return ""; -} - -bool LocalOmniboxPopupSource::ShouldServiceRequest( - const net::URLRequest* request) const { - DCHECK(request->url().host() == chrome::kChromeSearchLocalOmniboxPopupHost); - - if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { - DCHECK(StartsWithASCII(request->url().path(), "/", true)); - std::string filename = request->url().path().substr(1); - return filename == kHTMLFilename || filename == kJsFilename || - filename == kCSSFilename; - } - return false; -} diff --git a/chrome/browser/instant/local_omnibox_popup_source.h b/chrome/browser/instant/local_omnibox_popup_source.h deleted file mode 100644 index fb40fcd..0000000 --- a/chrome/browser/instant/local_omnibox_popup_source.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2013 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_INSTANT_LOCAL_OMNIBOX_POPUP_SOURCE_H_ -#define CHROME_BROWSER_INSTANT_LOCAL_OMNIBOX_POPUP_SOURCE_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "content/public/browser/url_data_source.h" - -// Serves HTML and resources for the local omnibox popup i.e. -// chrome-search://local-omnibox-popup/local_omnibox_popup.html -class LocalOmniboxPopupSource : public content::URLDataSource { - public: - LocalOmniboxPopupSource(); - - // content::URLDataSource overrides. - virtual std::string GetSource() OVERRIDE; - virtual void StartDataRequest( - const std::string& path, - bool is_incognito, - const content::URLDataSource::GotDataCallback& callback) OVERRIDE; - virtual std::string GetMimeType(const std::string& path) const OVERRIDE; - virtual bool ShouldServiceRequest( - const net::URLRequest* request) const OVERRIDE; - - private: - virtual ~LocalOmniboxPopupSource(); - - DISALLOW_COPY_AND_ASSIGN(LocalOmniboxPopupSource); -}; - -#endif // CHROME_BROWSER_INSTANT_LOCAL_OMNIBOX_POPUP_SOURCE_H_ diff --git a/chrome/browser/instant/search.cc b/chrome/browser/instant/search.cc deleted file mode 100644 index 25adc19..0000000 --- a/chrome/browser/instant/search.cc +++ /dev/null @@ -1,550 +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/instant/search.h" - -#include "base/command_line.h" -#include "base/metrics/field_trial.h" -#include "base/metrics/histogram.h" -#include "base/prefs/pref_service.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/string_split.h" -#include "chrome/browser/instant/instant_service.h" -#include "chrome/browser/instant/instant_service_factory.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/search_engines/template_url_service.h" -#include "chrome/browser/search_engines/template_url_service_factory.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/url_constants.h" -#include "components/user_prefs/pref_registry_syncable.h" -#include "content/public/browser/navigation_entry.h" -#include "content/public/browser/render_process_host.h" -#include "content/public/browser/web_contents.h" - -namespace chrome { -namespace search { - -namespace { - -// The default value we should assign to the instant_extended.enabled pref. As -// with other prefs, the default is used only when the user hasn't toggled the -// pref explicitly. -enum InstantExtendedDefault { - INSTANT_DEFAULT_ON, // Default the pref to be enabled. - INSTANT_USE_EXISTING, // Use the current value of the instant.enabled pref. - INSTANT_DEFAULT_OFF, // Default the pref to be disabled. -}; - -// Configuration options for Embedded Search. -// InstantExtended field trials are named in such a way that we can parse out -// the experiment configuration from the trial's group name in order to give -// us maximum flexability in running experiments. -// Field trial groups should be named things like "Group7 espv:2 instant:1". -// The first token is always GroupN for some integer N, followed by a -// space-delimited list of key:value pairs which correspond to these flags: -const char kEmbeddedPageVersionFlagName[] = "espv"; -const uint64 kEmbeddedPageVersionDisabled = 0; -#if defined(OS_IOS) || defined(OS_ANDROID) -const uint64 kEmbeddedPageVersionDefault = 1; -#else -const uint64 kEmbeddedPageVersionDefault = 2; -#endif - -const char kInstantExtendedActivationName[] = "instant"; -const InstantExtendedDefault kInstantExtendedActivationDefault = - INSTANT_DEFAULT_ON; - -// Constants for the field trial name and group prefix. -const char kInstantExtendedFieldTrialName[] = "InstantExtended"; -const char kGroupNumberPrefix[] = "Group"; - -// If the field trial's group name ends with this string its configuration will -// be ignored and Instant Extended will not be enabled by default. -const char kDisablingSuffix[] = "DISABLED"; - -TemplateURL* GetDefaultSearchProviderTemplateURL(Profile* profile) { - TemplateURLService* template_url_service = - TemplateURLServiceFactory::GetForProfile(profile); - if (template_url_service) - return template_url_service->GetDefaultSearchProvider(); - return NULL; -} - -GURL TemplateURLRefToGURL(const TemplateURLRef& ref, int start_margin) { - TemplateURLRef::SearchTermsArgs search_terms_args = - TemplateURLRef::SearchTermsArgs(string16()); - search_terms_args.omnibox_start_margin = start_margin; - return GURL(ref.ReplaceSearchTerms(search_terms_args)); -} - -bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url) { - return my_url.host() == other_url.host() && - my_url.port() == other_url.port() && - my_url.path() == other_url.path() && - (my_url.scheme() == other_url.scheme() || - (my_url.SchemeIs(chrome::kHttpsScheme) && - other_url.SchemeIs(chrome::kHttpScheme))); -} - -bool IsCommandLineInstantURL(const GURL& url) { - const CommandLine* cl = CommandLine::ForCurrentProcess(); - const GURL instant_url(cl->GetSwitchValueASCII(switches::kInstantURL)); - return instant_url.is_valid() && MatchesOriginAndPath(url, instant_url); -} - -bool MatchesAnySearchURL(const GURL& url, TemplateURL* template_url) { - GURL search_url = - TemplateURLRefToGURL(template_url->url_ref(), kDisableStartMargin); - if (search_url.is_valid() && MatchesOriginAndPath(url, search_url)) - return true; - - // "URLCount() - 1" because we already tested url_ref above. - for (size_t i = 0; i < template_url->URLCount() - 1; ++i) { - TemplateURLRef ref(template_url, i); - search_url = TemplateURLRefToGURL(ref, kDisableStartMargin); - if (search_url.is_valid() && MatchesOriginAndPath(url, search_url)) - return true; - } - - return false; -} - -enum OptInState { - NOT_SET, // The user has not manually opted into or out of InstantExtended. - OPT_IN, // The user has opted-in to InstantExtended. - OPT_OUT, // The user has opted-out of InstantExtended. - OPT_IN_STATE_ENUM_COUNT, -}; - -void RecordInstantExtendedOptInState(OptInState state) { - static bool recorded = false; - if (!recorded) { - recorded = true; - UMA_HISTOGRAM_ENUMERATION("InstantExtended.OptInState", state, - OPT_IN_STATE_ENUM_COUNT); - } -} - -// Returns true if |contents| is rendered inside the Instant process for -// |profile|. -bool IsRenderedInInstantProcess(const content::WebContents* contents, - Profile* profile) { - const content::RenderProcessHost* process_host = - contents->GetRenderProcessHost(); - if (!process_host) - return false; - - const InstantService* instant_service = - InstantServiceFactory::GetForProfile(profile); - if (!instant_service) - return false; - - return instant_service->IsInstantProcess(process_host->GetID()); -} - -// Returns true if |url| can be used as an Instant URL for |profile|. -bool IsInstantURL(const GURL& url, Profile* profile) { - TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); - if (!template_url) - return false; - - const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); - const bool extended_api_enabled = IsInstantExtendedAPIEnabled(); - GURL effective_url = url; - - if (IsCommandLineInstantURL(url)) - effective_url = CoerceCommandLineURLToTemplateURL(url, instant_url_ref, - kDisableStartMargin); - - if (!effective_url.is_valid()) - return false; - - if (extended_api_enabled && !effective_url.SchemeIsSecure()) - return false; - - if (extended_api_enabled && - !template_url->HasSearchTermsReplacementKey(effective_url)) - return false; - - const GURL instant_url = - TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin); - if (!instant_url.is_valid()) - return false; - - if (MatchesOriginAndPath(effective_url, instant_url)) - return true; - - if (extended_api_enabled && MatchesAnySearchURL(effective_url, template_url)) - return true; - - return false; -} - -string16 GetSearchTermsImpl(const content::WebContents* contents, - const content::NavigationEntry* entry) { - if (!IsQueryExtractionEnabled()) - return string16(); - - // For security reasons, don't extract search terms if the page is not being - // rendered in the privileged Instant renderer process. This is to protect - // against a malicious page somehow scripting the search results page and - // faking search terms in the URL. Random pages can't get into the Instant - // renderer and scripting doesn't work cross-process, so if the page is in - // the Instant process, we know it isn't being exploited. - // Since iOS and Android doesn't use the instant framework, these checks are - // disabled for the two platforms. - Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); -#if !defined(OS_IOS) && !defined(OS_ANDROID) - if (!IsRenderedInInstantProcess(contents, profile) && - (contents->GetController().GetLastCommittedEntry() == entry || - !ShouldAssignURLToInstantRenderer(entry->GetURL(), profile))) - return string16(); -#endif // !defined(OS_IOS) && !defined(OS_ANDROID) - // Check to see if search terms have already been extracted. - string16 search_terms = GetSearchTermsFromNavigationEntry(entry); - if (!search_terms.empty()) - return search_terms; - - // Otherwise, extract from the URL. - TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); - if (!template_url) - return string16(); - - GURL url = entry->GetVirtualURL(); - - if (IsCommandLineInstantURL(url)) - url = CoerceCommandLineURLToTemplateURL(url, template_url->url_ref(), - kDisableStartMargin); - - if (url.SchemeIsSecure() && template_url->HasSearchTermsReplacementKey(url)) - template_url->ExtractSearchTermsFromURL(url, &search_terms); - - return search_terms; -} - -} // namespace - -const char kInstantExtendedSearchTermsKey[] = "search_terms"; - -// Negative start-margin values prevent the "es_sm" parameter from being used. -const int kDisableStartMargin = -1; - -bool IsInstantExtendedAPIEnabled() { -#if defined(OS_IOS) || defined(OS_ANDROID) - return false; -#else - // On desktop, query extraction is part of Instant extended, so if one is - // enabled, the other is too. - return IsQueryExtractionEnabled(); -#endif // defined(OS_IOS) || defined(OS_ANDROID) -} - -// Determine what embedded search page version to request from the user's -// default search provider. If 0, the embedded search UI should not be enabled. -uint64 EmbeddedSearchPageVersion() { - // Check the command-line/about:flags setting first, which should have - // precedence and allows the trial to not be reported (if it's never queried). - const CommandLine* command_line = CommandLine::ForCurrentProcess(); - if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) { - RecordInstantExtendedOptInState(OPT_OUT); - return kEmbeddedPageVersionDisabled; - } - if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { - // The user has set the about:flags switch to Enabled - give the default - // UI version. - RecordInstantExtendedOptInState(OPT_IN); - return kEmbeddedPageVersionDefault; - } - - RecordInstantExtendedOptInState(NOT_SET); - FieldTrialFlags flags; - if (GetFieldTrialInfo( - base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName), - &flags, NULL)) { - return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, - kEmbeddedPageVersionDefault, - flags); - } - return kEmbeddedPageVersionDisabled; -} - -bool IsQueryExtractionEnabled() { - return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled; -} - -string16 GetSearchTermsFromNavigationEntry( - const content::NavigationEntry* entry) { - string16 search_terms; - if (entry) - entry->GetExtraData(kInstantExtendedSearchTermsKey, &search_terms); - return search_terms; -} - -string16 GetSearchTerms(const content::WebContents* contents) { - if (!contents) - return string16(); - - const content::NavigationEntry* entry = - contents->GetController().GetVisibleEntry(); - if (!entry) - return string16(); - - return GetSearchTermsImpl(contents, entry); -} - -bool IsInstantNTP(const content::WebContents* contents) { - if (!contents) - return false; - - return NavEntryIsInstantNTP(contents, - contents->GetController().GetVisibleEntry()); -} - -bool NavEntryIsInstantNTP(const content::WebContents* contents, - const content::NavigationEntry* entry) { - if (!contents || !entry) - return false; - - Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); - return IsInstantExtendedAPIEnabled() && - IsRenderedInInstantProcess(contents, profile) && - IsInstantURL(entry->GetVirtualURL(), profile) && - GetSearchTermsImpl(contents, entry).empty(); -} - -bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile) { - return url.is_valid() && - profile && - (url.SchemeIs(chrome::kChromeSearchScheme) || - IsInstantURL(url, profile) || - (IsInstantExtendedAPIEnabled() && - url == GURL(chrome::kChromeSearchLocalOmniboxPopupURL))); -} - -void RegisterUserPrefs(PrefRegistrySyncable* registry) { - registry->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, - PrefRegistrySyncable::SYNCABLE_PREF); - registry->RegisterBooleanPref(prefs::kInstantEnabled, false, - PrefRegistrySyncable::SYNCABLE_PREF); - // This default is overridden by SetInstantExtendedPrefDefault(). - registry->RegisterBooleanPref(prefs::kInstantExtendedEnabled, false, - PrefRegistrySyncable::SYNCABLE_PREF); -} - -const char* GetInstantPrefName() { - return IsInstantExtendedAPIEnabled() ? prefs::kInstantExtendedEnabled : - prefs::kInstantEnabled; -} - -bool IsInstantPrefEnabled(Profile* profile) { - if (!profile || profile->IsOffTheRecord()) - return false; - - const PrefService* prefs = profile->GetPrefs(); - if (!prefs) - return false; - - const char* pref_name = GetInstantPrefName(); - const bool pref_value = prefs->GetBoolean(pref_name); - - if (pref_name == prefs::kInstantExtendedEnabled) { - // Note that this is only recorded for the first profile that calls this - // code (which happens on startup). - static bool recorded = false; - if (!recorded) { - UMA_HISTOGRAM_BOOLEAN("InstantExtended.PrefValue", pref_value); - recorded = true; - } - } - - return pref_value; -} - -void SetInstantExtendedPrefDefault(Profile* profile) { - PrefService* prefs = profile ? profile->GetPrefs() : NULL; - if (!prefs) - return; - - bool pref_default = false; - - // Check the command-line/about:flags setting first, which should have - // precedence and allows the trial to not be reported (if it's never queried). - const CommandLine* command_line = CommandLine::ForCurrentProcess(); - if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { - pref_default = true; - } else if (!command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) { - uint64 trial_default = kInstantExtendedActivationDefault; - - FieldTrialFlags flags; - if (GetFieldTrialInfo( - base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName), - &flags, NULL)) { - trial_default = GetUInt64ValueForFlagWithDefault( - kInstantExtendedActivationName, - kInstantExtendedActivationDefault, - flags); - } - - if (trial_default == INSTANT_DEFAULT_ON) { - pref_default = true; - } else if (trial_default != INSTANT_DEFAULT_OFF) { - pref_default = prefs->GetBoolean(prefs::kInstantEnabled); - } - } - - prefs->SetDefaultPrefValue(prefs::kInstantExtendedEnabled, - Value::CreateBooleanValue(pref_default)); -} - -GURL GetInstantURL(Profile* profile, int start_margin) { - const bool extended_api_enabled = IsInstantExtendedAPIEnabled(); - - const PrefService* prefs = profile && !profile->IsOffTheRecord() ? - profile->GetPrefs() : NULL; - if (!IsInstantPrefEnabled(profile) && - !(extended_api_enabled && prefs && - prefs->GetBoolean(prefs::kSearchSuggestEnabled))) - return GURL(); - - TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); - if (!template_url) - return GURL(); - - CommandLine* cl = CommandLine::ForCurrentProcess(); - if (cl->HasSwitch(switches::kInstantURL)) { - GURL instant_url(cl->GetSwitchValueASCII(switches::kInstantURL)); - if (extended_api_enabled) { - // Extended mode won't work if the search terms replacement key is absent. - GURL coerced_url = CoerceCommandLineURLToTemplateURL( - instant_url, template_url->instant_url_ref(), start_margin); - if (!template_url->HasSearchTermsReplacementKey(coerced_url)) - return GURL(); - } - return instant_url; - } - - GURL instant_url = - TemplateURLRefToGURL(template_url->instant_url_ref(), start_margin); - - if (extended_api_enabled) { - // Extended mode won't work if the search terms replacement key is absent. - if (!template_url->HasSearchTermsReplacementKey(instant_url)) - return GURL(); - - // Extended mode requires HTTPS. Force it if necessary. - if (!instant_url.SchemeIsSecure()) { - const std::string secure_scheme = chrome::kHttpsScheme; - GURL::Replacements replacements; - replacements.SetSchemeStr(secure_scheme); - instant_url = instant_url.ReplaceComponents(replacements); - } - } - - return instant_url; -} - -bool IsInstantEnabled(Profile* profile) { - return GetInstantURL(profile, kDisableStartMargin).is_valid(); -} - -void EnableInstantExtendedAPIForTesting() { - CommandLine* cl = CommandLine::ForCurrentProcess(); - cl->AppendSwitch(switches::kEnableInstantExtendedAPI); -} - -bool GetFieldTrialInfo(const std::string& group_name, - FieldTrialFlags* flags, - uint64* group_number) { - if (EndsWith(group_name, kDisablingSuffix, true) || - !StartsWithASCII(group_name, kGroupNumberPrefix, true)) - return false; - - // We have a valid trial that starts with "Group" and isn't disabled. - // First extract the flags. - std::string group_prefix(group_name); - - size_t first_space = group_name.find(" "); - if (first_space != std::string::npos) { - // There is a flags section of the group name. Split that out and parse it. - group_prefix = group_name.substr(0, first_space); - if (!base::SplitStringIntoKeyValuePairs(group_name.substr(first_space), - ':', ' ', flags)) { - // Failed to parse the flags section. Assume the whole group name is - // invalid. - return false; - } - } - - // Now extract the group number, making sure we get a non-zero value. - uint64 temp_group_number = 0; - std::string group_suffix = group_prefix.substr(strlen(kGroupNumberPrefix)); - if (!base::StringToUint64(group_suffix, &temp_group_number) || - temp_group_number == 0) - return false; - - if (group_number) - *group_number = temp_group_number; - - return true; -} - -// Given a FieldTrialFlags object, returns the string value of the provided -// flag. -std::string GetStringValueForFlagWithDefault(const std::string& flag, - const std::string& default_value, - const FieldTrialFlags& flags) { - FieldTrialFlags::const_iterator i; - for (i = flags.begin(); i != flags.end(); i++) { - if (i->first == flag) - return i->second; - } - return default_value; -} - -// Given a FieldTrialFlags object, returns the uint64 value of the provided -// flag. -uint64 GetUInt64ValueForFlagWithDefault(const std::string& flag, - uint64 default_value, - const FieldTrialFlags& flags) { - uint64 value; - std::string str_value = GetStringValueForFlagWithDefault(flag, "", flags); - if (base::StringToUint64(str_value, &value)) - return value; - return default_value; -} - -// Given a FieldTrialFlags object, returns the boolean value of the provided -// flag. -bool GetBoolValueForFlagWithDefault(const std::string& flag, - bool default_value, - const FieldTrialFlags& flags) { - return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); -} - -// Coerces the commandline Instant URL to look like a template URL, so that we -// can extract search terms from it. -GURL CoerceCommandLineURLToTemplateURL(const GURL& instant_url, - const TemplateURLRef& ref, - int start_margin) { - GURL search_url = TemplateURLRefToGURL(ref, start_margin); - - // NOTE(samarth): GURL returns temporaries which we must save because - // GURL::Replacements expects the replacements to live until - // ReplaceComponents is called. - const std::string search_scheme = chrome::kHttpsScheme; - const std::string search_host = search_url.host(); - const std::string search_port = search_url.port(); - const std::string search_path = search_url.path(); - - GURL::Replacements replacements; - replacements.SetSchemeStr(search_scheme); - replacements.SetHostStr(search_host); - replacements.SetPortStr(search_port); - replacements.SetPathStr(search_path); - return instant_url.ReplaceComponents(replacements); -} - -} // namespace search -} // namespace chrome diff --git a/chrome/browser/instant/search.h b/chrome/browser/instant/search.h deleted file mode 100644 index a25b819..0000000 --- a/chrome/browser/instant/search.h +++ /dev/null @@ -1,159 +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_INSTANT_SEARCH_H_ -#define CHROME_BROWSER_INSTANT_SEARCH_H_ - -#include -#include -#include - -#include "base/basictypes.h" -#include "base/string16.h" - -class GURL; -class PrefRegistrySyncable; -class Profile; -class TemplateURL; -class TemplateURLRef; - -namespace content { -class NavigationEntry; -class WebContents; -} - -namespace chrome { -namespace search { - -// The key used to store search terms data in the NavigationEntry to be later -// displayed in the omnibox. With the context of the user's exact query, -// InstantController sets the correct search terms to be displayed. -extern const char kInstantExtendedSearchTermsKey[]; - -// Use this value for "start margin" to prevent the "es_sm" parameter from -// being used. -extern const int kDisableStartMargin; - -// Returns whether the Instant Extended API is enabled. -bool IsInstantExtendedAPIEnabled(); - -// Returns the value to pass to the &espv CGI parameter when loading the -// embedded search page from the user's default search provider. Will be -// 0 if the Instant Extended API is not enabled. -uint64 EmbeddedSearchPageVersion(); - -// Returns whether query extraction is enabled. -bool IsQueryExtractionEnabled(); - -// Returns the search terms attached to a specific NavigationEntry, or empty -// string otherwise. Does not consider IsQueryExtractionEnabled(), so most -// callers should use GetSearchTerms() below instead. -string16 GetSearchTermsFromNavigationEntry( - const content::NavigationEntry* entry); - -// Returns search terms if this WebContents is a search results page. It looks -// in the visible NavigationEntry first, to see if search terms have already -// been extracted. Failing that, it tries to extract search terms from the URL. -// Returns a blank string if search terms were not found, or if search terms -// extraction is disabled for this WebContents or profile. -string16 GetSearchTerms(const content::WebContents* contents); - -// Returns true if |url| should be rendered in the Instant renderer process. -bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile); - -// Returns true if the visible entry of |contents| is a New Tab Page rendered -// by Instant. A page that matches the search or Instant URL of the default -// search provider but does not have any search terms is considered an Instant -// New Tab Page. -bool IsInstantNTP(const content::WebContents* contents); - -// Same as IsInstantNTP but uses |nav_entry| to determine the URL for the page -// instead of using the visible entry. -bool NavEntryIsInstantNTP(const content::WebContents* contents, - const content::NavigationEntry* nav_entry); - -// Registers Instant-related user preferences. Called at startup. -void RegisterUserPrefs(PrefRegistrySyncable* registry); - -// Returns prefs::kInstantExtendedEnabled in extended mode; -// prefs::kInstantEnabled otherwise. -const char* GetInstantPrefName(); - -// Returns whether the Instant pref (as per GetInstantPrefName()) is enabled. -bool IsInstantPrefEnabled(Profile* profile); - -// Sets the default value of prefs::kInstantExtendedEnabled, based on field -// trials and the current value of prefs::kInstantEnabled. -void SetInstantExtendedPrefDefault(Profile* profile); - -// Returns the Instant URL of the default search engine. Returns an empty GURL -// if the engine doesn't have an Instant URL, or if it shouldn't be used (say -// because it doesn't satisfy the requirements for extended mode or if Instant -// is disabled through preferences). Callers must check that the returned URL is -// valid before using it. The value of |start_margin| is used for the "es_sm" -// parameter in the URL. -// NOTE: This method expands the default search engine's instant_url template, -// so it shouldn't be called from SearchTermsData or other such code that would -// lead to an infinite recursion. -GURL GetInstantURL(Profile* profile, int start_margin); - -// Instant (loading a remote server page and talking to it using the searchbox -// API) is considered enabled if there's a valid Instant URL that can be used, -// so this simply returns whether GetInstantURL() is a valid URL. -// NOTE: This method expands the default search engine's instant_ur templatel, -// so it shouldn't be called from SearchTermsData or other such code that would -// lead to an infinite recursion. -bool IsInstantEnabled(Profile* profile); - -// ----------------------------------------------------- -// The following APIs are exposed for use in tests only. -// ----------------------------------------------------- - -// Forces the Instant Extended API to be enabled for tests. -void EnableInstantExtendedAPIForTesting(); - -// Type for a collection of experiment configuration parameters. -typedef std::vector > FieldTrialFlags; - -// Given a field trial group name, parses out the group number and configuration -// flags. On success, |flags| will be filled with the field trial flags. |flags| -// must not be NULL. If not NULL, |group_number| will receive the experiment -// group number. -// Returns true iff field trial info was successfully parsed out of -// |group_name|. -// Exposed for testing only. -bool GetFieldTrialInfo(const std::string& group_name, - FieldTrialFlags* flags, - uint64* group_number); - -// Given a FieldTrialFlags object, returns the string value of the provided -// flag. -// Exposed for testing only. -std::string GetStringValueForFlagWithDefault(const std::string& flag, - const std::string& default_value, - const FieldTrialFlags& flags); - -// Given a FieldTrialFlags object, returns the uint64 value of the provided -// flag. -// Exposed for testing only. -uint64 GetUInt64ValueForFlagWithDefault(const std::string& flag, - uint64 default_value, - const FieldTrialFlags& flags); - -// Given a FieldTrialFlags object, returns the bool value of the provided flag. -// Exposed for testing only. -bool GetBoolValueForFlagWithDefault(const std::string& flag, - bool default_value, - const FieldTrialFlags& flags); - -// Coerces the commandline Instant URL to look like a template URL, so that we -// can extract search terms from it. Exposed for testing only. -GURL CoerceCommandLineURLToTemplateURL(const GURL& instant_url, - const TemplateURLRef& ref, - int start_margin); - -} // namespace search -} // namespace chrome - -#endif // CHROME_BROWSER_INSTANT_SEARCH_H_ diff --git a/chrome/browser/instant/search_unittest.cc b/chrome/browser/instant/search_unittest.cc deleted file mode 100644 index 46fecea..0000000 --- a/chrome/browser/instant/search_unittest.cc +++ /dev/null @@ -1,317 +0,0 @@ -// Copyright (c) 2013 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 "base/command_line.h" -#include "base/prefs/pref_service.h" -#include "chrome/browser/instant/search.h" -#include "chrome/browser/search_engines/template_url_service.h" -#include "chrome/browser/search_engines/template_url_service_factory.h" -#include "chrome/browser/ui/tabs/tab_strip_model.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/url_constants.h" -#include "chrome/test/base/browser_with_test_window_test.h" -#include "chrome/test/base/ui_test_utils.h" -#include "content/public/browser/web_contents.h" - -namespace chrome { -namespace search { - -TEST(EmbeddedSearchFieldTrialTest, GetFieldTrialInfo) { - FieldTrialFlags flags; - uint64 group_number = 0; - const uint64 ZERO = 0; - - EXPECT_FALSE(GetFieldTrialInfo("", &flags, &group_number)); - EXPECT_EQ(ZERO, group_number); - EXPECT_EQ(ZERO, flags.size()); - - EXPECT_TRUE(GetFieldTrialInfo("Group77", &flags, &group_number)); - EXPECT_EQ(uint64(77), group_number); - EXPECT_EQ(ZERO, flags.size()); - - group_number = 0; - EXPECT_FALSE(GetFieldTrialInfo("Group77.2", &flags, &group_number)); - EXPECT_EQ(ZERO, group_number); - EXPECT_EQ(ZERO, flags.size()); - - EXPECT_FALSE(GetFieldTrialInfo("Invalid77", &flags, &group_number)); - EXPECT_EQ(ZERO, group_number); - EXPECT_EQ(ZERO, flags.size()); - - EXPECT_FALSE(GetFieldTrialInfo("Invalid77", &flags, NULL)); - EXPECT_EQ(ZERO, flags.size()); - - EXPECT_TRUE(GetFieldTrialInfo("Group77 ", &flags, &group_number)); - EXPECT_EQ(uint64(77), group_number); - EXPECT_EQ(ZERO, flags.size()); - - group_number = 0; - flags.clear(); - EXPECT_EQ(uint64(9999), GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); - EXPECT_TRUE(GetFieldTrialInfo("Group77 foo:6", &flags, &group_number)); - EXPECT_EQ(uint64(77), group_number); - EXPECT_EQ(uint64(1), flags.size()); - EXPECT_EQ(uint64(6), GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); - - group_number = 0; - flags.clear(); - EXPECT_TRUE(GetFieldTrialInfo( - "Group77 bar:1 baz:7 cat:dogs", &flags, &group_number)); - EXPECT_EQ(uint64(77), group_number); - EXPECT_EQ(uint64(3), flags.size()); - EXPECT_EQ(true, GetBoolValueForFlagWithDefault("bar", false, flags)); - EXPECT_EQ(uint64(7), GetUInt64ValueForFlagWithDefault("baz", 0, flags)); - EXPECT_EQ("dogs", GetStringValueForFlagWithDefault("cat", "", flags)); - EXPECT_EQ("default", GetStringValueForFlagWithDefault( - "moose", "default", flags)); - - group_number = 0; - flags.clear(); - EXPECT_FALSE(GetFieldTrialInfo( - "Group77 bar:1 baz:7 cat:dogs DISABLED", &flags, &group_number)); - EXPECT_EQ(ZERO, group_number); - EXPECT_EQ(ZERO, flags.size()); -} - -class SearchTest : public BrowserWithTestWindowTest { - protected: - virtual void SetUp() OVERRIDE { - BrowserWithTestWindowTest::SetUp(); - TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( - profile(), &TemplateURLServiceFactory::BuildInstanceFor); - TemplateURLService* template_url_service = - TemplateURLServiceFactory::GetForProfile(profile()); - ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); - - TemplateURLData data; - data.SetURL("http://foo.com/url?bar={searchTerms}"); - data.instant_url = "http://foo.com/instant?foo=foo#foo=foo"; - data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); - data.search_terms_replacement_key = "strk"; - - TemplateURL* template_url = new TemplateURL(profile(), data); - // Takes ownership of |template_url|. - template_url_service->Add(template_url); - template_url_service->SetDefaultSearchProvider(template_url); - } -}; - -struct SearchTestCase { - const char* url; - bool expected_result; - const char* comment; -}; - -TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedDisabled) { - const SearchTestCase kTestCases[] = { - {"chrome-search://foo/bar", true, ""}, - {"http://foo.com/instant", true, ""}, - {"http://foo.com/instant?foo=bar", true, ""}, - {"https://foo.com/instant", true, ""}, - {"https://foo.com/instant#foo=bar", true, ""}, - {"HtTpS://fOo.CoM/instant", true, ""}, - {"http://foo.com:80/instant", true, ""}, - {"invalid URL", false, "Invalid URL"}, - {"unknown://scheme/path", false, "Unknown scheme"}, - {"ftp://foo.com/instant", false, "Non-HTTP scheme"}, - {"http://sub.foo.com/instant", false, "Non-exact host"}, - {"http://foo.com:26/instant", false, "Non-default port"}, - {"http://foo.com/instant/bar", false, "Non-exact path"}, - {"http://foo.com/Instant", false, "Case sensitive path"}, - {"http://foo.com/", false, "Non-exact path"}, - {"https://foo.com/", false, "Non-exact path"}, - {"https://foo.com/url?strk", false, "Non-extended mode"}, - {"https://foo.com/alt?strk", false, "Non-extended mode"}, - }; - - for (size_t i = 0; i < arraysize(kTestCases); ++i) { - const SearchTestCase& test = kTestCases[i]; - EXPECT_EQ(test.expected_result, - ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) - << test.url << " " << test.comment; - } -} - -TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) { - EnableInstantExtendedAPIForTesting(); - - const SearchTestCase kTestCases[] = { - {chrome::kChromeSearchLocalOmniboxPopupURL, true, ""}, - {"https://foo.com/instant?strk", true, ""}, - {"https://foo.com/instant#strk", true, ""}, - {"https://foo.com/instant?strk=0", true, ""}, - {"https://foo.com/url?strk", true, ""}, - {"https://foo.com/alt?strk", true, ""}, - {"http://foo.com/instant", false, "Non-HTTPS"}, - {"http://foo.com/instant?strk", false, "Non-HTTPS"}, - {"http://foo.com/instant?strk=1", false, "Non-HTTPS"}, - {"https://foo.com/instant", false, "No search terms replacement"}, - {"https://foo.com/?strk", false, "Non-exact path"}, - }; - - for (size_t i = 0; i < arraysize(kTestCases); ++i) { - const SearchTestCase& test = kTestCases[i]; - EXPECT_EQ(test.expected_result, - ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) - << test.url << " " << test.comment; - } -} - -TEST_F(SearchTest, CoerceCommandLineURLToTemplateURL) { - TemplateURL* template_url = - TemplateURLServiceFactory::GetForProfile(profile())-> - GetDefaultSearchProvider(); - EXPECT_EQ( - GURL("https://foo.com/instant?bar=bar#bar=bar"), - CoerceCommandLineURLToTemplateURL( - GURL("http://myserver.com:9000/dev?bar=bar#bar=bar"), - template_url->instant_url_ref(), kDisableStartMargin)); -} - -const SearchTestCase kInstantNTPTestCases[] = { - {"https://foo.com/instant?strk", true, "Valid Instant URL"}, - {"https://foo.com/instant#strk", true, "Valid Instant URL"}, - {"https://foo.com/url?strk", true, "Valid search URL"}, - {"https://foo.com/url#strk", true, "Valid search URL"}, - {"https://foo.com/alt?strk", true, "Valid alternative URL"}, - {"https://foo.com/alt#strk", true, "Valid alternative URL"}, - {"https://foo.com/url?strk&bar=", true, "No query terms"}, - {"https://foo.com/url?strk&q=abc", true, "No query terms key"}, - {"https://foo.com/url?strk#bar=abc", true, "Query terms key in ref"}, - {"https://foo.com/url?strk&bar=abc", false, "Has query terms"}, - {"http://foo.com/instant?strk=1", false, "Insecure URL"}, - {"https://foo.com/instant", false, "No search terms replacement"}, - {"chrome://blank/", false, "Chrome scheme"}, - {"chrome-search//foo", false, "Chrome-search scheme"}, - {chrome::kChromeSearchLocalOmniboxPopupURL, false, "Local omnibox popup"}, - {"https://bar.com/instant?strk=1", false, "Random non-search page"}, -}; - -TEST_F(SearchTest, InstantNTPExtendedEnabled) { - EnableInstantExtendedAPIForTesting(); - AddTab(browser(), GURL("chrome://blank")); - for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { - const SearchTestCase& test = kInstantNTPTestCases[i]; - NavigateAndCommitActiveTab(GURL(test.url)); - const content::WebContents* contents = - browser()->tab_strip_model()->GetWebContentsAt(0); - EXPECT_EQ(test.expected_result, IsInstantNTP(contents)) - << test.url << " " << test.comment; - } -} - -TEST_F(SearchTest, InstantNTPExtendedDisabled) { - AddTab(browser(), GURL("chrome://blank")); - for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { - const SearchTestCase& test = kInstantNTPTestCases[i]; - NavigateAndCommitActiveTab(GURL(test.url)); - const content::WebContents* contents = - browser()->tab_strip_model()->GetWebContentsAt(0); - EXPECT_FALSE(IsInstantNTP(contents)) << test.url << " " << test.comment; - } -} - -TEST_F(SearchTest, InstantNTPCustomNavigationEntry) { - EnableInstantExtendedAPIForTesting(); - AddTab(browser(), GURL("chrome://blank")); - for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { - const SearchTestCase& test = kInstantNTPTestCases[i]; - NavigateAndCommitActiveTab(GURL(test.url)); - content::WebContents* contents = - browser()->tab_strip_model()->GetWebContentsAt(0); - content::NavigationController& controller = contents->GetController(); - controller.SetTransientEntry( - controller.CreateNavigationEntry(GURL("chrome://blank"), - content::Referrer(), - content::PAGE_TRANSITION_LINK, - false, - std::string(), - contents->GetBrowserContext())); - // The active entry is chrome://blank and not an NTP. - EXPECT_FALSE(IsInstantNTP(contents)); - EXPECT_EQ(test.expected_result, - NavEntryIsInstantNTP(contents, - controller.GetLastCommittedEntry())) - << test.url << " " << test.comment; - } -} - -TEST_F(SearchTest, GetInstantURLExtendedDisabled) { - // Instant is disabled, so no Instant URL. - EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); - - // Enable Instant. - profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, true); - EXPECT_EQ(GURL("http://foo.com/instant?foo=foo#foo=foo"), - GetInstantURL(profile(), kDisableStartMargin)); - - // Override the Instant URL on the commandline. - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kInstantURL, - "http://myserver.com:9000/dev?bar=bar#bar=bar"); - EXPECT_EQ(GURL("http://myserver.com:9000/dev?bar=bar#bar=bar"), - GetInstantURL(profile(), kDisableStartMargin)); -} - -TEST_F(SearchTest, GetInstantURLExtendedEnabled) { - EnableInstantExtendedAPIForTesting(); - - // Instant is disabled, so no Instant URL. - EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); - - // Enable Instant. Still no Instant URL because "strk" is missing. - profile()->GetPrefs()->SetBoolean(prefs::kInstantExtendedEnabled, true); - EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); - - { - // Set an Instant URL with a valid search terms replacement key. - TemplateURLService* template_url_service = - TemplateURLServiceFactory::GetForProfile(profile()); - - TemplateURLData data; - data.SetURL("http://foo.com/url?bar={searchTerms}"); - data.instant_url = "http://foo.com/instant?foo=foo#foo=foo&strk"; - data.search_terms_replacement_key = "strk"; - - TemplateURL* template_url = new TemplateURL(profile(), data); - // Takes ownership of |template_url|. - template_url_service->Add(template_url); - template_url_service->SetDefaultSearchProvider(template_url); - } - - // Now there should be a valid Instant URL. Note the HTTPS "upgrade". - EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), - GetInstantURL(profile(), kDisableStartMargin)); - - // Enable suggest. No difference. - profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); - EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), - GetInstantURL(profile(), kDisableStartMargin)); - - // Disable Instant. No difference, because suggest is still enabled. - profile()->GetPrefs()->SetBoolean(prefs::kInstantExtendedEnabled, false); - EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), - GetInstantURL(profile(), kDisableStartMargin)); - - // Override the Instant URL on the commandline. Oops, forgot "strk". - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kInstantURL, - "http://myserver.com:9000/dev?bar=bar#bar=bar"); - EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); - - // Override with "strk". For fun, put it in the query, instead of the ref. - CommandLine::ForCurrentProcess()->AppendSwitchASCII( - switches::kInstantURL, - "http://myserver.com:9000/dev?bar=bar&strk#bar=bar"); - EXPECT_EQ(GURL("http://myserver.com:9000/dev?bar=bar&strk#bar=bar"), - GetInstantURL(profile(), kDisableStartMargin)); - - // Disable suggest. No Instant URL. - profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); - EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); -} - -} // namespace search -} // namespace chrome diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc index cb26e9b..8aad6b1 100644 --- a/chrome/browser/policy/policy_browsertest.cc +++ b/chrome/browser/policy/policy_browsertest.cc @@ -31,9 +31,6 @@ #include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" -#include "chrome/browser/instant/instant_service.h" -#include "chrome/browser/instant/instant_service_factory.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/media/media_capture_devices_dispatcher.h" #include "chrome/browser/media/media_stream_devices_controller.h" #include "chrome/browser/net/url_request_mock_util.h" @@ -43,6 +40,9 @@ #include "chrome/browser/policy/policy_map.h" #include "chrome/browser/prefs/session_startup_pref.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/instant_service.h" +#include "chrome/browser/search/instant_service_factory.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index 97348eb..731a9a3 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -33,7 +33,6 @@ #include "chrome/browser/google/google_url_tracker_factory.h" #include "chrome/browser/gpu/gl_string_manager.h" #include "chrome/browser/gpu/gpu_mode_manager.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/intranet_redirect_detector.h" #include "chrome/browser/io_thread.h" #include "chrome/browser/managed_mode/managed_mode.h" @@ -63,6 +62,7 @@ #include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/renderer_host/web_cache_manager.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/search_engines/template_url_prepopulate_data.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/sync/invalidations/invalidator_storage.h" diff --git a/chrome/browser/search/OWNERS b/chrome/browser/search/OWNERS new file mode 100644 index 0000000..8514380 --- /dev/null +++ b/chrome/browser/search/OWNERS @@ -0,0 +1,3 @@ +dhollowa@chromium.org +sky@chromium.org +sreeram@chromium.org diff --git a/chrome/browser/search/instant_io_context.cc b/chrome/browser/search/instant_io_context.cc new file mode 100644 index 0000000..ad813ea --- /dev/null +++ b/chrome/browser/search/instant_io_context.cc @@ -0,0 +1,151 @@ +// Copyright 2013 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/search/instant_io_context.h" + +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/resource_context.h" +#include "content/public/browser/resource_request_info.h" +#include "googleurl/src/gurl.h" +#include "net/url_request/url_request.h" + +using content::BrowserThread; + +namespace { + +// Retrieves the Instant data from the |context|'s named user-data. +InstantIOContext* GetDataForResourceContext( + content::ResourceContext* context) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + return base::UserDataAdapter::Get( + context, InstantIOContext::kInstantIOContextKeyName); +} + +InstantIOContext* GetDataForRequest(const net::URLRequest* request) { + const content::ResourceRequestInfo* info = + content::ResourceRequestInfo::ForRequest(request); + if (!info) + return NULL; + + return GetDataForResourceContext(info->GetContext()); +} + +} // namespace + +const char InstantIOContext::kInstantIOContextKeyName[] = "instant_io_context"; + +InstantIOContext::InstantIOContext() { + // The InstantIOContext is created on the UI thread but is accessed + // on the IO thread. + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); +} + +InstantIOContext::~InstantIOContext() { +} + +// static +void InstantIOContext::SetUserDataOnIO( + content::ResourceContext* resource_context, + scoped_refptr instant_io_context) { + resource_context->SetUserData( + InstantIOContext::kInstantIOContextKeyName, + new base::UserDataAdapter(instant_io_context)); +} + +// static +void InstantIOContext::AddInstantProcessOnIO( + scoped_refptr instant_io_context, int process_id) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + instant_io_context->process_ids_.insert(process_id); +} + +// static +void InstantIOContext::RemoveInstantProcessOnIO( + scoped_refptr instant_io_context, int process_id) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + instant_io_context->process_ids_.erase(process_id); +} + +// static +void InstantIOContext::ClearInstantProcessesOnIO( + scoped_refptr instant_io_context) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + instant_io_context->process_ids_.clear(); +} + +// static +void InstantIOContext::AddMostVisitedItemIDOnIO( + scoped_refptr instant_io_context, + uint64 most_visited_item_id, const GURL& url) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + instant_io_context->most_visited_item_id_to_url_map_[most_visited_item_id] = + url; +} + +// static +void InstantIOContext::DeleteMostVisitedURLsOnIO( + scoped_refptr instant_io_context, + std::vector deleted_ids, bool all_history) { + if (all_history) { + instant_io_context->most_visited_item_id_to_url_map_.clear(); + return; + } + + for (size_t i = 0; i < deleted_ids.size(); ++i) { + instant_io_context->most_visited_item_id_to_url_map_.erase( + instant_io_context->most_visited_item_id_to_url_map_.find( + deleted_ids[i])); + } +} + +// static +bool InstantIOContext::ShouldServiceRequest(const net::URLRequest* request) { + const content::ResourceRequestInfo* info = + content::ResourceRequestInfo::ForRequest(request); + if (!info) + return false; + + InstantIOContext* instant_io_context = GetDataForRequest(request); + if (!instant_io_context) + return false; + + int process_id = -1; + int render_view_id = -1; + if (info->GetAssociatedRenderView(&process_id, &render_view_id) && + instant_io_context->IsInstantProcess(process_id)) + return true; + return false; +} + +// static +bool InstantIOContext::GetURLForMostVisitedItemId( + const net::URLRequest* request, + uint64 most_visited_item_id, + GURL* url) { + InstantIOContext* instant_io_context = GetDataForRequest(request); + if (!instant_io_context) { + *url = GURL(); + return false; + } + + return instant_io_context->GetURLForMostVisitedItemId(most_visited_item_id, + url); +} + +bool InstantIOContext::IsInstantProcess(int process_id) const { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + return process_ids_.count(process_id) != 0; +} + +bool InstantIOContext::GetURLForMostVisitedItemId(uint64 most_visited_item_id, + GURL* url) { + std::map::iterator it = + most_visited_item_id_to_url_map_.find(most_visited_item_id); + if (it != most_visited_item_id_to_url_map_.end()) { + *url = it->second; + return true; + } + *url = GURL(); + return false; +} diff --git a/chrome/browser/search/instant_io_context.h b/chrome/browser/search/instant_io_context.h new file mode 100644 index 0000000..c9357b6 --- /dev/null +++ b/chrome/browser/search/instant_io_context.h @@ -0,0 +1,100 @@ +// Copyright 2013 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_SEARCH_INSTANT_IO_CONTEXT_H_ +#define CHROME_BROWSER_SEARCH_INSTANT_IO_CONTEXT_H_ + +#include +#include +#include + +#include "base/basictypes.h" +#include "base/memory/ref_counted.h" + +class GURL; + +namespace content { +class ResourceContext; +} + +namespace net { +class URLRequest; +} + +// IO thread data held for Instant. This reflects the data held in +// InstantService for use on the IO thread. Owned by ResourceContext +// as user data. +class InstantIOContext : public base::RefCountedThreadSafe { + public: + InstantIOContext(); + + // Key name for context UserData. UserData is created by InstantService + // but accessed by InstantIOContext. + static const char kInstantIOContextKeyName[]; + + // Installs the |instant_io_context| into the UserData of the + // |resource_context|. + static void SetUserDataOnIO( + content::ResourceContext* resource_context, + scoped_refptr instant_io_context); + + // Add and remove RenderProcessHost IDs that are associated with Instant + // processes. Used to keep process IDs in sync with InstantService. + static void AddInstantProcessOnIO( + scoped_refptr instant_io_context, + int process_id); + static void RemoveInstantProcessOnIO( + scoped_refptr instant_io_context, + int process_id); + static void ClearInstantProcessesOnIO( + scoped_refptr instant_io_context); + + // Associates the |most_visited_item_id| with the |url|. + static void AddMostVisitedItemIDOnIO( + scoped_refptr instant_io_context, + uint64 most_visited_item_id, const GURL& url); + + // Deletes the Most Visited item IDs contained in |deleted_ids| from the url + // mapping. If |all_history| is true, then ignores |deleted_ids| and + // deletes all mappings. + static void DeleteMostVisitedURLsOnIO( + scoped_refptr instant_io_context, + std::vector deleted_ids, bool all_history); + + // Determine if this chrome-search: request is coming from an Instant render + // process. + static bool ShouldServiceRequest(const net::URLRequest* request); + + // Returns true if the |most_visited_item_id| is known, and |url| is set. + // Returns false otherwise. + static bool GetURLForMostVisitedItemId( + const net::URLRequest* request, + uint64 most_visited_item_id, GURL* url); + + protected: + virtual ~InstantIOContext(); + + private: + friend class base::RefCountedThreadSafe; + + // Check that |process_id| is in the known set of Instant processes, ie. + // |process_ids_|. + bool IsInstantProcess(int process_id) const; + + bool GetURLForMostVisitedItemId(uint64 most_visited_item_id, GURL* url); + + // The process IDs associated with Instant processes. Mirror of the process + // IDs in InstantService. Duplicated here for synchronous access on the IO + // thread. + std::set process_ids_; + + // The Most Visited item IDs map associated with Instant processes. Mirror of + // the Most Visited item ID map in InstantService. Duplicated here for + // synchronous access on the IO thread. + std::map most_visited_item_id_to_url_map_; + + DISALLOW_COPY_AND_ASSIGN(InstantIOContext); +}; + +#endif // CHROME_BROWSER_SEARCH_INSTANT_IO_CONTEXT_H_ diff --git a/chrome/browser/search/instant_service.cc b/chrome/browser/search/instant_service.cc new file mode 100644 index 0000000..00e34b5 --- /dev/null +++ b/chrome/browser/search/instant_service.cc @@ -0,0 +1,249 @@ +// Copyright 2013 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/search/instant_service.h" + +#include "base/strings/string_number_conversions.h" +#include "chrome/browser/history/history_notifications.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/instant_io_context.h" +#include "chrome/browser/search/instant_service_factory.h" +#include "chrome/browser/search/local_omnibox_popup_source.h" +#include "chrome/browser/ui/webui/favicon_source.h" +#include "chrome/browser/ui/webui/ntp/thumbnail_source.h" +#include "chrome/browser/ui/webui/theme_source.h" +#include "chrome/common/chrome_notification_types.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/notification_service.h" +#include "content/public/browser/notification_types.h" +#include "content/public/browser/render_process_host.h" +#include "content/public/browser/url_data_source.h" +#include "googleurl/src/gurl.h" +#include "net/url_request/url_request.h" + +using content::BrowserThread; + +namespace { + +// Copies deleted urls out of the history data structure |details| into a +// straight vector of GURLs. +void HistoryDetailsToDeletedURLs(const history::URLsDeletedDetails& details, + std::vector* deleted_urls) { + for (history::URLRows::const_iterator it = details.rows.begin(); + it != details.rows.end(); + ++it) { + deleted_urls->push_back(it->url()); + } +} + +} // namespace + +InstantService::InstantService(Profile* profile) + : profile_(profile), + last_most_visited_item_id_(0) { + // Stub for unit tests. + if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) + return; + + registrar_.Add(this, + content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, + content::NotificationService::AllSources()); + registrar_.Add(this, + chrome::NOTIFICATION_HISTORY_URLS_DELETED, + content::NotificationService::AllSources()); + + instant_io_context_ = new InstantIOContext(); + + if (profile_ && profile_->GetResourceContext()) { + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&InstantIOContext::SetUserDataOnIO, + profile->GetResourceContext(), instant_io_context_)); + } + + // Set up the data sources that Instant uses on the NTP. +#if defined(ENABLE_THEMES) + content::URLDataSource::Add(profile, new ThemeSource(profile)); +#endif + content::URLDataSource::Add(profile, new ThumbnailSource(profile)); + content::URLDataSource::Add(profile, new FaviconSource( + profile, FaviconSource::FAVICON)); + content::URLDataSource::Add(profile, new LocalOmniboxPopupSource()); +} + +InstantService::~InstantService() { +} + +// static +const std::string InstantService::MaybeTranslateInstantPathOnUI( + Profile* profile, const std::string& path) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + InstantService* instant_service = + InstantServiceFactory::GetForProfile(profile); + if (!instant_service) + return path; + + uint64 most_visited_item_id = 0; + if (base::StringToUint64(path, &most_visited_item_id)) { + GURL url; + if (instant_service->GetURLForMostVisitedItemId(most_visited_item_id, &url)) + return url.spec(); + } + return path; +} + +const std::string InstantService::MaybeTranslateInstantPathOnIO( + const net::URLRequest* request, const std::string& path) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + uint64 most_visited_item_id = 0; + if (base::StringToUint64(path, &most_visited_item_id)) { + GURL url; + if (InstantIOContext::GetURLForMostVisitedItemId(request, + most_visited_item_id, + &url)) + return url.spec(); + } + return path; +} + +// static +bool InstantService::IsInstantPath(const GURL& url) { + // Strip leading slash. + std::string path = url.path().substr(1); + + // Check that path is of Most Visited item ID form. + uint64 dummy = 0; + return base::StringToUint64(path, &dummy); +} + +void InstantService::AddInstantProcess(int process_id) { + process_ids_.insert(process_id); + + if (instant_io_context_) { + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&InstantIOContext::AddInstantProcessOnIO, + instant_io_context_, process_id)); + } +} + +bool InstantService::IsInstantProcess(int process_id) const { + return process_ids_.find(process_id) != process_ids_.end(); +} + +uint64 InstantService::AddURL(const GURL& url) { + uint64 id = 0; + if (GetMostVisitedItemIDForURL(url, &id)) + return id; + + last_most_visited_item_id_++; + most_visited_item_id_to_url_map_[last_most_visited_item_id_] = url; + url_to_most_visited_item_id_map_[url] = last_most_visited_item_id_; + + if (instant_io_context_) { + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&InstantIOContext::AddMostVisitedItemIDOnIO, + instant_io_context_, last_most_visited_item_id_, url)); + } + + return last_most_visited_item_id_; +} + +bool InstantService::GetMostVisitedItemIDForURL( + const GURL& url, + uint64 *most_visited_item_id) { + std::map::iterator it = + url_to_most_visited_item_id_map_.find(url); + if (it != url_to_most_visited_item_id_map_.end()) { + *most_visited_item_id = it->second; + return true; + } + *most_visited_item_id = 0; + return false; +} + +bool InstantService::GetURLForMostVisitedItemId(uint64 most_visited_item_id, + GURL* url) { + std::map::iterator it = + most_visited_item_id_to_url_map_.find(most_visited_item_id); + if (it != most_visited_item_id_to_url_map_.end()) { + *url = it->second; + return true; + } + *url = GURL(); + return false; +} + +void InstantService::Shutdown() { + process_ids_.clear(); + + if (instant_io_context_) { + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&InstantIOContext::ClearInstantProcessesOnIO, + instant_io_context_)); + } + instant_io_context_ = NULL; +} + +void InstantService::Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) { + switch (type) { + case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { + int process_id = + content::Source(source)->GetID(); + process_ids_.erase(process_id); + + if (instant_io_context_) { + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&InstantIOContext::RemoveInstantProcessOnIO, + instant_io_context_, process_id)); + } + break; + } + case chrome::NOTIFICATION_HISTORY_URLS_DELETED: { + content::Details det(details); + std::vector deleted_urls; + HistoryDetailsToDeletedURLs(*det.ptr(), &deleted_urls); + + std::vector deleted_ids; + if (det->all_history) { + url_to_most_visited_item_id_map_.clear(); + most_visited_item_id_to_url_map_.clear(); + } else { + DeleteHistoryURLs(deleted_urls, &deleted_ids); + } + + if (instant_io_context_) { + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&InstantIOContext::DeleteMostVisitedURLsOnIO, + instant_io_context_, deleted_ids, det->all_history)); + } + break; + } + default: + NOTREACHED() << "Unexpected notification type in InstantService."; + } +} + +void InstantService::DeleteHistoryURLs(const std::vector& deleted_urls, + std::vector* deleted_ids) { + for (std::vector::const_iterator it = deleted_urls.begin(); + it != deleted_urls.end(); + ++it) { + std::map::iterator item = + url_to_most_visited_item_id_map_.find(*it); + if (item != url_to_most_visited_item_id_map_.end()) { + uint64 most_visited_item_id = item->second; + url_to_most_visited_item_id_map_.erase(item); + most_visited_item_id_to_url_map_.erase( + most_visited_item_id_to_url_map_.find(most_visited_item_id)); + deleted_ids->push_back(most_visited_item_id); + } + } +} diff --git a/chrome/browser/search/instant_service.h b/chrome/browser/search/instant_service.h new file mode 100644 index 0000000..d1c84ca --- /dev/null +++ b/chrome/browser/search/instant_service.h @@ -0,0 +1,104 @@ +// Copyright 2013 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_SEARCH_INSTANT_SERVICE_H_ +#define CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ + +#include +#include +#include + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/memory/ref_counted.h" +#include "chrome/browser/profiles/profile_keyed_service.h" +#include "content/public/browser/notification_observer.h" +#include "content/public/browser/notification_registrar.h" + +class GURL; +class InstantIOContext; +class Profile; + +namespace net { +class URLRequest; +} + +// Tracks render process host IDs that are associated with Instant. +class InstantService : public ProfileKeyedService, + public content::NotificationObserver { + public: + explicit InstantService(Profile* profile); + virtual ~InstantService(); + + // A utility to translate an Instant path if it is of Most Visited item ID + // form. If path is a Most Visited item ID and we have a URL for it, then + // this URL is returned in string form. The |path| is a URL fragment + // corresponding to the path of url with the leading slash ("/") stripped. + // For example, chrome-search://favicon/72 would yield a |path| value of "72", + // and since 72 is a valid uint64 the path is translated to a valid url, + // "http://bingo.com/", say. + static const std::string MaybeTranslateInstantPathOnUI( + Profile* profile, const std::string& path); + static const std::string MaybeTranslateInstantPathOnIO( + const net::URLRequest* request, const std::string& path); + static bool IsInstantPath(const GURL& url); + + // Add, remove, and query RenderProcessHost IDs that are associated with + // Instant processes. + void AddInstantProcess(int process_id); + bool IsInstantProcess(int process_id) const; + +#if defined(UNIT_TEST) + int GetInstantProcessCount() const { + return process_ids_.size(); + } +#endif + + // If |url| is known the existing Most Visited item ID is returned. Otherwise + // a new Most Visited item ID is associated with the |url| and returned. + uint64 AddURL(const GURL& url); + + // If there is a mapping for the |url|, sets |most_visited_item_id| and + // returns true. + bool GetMostVisitedItemIDForURL(const GURL& url, + uint64* most_visited_item_id); + + // If there is a mapping for the |most_visited_item_id|, sets |url| and + // returns true. + bool GetURLForMostVisitedItemId(uint64 most_visited_item_id, GURL* url); + + private: + // Overridden from ProfileKeyedService: + virtual void Shutdown() OVERRIDE; + + // Overridden from content::NotificationObserver: + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) OVERRIDE; + + // Removes entries of each url in |deleted_urls| from the ID maps. Or all + // IDs if |all_history| is true. |deleted_ids| is filled with the newly + // deleted Most Visited item IDs. + void DeleteHistoryURLs(const std::vector& deleted_urls, + std::vector* deleted_ids); + + Profile* const profile_; + + // The process ids associated with Instant processes. + std::set process_ids_; + + // A mapping of Most Visited IDs to URLs. Used to hide Most Visited and + // Favicon URLs from the Instant search provider. + uint64 last_most_visited_item_id_; + std::map most_visited_item_id_to_url_map_; + std::map url_to_most_visited_item_id_map_; + + content::NotificationRegistrar registrar_; + + scoped_refptr instant_io_context_; + + DISALLOW_COPY_AND_ASSIGN(InstantService); +}; + +#endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_H_ diff --git a/chrome/browser/search/instant_service_factory.cc b/chrome/browser/search/instant_service_factory.cc new file mode 100644 index 0000000..ebb68a9 --- /dev/null +++ b/chrome/browser/search/instant_service_factory.cc @@ -0,0 +1,37 @@ +// Copyright 2013 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/search/instant_service_factory.h" + +#include "chrome/browser/profiles/profile_dependency_manager.h" +#include "chrome/browser/search/instant_service.h" + +// static +InstantService* InstantServiceFactory::GetForProfile(Profile* profile) { + return static_cast( + GetInstance()->GetServiceForProfile(profile, true)); +} + +// static +InstantServiceFactory* InstantServiceFactory::GetInstance() { + return Singleton::get(); +} + +InstantServiceFactory::InstantServiceFactory() + : ProfileKeyedServiceFactory("InstantService", + ProfileDependencyManager::GetInstance()) { + // No dependencies. +} + +InstantServiceFactory::~InstantServiceFactory() { +} + +bool InstantServiceFactory::ServiceHasOwnInstanceInIncognito() const { + return true; +} + +ProfileKeyedService* InstantServiceFactory::BuildServiceInstanceFor( + Profile* profile) const { + return new InstantService(profile); +} diff --git a/chrome/browser/search/instant_service_factory.h b/chrome/browser/search/instant_service_factory.h new file mode 100644 index 0000000..ad02cdf --- /dev/null +++ b/chrome/browser/search/instant_service_factory.h @@ -0,0 +1,39 @@ +// Copyright 2013 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_SEARCH_INSTANT_SERVICE_FACTORY_H_ +#define CHROME_BROWSER_SEARCH_INSTANT_SERVICE_FACTORY_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/memory/singleton.h" +#include "chrome/browser/profiles/profile_keyed_service_factory.h" + +class InstantService; +class Profile; +class ProfileKeyedService; + +// Singleton that owns all InstantServices and associates them with Profiles. +class InstantServiceFactory : public ProfileKeyedServiceFactory { + public: + // Returns the InstantService for |profile|. + static InstantService* GetForProfile(Profile* profile); + + static InstantServiceFactory* GetInstance(); + + private: + friend struct DefaultSingletonTraits; + + InstantServiceFactory(); + virtual ~InstantServiceFactory(); + + // Overridden from ProfileKeyedServiceFactory: + virtual bool ServiceHasOwnInstanceInIncognito() const OVERRIDE; + virtual ProfileKeyedService* BuildServiceInstanceFor( + Profile* profile) const OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(InstantServiceFactory); +}; + +#endif // CHROME_BROWSER_SEARCH_INSTANT_SERVICE_FACTORY_H_ diff --git a/chrome/browser/search/local_omnibox_popup_source.cc b/chrome/browser/search/local_omnibox_popup_source.cc new file mode 100644 index 0000000..a11a2d8 --- /dev/null +++ b/chrome/browser/search/local_omnibox_popup_source.cc @@ -0,0 +1,77 @@ +// Copyright 2013 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/search/local_omnibox_popup_source.h" + +#include "base/logging.h" +#include "base/memory/ref_counted_memory.h" +#include "base/string_util.h" +#include "chrome/common/url_constants.h" +#include "content/public/common/content_client.h" +#include "googleurl/src/gurl.h" +#include "grit/browser_resources.h" +#include "net/url_request/url_request.h" + +namespace { + +const char kHTMLFilename[] = "local-omnibox-popup.html"; +const char kJsFilename[] = "local-omnibox-popup.js"; +const char kCSSFilename[] = "local-omnibox-popup.css"; + +} // namespace + +LocalOmniboxPopupSource::LocalOmniboxPopupSource() { +} + +LocalOmniboxPopupSource::~LocalOmniboxPopupSource() { +} + +std::string LocalOmniboxPopupSource::GetSource() { + return chrome::kChromeSearchLocalOmniboxPopupHost; +} + +void LocalOmniboxPopupSource::StartDataRequest( + const std::string& path, + bool is_incognito, + const content::URLDataSource::GotDataCallback& callback) { + int identifier = -1; + if (path == kHTMLFilename) { + identifier = IDR_LOCAL_OMNIBOX_POPUP_HTML; + } else if (path == kJsFilename) { + identifier = IDR_LOCAL_OMNIBOX_POPUP_JS; + } else if (path == kCSSFilename) { + identifier = IDR_LOCAL_OMNIBOX_POPUP_CSS; + } else { + callback.Run(NULL); + return; + } + + scoped_refptr response( + content::GetContentClient()->GetDataResourceBytes(identifier)); + callback.Run(response); +} + +std::string LocalOmniboxPopupSource::GetMimeType( + const std::string& path) const { + if (path == kHTMLFilename) + return "text/html"; + if (path == kJsFilename) + return "application/javascript"; + if (path == kCSSFilename) + return "text/css"; + return ""; +} + +bool LocalOmniboxPopupSource::ShouldServiceRequest( + const net::URLRequest* request) const { + DCHECK(request->url().host() == chrome::kChromeSearchLocalOmniboxPopupHost); + + if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { + DCHECK(StartsWithASCII(request->url().path(), "/", true)); + std::string filename = request->url().path().substr(1); + return filename == kHTMLFilename || filename == kJsFilename || + filename == kCSSFilename; + } + return false; +} diff --git a/chrome/browser/search/local_omnibox_popup_source.h b/chrome/browser/search/local_omnibox_popup_source.h new file mode 100644 index 0000000..a85d2e4 --- /dev/null +++ b/chrome/browser/search/local_omnibox_popup_source.h @@ -0,0 +1,34 @@ +// Copyright 2013 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_SEARCH_LOCAL_OMNIBOX_POPUP_SOURCE_H_ +#define CHROME_BROWSER_SEARCH_LOCAL_OMNIBOX_POPUP_SOURCE_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "content/public/browser/url_data_source.h" + +// Serves HTML and resources for the local omnibox popup i.e. +// chrome-search://local-omnibox-popup/local_omnibox_popup.html +class LocalOmniboxPopupSource : public content::URLDataSource { + public: + LocalOmniboxPopupSource(); + + // content::URLDataSource overrides. + virtual std::string GetSource() OVERRIDE; + virtual void StartDataRequest( + const std::string& path, + bool is_incognito, + const content::URLDataSource::GotDataCallback& callback) OVERRIDE; + virtual std::string GetMimeType(const std::string& path) const OVERRIDE; + virtual bool ShouldServiceRequest( + const net::URLRequest* request) const OVERRIDE; + + private: + virtual ~LocalOmniboxPopupSource(); + + DISALLOW_COPY_AND_ASSIGN(LocalOmniboxPopupSource); +}; + +#endif // CHROME_BROWSER_SEARCH_LOCAL_OMNIBOX_POPUP_SOURCE_H_ diff --git a/chrome/browser/search/search.cc b/chrome/browser/search/search.cc new file mode 100644 index 0000000..4385336 --- /dev/null +++ b/chrome/browser/search/search.cc @@ -0,0 +1,550 @@ +// 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/search/search.h" + +#include "base/command_line.h" +#include "base/metrics/field_trial.h" +#include "base/metrics/histogram.h" +#include "base/prefs/pref_service.h" +#include "base/strings/string_number_conversions.h" +#include "base/strings/string_split.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/instant_service.h" +#include "chrome/browser/search/instant_service_factory.h" +#include "chrome/browser/search_engines/template_url_service.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/url_constants.h" +#include "components/user_prefs/pref_registry_syncable.h" +#include "content/public/browser/navigation_entry.h" +#include "content/public/browser/render_process_host.h" +#include "content/public/browser/web_contents.h" + +namespace chrome { +namespace search { + +namespace { + +// The default value we should assign to the instant_extended.enabled pref. As +// with other prefs, the default is used only when the user hasn't toggled the +// pref explicitly. +enum InstantExtendedDefault { + INSTANT_DEFAULT_ON, // Default the pref to be enabled. + INSTANT_USE_EXISTING, // Use the current value of the instant.enabled pref. + INSTANT_DEFAULT_OFF, // Default the pref to be disabled. +}; + +// Configuration options for Embedded Search. +// InstantExtended field trials are named in such a way that we can parse out +// the experiment configuration from the trial's group name in order to give +// us maximum flexability in running experiments. +// Field trial groups should be named things like "Group7 espv:2 instant:1". +// The first token is always GroupN for some integer N, followed by a +// space-delimited list of key:value pairs which correspond to these flags: +const char kEmbeddedPageVersionFlagName[] = "espv"; +const uint64 kEmbeddedPageVersionDisabled = 0; +#if defined(OS_IOS) || defined(OS_ANDROID) +const uint64 kEmbeddedPageVersionDefault = 1; +#else +const uint64 kEmbeddedPageVersionDefault = 2; +#endif + +const char kInstantExtendedActivationName[] = "instant"; +const InstantExtendedDefault kInstantExtendedActivationDefault = + INSTANT_DEFAULT_ON; + +// Constants for the field trial name and group prefix. +const char kInstantExtendedFieldTrialName[] = "InstantExtended"; +const char kGroupNumberPrefix[] = "Group"; + +// If the field trial's group name ends with this string its configuration will +// be ignored and Instant Extended will not be enabled by default. +const char kDisablingSuffix[] = "DISABLED"; + +TemplateURL* GetDefaultSearchProviderTemplateURL(Profile* profile) { + TemplateURLService* template_url_service = + TemplateURLServiceFactory::GetForProfile(profile); + if (template_url_service) + return template_url_service->GetDefaultSearchProvider(); + return NULL; +} + +GURL TemplateURLRefToGURL(const TemplateURLRef& ref, int start_margin) { + TemplateURLRef::SearchTermsArgs search_terms_args = + TemplateURLRef::SearchTermsArgs(string16()); + search_terms_args.omnibox_start_margin = start_margin; + return GURL(ref.ReplaceSearchTerms(search_terms_args)); +} + +bool MatchesOriginAndPath(const GURL& my_url, const GURL& other_url) { + return my_url.host() == other_url.host() && + my_url.port() == other_url.port() && + my_url.path() == other_url.path() && + (my_url.scheme() == other_url.scheme() || + (my_url.SchemeIs(chrome::kHttpsScheme) && + other_url.SchemeIs(chrome::kHttpScheme))); +} + +bool IsCommandLineInstantURL(const GURL& url) { + const CommandLine* cl = CommandLine::ForCurrentProcess(); + const GURL instant_url(cl->GetSwitchValueASCII(switches::kInstantURL)); + return instant_url.is_valid() && MatchesOriginAndPath(url, instant_url); +} + +bool MatchesAnySearchURL(const GURL& url, TemplateURL* template_url) { + GURL search_url = + TemplateURLRefToGURL(template_url->url_ref(), kDisableStartMargin); + if (search_url.is_valid() && MatchesOriginAndPath(url, search_url)) + return true; + + // "URLCount() - 1" because we already tested url_ref above. + for (size_t i = 0; i < template_url->URLCount() - 1; ++i) { + TemplateURLRef ref(template_url, i); + search_url = TemplateURLRefToGURL(ref, kDisableStartMargin); + if (search_url.is_valid() && MatchesOriginAndPath(url, search_url)) + return true; + } + + return false; +} + +enum OptInState { + NOT_SET, // The user has not manually opted into or out of InstantExtended. + OPT_IN, // The user has opted-in to InstantExtended. + OPT_OUT, // The user has opted-out of InstantExtended. + OPT_IN_STATE_ENUM_COUNT, +}; + +void RecordInstantExtendedOptInState(OptInState state) { + static bool recorded = false; + if (!recorded) { + recorded = true; + UMA_HISTOGRAM_ENUMERATION("InstantExtended.OptInState", state, + OPT_IN_STATE_ENUM_COUNT); + } +} + +// Returns true if |contents| is rendered inside the Instant process for +// |profile|. +bool IsRenderedInInstantProcess(const content::WebContents* contents, + Profile* profile) { + const content::RenderProcessHost* process_host = + contents->GetRenderProcessHost(); + if (!process_host) + return false; + + const InstantService* instant_service = + InstantServiceFactory::GetForProfile(profile); + if (!instant_service) + return false; + + return instant_service->IsInstantProcess(process_host->GetID()); +} + +// Returns true if |url| can be used as an Instant URL for |profile|. +bool IsInstantURL(const GURL& url, Profile* profile) { + TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); + if (!template_url) + return false; + + const TemplateURLRef& instant_url_ref = template_url->instant_url_ref(); + const bool extended_api_enabled = IsInstantExtendedAPIEnabled(); + GURL effective_url = url; + + if (IsCommandLineInstantURL(url)) + effective_url = CoerceCommandLineURLToTemplateURL(url, instant_url_ref, + kDisableStartMargin); + + if (!effective_url.is_valid()) + return false; + + if (extended_api_enabled && !effective_url.SchemeIsSecure()) + return false; + + if (extended_api_enabled && + !template_url->HasSearchTermsReplacementKey(effective_url)) + return false; + + const GURL instant_url = + TemplateURLRefToGURL(instant_url_ref, kDisableStartMargin); + if (!instant_url.is_valid()) + return false; + + if (MatchesOriginAndPath(effective_url, instant_url)) + return true; + + if (extended_api_enabled && MatchesAnySearchURL(effective_url, template_url)) + return true; + + return false; +} + +string16 GetSearchTermsImpl(const content::WebContents* contents, + const content::NavigationEntry* entry) { + if (!IsQueryExtractionEnabled()) + return string16(); + + // For security reasons, don't extract search terms if the page is not being + // rendered in the privileged Instant renderer process. This is to protect + // against a malicious page somehow scripting the search results page and + // faking search terms in the URL. Random pages can't get into the Instant + // renderer and scripting doesn't work cross-process, so if the page is in + // the Instant process, we know it isn't being exploited. + // Since iOS and Android doesn't use the instant framework, these checks are + // disabled for the two platforms. + Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); +#if !defined(OS_IOS) && !defined(OS_ANDROID) + if (!IsRenderedInInstantProcess(contents, profile) && + (contents->GetController().GetLastCommittedEntry() == entry || + !ShouldAssignURLToInstantRenderer(entry->GetURL(), profile))) + return string16(); +#endif // !defined(OS_IOS) && !defined(OS_ANDROID) + // Check to see if search terms have already been extracted. + string16 search_terms = GetSearchTermsFromNavigationEntry(entry); + if (!search_terms.empty()) + return search_terms; + + // Otherwise, extract from the URL. + TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); + if (!template_url) + return string16(); + + GURL url = entry->GetVirtualURL(); + + if (IsCommandLineInstantURL(url)) + url = CoerceCommandLineURLToTemplateURL(url, template_url->url_ref(), + kDisableStartMargin); + + if (url.SchemeIsSecure() && template_url->HasSearchTermsReplacementKey(url)) + template_url->ExtractSearchTermsFromURL(url, &search_terms); + + return search_terms; +} + +} // namespace + +const char kInstantExtendedSearchTermsKey[] = "search_terms"; + +// Negative start-margin values prevent the "es_sm" parameter from being used. +const int kDisableStartMargin = -1; + +bool IsInstantExtendedAPIEnabled() { +#if defined(OS_IOS) || defined(OS_ANDROID) + return false; +#else + // On desktop, query extraction is part of Instant extended, so if one is + // enabled, the other is too. + return IsQueryExtractionEnabled(); +#endif // defined(OS_IOS) || defined(OS_ANDROID) +} + +// Determine what embedded search page version to request from the user's +// default search provider. If 0, the embedded search UI should not be enabled. +uint64 EmbeddedSearchPageVersion() { + // Check the command-line/about:flags setting first, which should have + // precedence and allows the trial to not be reported (if it's never queried). + const CommandLine* command_line = CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) { + RecordInstantExtendedOptInState(OPT_OUT); + return kEmbeddedPageVersionDisabled; + } + if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { + // The user has set the about:flags switch to Enabled - give the default + // UI version. + RecordInstantExtendedOptInState(OPT_IN); + return kEmbeddedPageVersionDefault; + } + + RecordInstantExtendedOptInState(NOT_SET); + FieldTrialFlags flags; + if (GetFieldTrialInfo( + base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName), + &flags, NULL)) { + return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, + kEmbeddedPageVersionDefault, + flags); + } + return kEmbeddedPageVersionDisabled; +} + +bool IsQueryExtractionEnabled() { + return EmbeddedSearchPageVersion() != kEmbeddedPageVersionDisabled; +} + +string16 GetSearchTermsFromNavigationEntry( + const content::NavigationEntry* entry) { + string16 search_terms; + if (entry) + entry->GetExtraData(kInstantExtendedSearchTermsKey, &search_terms); + return search_terms; +} + +string16 GetSearchTerms(const content::WebContents* contents) { + if (!contents) + return string16(); + + const content::NavigationEntry* entry = + contents->GetController().GetVisibleEntry(); + if (!entry) + return string16(); + + return GetSearchTermsImpl(contents, entry); +} + +bool IsInstantNTP(const content::WebContents* contents) { + if (!contents) + return false; + + return NavEntryIsInstantNTP(contents, + contents->GetController().GetVisibleEntry()); +} + +bool NavEntryIsInstantNTP(const content::WebContents* contents, + const content::NavigationEntry* entry) { + if (!contents || !entry) + return false; + + Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); + return IsInstantExtendedAPIEnabled() && + IsRenderedInInstantProcess(contents, profile) && + IsInstantURL(entry->GetVirtualURL(), profile) && + GetSearchTermsImpl(contents, entry).empty(); +} + +bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile) { + return url.is_valid() && + profile && + (url.SchemeIs(chrome::kChromeSearchScheme) || + IsInstantURL(url, profile) || + (IsInstantExtendedAPIEnabled() && + url == GURL(chrome::kChromeSearchLocalOmniboxPopupURL))); +} + +void RegisterUserPrefs(PrefRegistrySyncable* registry) { + registry->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, + PrefRegistrySyncable::SYNCABLE_PREF); + registry->RegisterBooleanPref(prefs::kInstantEnabled, false, + PrefRegistrySyncable::SYNCABLE_PREF); + // This default is overridden by SetInstantExtendedPrefDefault(). + registry->RegisterBooleanPref(prefs::kInstantExtendedEnabled, false, + PrefRegistrySyncable::SYNCABLE_PREF); +} + +const char* GetInstantPrefName() { + return IsInstantExtendedAPIEnabled() ? prefs::kInstantExtendedEnabled : + prefs::kInstantEnabled; +} + +bool IsInstantPrefEnabled(Profile* profile) { + if (!profile || profile->IsOffTheRecord()) + return false; + + const PrefService* prefs = profile->GetPrefs(); + if (!prefs) + return false; + + const char* pref_name = GetInstantPrefName(); + const bool pref_value = prefs->GetBoolean(pref_name); + + if (pref_name == prefs::kInstantExtendedEnabled) { + // Note that this is only recorded for the first profile that calls this + // code (which happens on startup). + static bool recorded = false; + if (!recorded) { + UMA_HISTOGRAM_BOOLEAN("InstantExtended.PrefValue", pref_value); + recorded = true; + } + } + + return pref_value; +} + +void SetInstantExtendedPrefDefault(Profile* profile) { + PrefService* prefs = profile ? profile->GetPrefs() : NULL; + if (!prefs) + return; + + bool pref_default = false; + + // Check the command-line/about:flags setting first, which should have + // precedence and allows the trial to not be reported (if it's never queried). + const CommandLine* command_line = CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(switches::kEnableInstantExtendedAPI)) { + pref_default = true; + } else if (!command_line->HasSwitch(switches::kDisableInstantExtendedAPI)) { + uint64 trial_default = kInstantExtendedActivationDefault; + + FieldTrialFlags flags; + if (GetFieldTrialInfo( + base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName), + &flags, NULL)) { + trial_default = GetUInt64ValueForFlagWithDefault( + kInstantExtendedActivationName, + kInstantExtendedActivationDefault, + flags); + } + + if (trial_default == INSTANT_DEFAULT_ON) { + pref_default = true; + } else if (trial_default != INSTANT_DEFAULT_OFF) { + pref_default = prefs->GetBoolean(prefs::kInstantEnabled); + } + } + + prefs->SetDefaultPrefValue(prefs::kInstantExtendedEnabled, + Value::CreateBooleanValue(pref_default)); +} + +GURL GetInstantURL(Profile* profile, int start_margin) { + const bool extended_api_enabled = IsInstantExtendedAPIEnabled(); + + const PrefService* prefs = profile && !profile->IsOffTheRecord() ? + profile->GetPrefs() : NULL; + if (!IsInstantPrefEnabled(profile) && + !(extended_api_enabled && prefs && + prefs->GetBoolean(prefs::kSearchSuggestEnabled))) + return GURL(); + + TemplateURL* template_url = GetDefaultSearchProviderTemplateURL(profile); + if (!template_url) + return GURL(); + + CommandLine* cl = CommandLine::ForCurrentProcess(); + if (cl->HasSwitch(switches::kInstantURL)) { + GURL instant_url(cl->GetSwitchValueASCII(switches::kInstantURL)); + if (extended_api_enabled) { + // Extended mode won't work if the search terms replacement key is absent. + GURL coerced_url = CoerceCommandLineURLToTemplateURL( + instant_url, template_url->instant_url_ref(), start_margin); + if (!template_url->HasSearchTermsReplacementKey(coerced_url)) + return GURL(); + } + return instant_url; + } + + GURL instant_url = + TemplateURLRefToGURL(template_url->instant_url_ref(), start_margin); + + if (extended_api_enabled) { + // Extended mode won't work if the search terms replacement key is absent. + if (!template_url->HasSearchTermsReplacementKey(instant_url)) + return GURL(); + + // Extended mode requires HTTPS. Force it if necessary. + if (!instant_url.SchemeIsSecure()) { + const std::string secure_scheme = chrome::kHttpsScheme; + GURL::Replacements replacements; + replacements.SetSchemeStr(secure_scheme); + instant_url = instant_url.ReplaceComponents(replacements); + } + } + + return instant_url; +} + +bool IsInstantEnabled(Profile* profile) { + return GetInstantURL(profile, kDisableStartMargin).is_valid(); +} + +void EnableInstantExtendedAPIForTesting() { + CommandLine* cl = CommandLine::ForCurrentProcess(); + cl->AppendSwitch(switches::kEnableInstantExtendedAPI); +} + +bool GetFieldTrialInfo(const std::string& group_name, + FieldTrialFlags* flags, + uint64* group_number) { + if (EndsWith(group_name, kDisablingSuffix, true) || + !StartsWithASCII(group_name, kGroupNumberPrefix, true)) + return false; + + // We have a valid trial that starts with "Group" and isn't disabled. + // First extract the flags. + std::string group_prefix(group_name); + + size_t first_space = group_name.find(" "); + if (first_space != std::string::npos) { + // There is a flags section of the group name. Split that out and parse it. + group_prefix = group_name.substr(0, first_space); + if (!base::SplitStringIntoKeyValuePairs(group_name.substr(first_space), + ':', ' ', flags)) { + // Failed to parse the flags section. Assume the whole group name is + // invalid. + return false; + } + } + + // Now extract the group number, making sure we get a non-zero value. + uint64 temp_group_number = 0; + std::string group_suffix = group_prefix.substr(strlen(kGroupNumberPrefix)); + if (!base::StringToUint64(group_suffix, &temp_group_number) || + temp_group_number == 0) + return false; + + if (group_number) + *group_number = temp_group_number; + + return true; +} + +// Given a FieldTrialFlags object, returns the string value of the provided +// flag. +std::string GetStringValueForFlagWithDefault(const std::string& flag, + const std::string& default_value, + const FieldTrialFlags& flags) { + FieldTrialFlags::const_iterator i; + for (i = flags.begin(); i != flags.end(); i++) { + if (i->first == flag) + return i->second; + } + return default_value; +} + +// Given a FieldTrialFlags object, returns the uint64 value of the provided +// flag. +uint64 GetUInt64ValueForFlagWithDefault(const std::string& flag, + uint64 default_value, + const FieldTrialFlags& flags) { + uint64 value; + std::string str_value = GetStringValueForFlagWithDefault(flag, "", flags); + if (base::StringToUint64(str_value, &value)) + return value; + return default_value; +} + +// Given a FieldTrialFlags object, returns the boolean value of the provided +// flag. +bool GetBoolValueForFlagWithDefault(const std::string& flag, + bool default_value, + const FieldTrialFlags& flags) { + return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); +} + +// Coerces the commandline Instant URL to look like a template URL, so that we +// can extract search terms from it. +GURL CoerceCommandLineURLToTemplateURL(const GURL& instant_url, + const TemplateURLRef& ref, + int start_margin) { + GURL search_url = TemplateURLRefToGURL(ref, start_margin); + + // NOTE(samarth): GURL returns temporaries which we must save because + // GURL::Replacements expects the replacements to live until + // ReplaceComponents is called. + const std::string search_scheme = chrome::kHttpsScheme; + const std::string search_host = search_url.host(); + const std::string search_port = search_url.port(); + const std::string search_path = search_url.path(); + + GURL::Replacements replacements; + replacements.SetSchemeStr(search_scheme); + replacements.SetHostStr(search_host); + replacements.SetPortStr(search_port); + replacements.SetPathStr(search_path); + return instant_url.ReplaceComponents(replacements); +} + +} // namespace search +} // namespace chrome diff --git a/chrome/browser/search/search.h b/chrome/browser/search/search.h new file mode 100644 index 0000000..4c2cbf2 --- /dev/null +++ b/chrome/browser/search/search.h @@ -0,0 +1,159 @@ +// 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_SEARCH_SEARCH_H_ +#define CHROME_BROWSER_SEARCH_SEARCH_H_ + +#include +#include +#include + +#include "base/basictypes.h" +#include "base/string16.h" + +class GURL; +class PrefRegistrySyncable; +class Profile; +class TemplateURL; +class TemplateURLRef; + +namespace content { +class NavigationEntry; +class WebContents; +} + +namespace chrome { +namespace search { + +// The key used to store search terms data in the NavigationEntry to be later +// displayed in the omnibox. With the context of the user's exact query, +// InstantController sets the correct search terms to be displayed. +extern const char kInstantExtendedSearchTermsKey[]; + +// Use this value for "start margin" to prevent the "es_sm" parameter from +// being used. +extern const int kDisableStartMargin; + +// Returns whether the Instant Extended API is enabled. +bool IsInstantExtendedAPIEnabled(); + +// Returns the value to pass to the &espv CGI parameter when loading the +// embedded search page from the user's default search provider. Will be +// 0 if the Instant Extended API is not enabled. +uint64 EmbeddedSearchPageVersion(); + +// Returns whether query extraction is enabled. +bool IsQueryExtractionEnabled(); + +// Returns the search terms attached to a specific NavigationEntry, or empty +// string otherwise. Does not consider IsQueryExtractionEnabled(), so most +// callers should use GetSearchTerms() below instead. +string16 GetSearchTermsFromNavigationEntry( + const content::NavigationEntry* entry); + +// Returns search terms if this WebContents is a search results page. It looks +// in the visible NavigationEntry first, to see if search terms have already +// been extracted. Failing that, it tries to extract search terms from the URL. +// Returns a blank string if search terms were not found, or if search terms +// extraction is disabled for this WebContents or profile. +string16 GetSearchTerms(const content::WebContents* contents); + +// Returns true if |url| should be rendered in the Instant renderer process. +bool ShouldAssignURLToInstantRenderer(const GURL& url, Profile* profile); + +// Returns true if the visible entry of |contents| is a New Tab Page rendered +// by Instant. A page that matches the search or Instant URL of the default +// search provider but does not have any search terms is considered an Instant +// New Tab Page. +bool IsInstantNTP(const content::WebContents* contents); + +// Same as IsInstantNTP but uses |nav_entry| to determine the URL for the page +// instead of using the visible entry. +bool NavEntryIsInstantNTP(const content::WebContents* contents, + const content::NavigationEntry* nav_entry); + +// Registers Instant-related user preferences. Called at startup. +void RegisterUserPrefs(PrefRegistrySyncable* registry); + +// Returns prefs::kInstantExtendedEnabled in extended mode; +// prefs::kInstantEnabled otherwise. +const char* GetInstantPrefName(); + +// Returns whether the Instant pref (as per GetInstantPrefName()) is enabled. +bool IsInstantPrefEnabled(Profile* profile); + +// Sets the default value of prefs::kInstantExtendedEnabled, based on field +// trials and the current value of prefs::kInstantEnabled. +void SetInstantExtendedPrefDefault(Profile* profile); + +// Returns the Instant URL of the default search engine. Returns an empty GURL +// if the engine doesn't have an Instant URL, or if it shouldn't be used (say +// because it doesn't satisfy the requirements for extended mode or if Instant +// is disabled through preferences). Callers must check that the returned URL is +// valid before using it. The value of |start_margin| is used for the "es_sm" +// parameter in the URL. +// NOTE: This method expands the default search engine's instant_url template, +// so it shouldn't be called from SearchTermsData or other such code that would +// lead to an infinite recursion. +GURL GetInstantURL(Profile* profile, int start_margin); + +// Instant (loading a remote server page and talking to it using the searchbox +// API) is considered enabled if there's a valid Instant URL that can be used, +// so this simply returns whether GetInstantURL() is a valid URL. +// NOTE: This method expands the default search engine's instant_ur templatel, +// so it shouldn't be called from SearchTermsData or other such code that would +// lead to an infinite recursion. +bool IsInstantEnabled(Profile* profile); + +// ----------------------------------------------------- +// The following APIs are exposed for use in tests only. +// ----------------------------------------------------- + +// Forces the Instant Extended API to be enabled for tests. +void EnableInstantExtendedAPIForTesting(); + +// Type for a collection of experiment configuration parameters. +typedef std::vector > FieldTrialFlags; + +// Given a field trial group name, parses out the group number and configuration +// flags. On success, |flags| will be filled with the field trial flags. |flags| +// must not be NULL. If not NULL, |group_number| will receive the experiment +// group number. +// Returns true iff field trial info was successfully parsed out of +// |group_name|. +// Exposed for testing only. +bool GetFieldTrialInfo(const std::string& group_name, + FieldTrialFlags* flags, + uint64* group_number); + +// Given a FieldTrialFlags object, returns the string value of the provided +// flag. +// Exposed for testing only. +std::string GetStringValueForFlagWithDefault(const std::string& flag, + const std::string& default_value, + const FieldTrialFlags& flags); + +// Given a FieldTrialFlags object, returns the uint64 value of the provided +// flag. +// Exposed for testing only. +uint64 GetUInt64ValueForFlagWithDefault(const std::string& flag, + uint64 default_value, + const FieldTrialFlags& flags); + +// Given a FieldTrialFlags object, returns the bool value of the provided flag. +// Exposed for testing only. +bool GetBoolValueForFlagWithDefault(const std::string& flag, + bool default_value, + const FieldTrialFlags& flags); + +// Coerces the commandline Instant URL to look like a template URL, so that we +// can extract search terms from it. Exposed for testing only. +GURL CoerceCommandLineURLToTemplateURL(const GURL& instant_url, + const TemplateURLRef& ref, + int start_margin); + +} // namespace search +} // namespace chrome + +#endif // CHROME_BROWSER_SEARCH_SEARCH_H_ diff --git a/chrome/browser/search/search_unittest.cc b/chrome/browser/search/search_unittest.cc new file mode 100644 index 0000000..6fb827b --- /dev/null +++ b/chrome/browser/search/search_unittest.cc @@ -0,0 +1,317 @@ +// Copyright (c) 2013 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 "base/command_line.h" +#include "base/prefs/pref_service.h" +#include "chrome/browser/search/search.h" +#include "chrome/browser/search_engines/template_url_service.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" +#include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/url_constants.h" +#include "chrome/test/base/browser_with_test_window_test.h" +#include "chrome/test/base/ui_test_utils.h" +#include "content/public/browser/web_contents.h" + +namespace chrome { +namespace search { + +TEST(EmbeddedSearchFieldTrialTest, GetFieldTrialInfo) { + FieldTrialFlags flags; + uint64 group_number = 0; + const uint64 ZERO = 0; + + EXPECT_FALSE(GetFieldTrialInfo("", &flags, &group_number)); + EXPECT_EQ(ZERO, group_number); + EXPECT_EQ(ZERO, flags.size()); + + EXPECT_TRUE(GetFieldTrialInfo("Group77", &flags, &group_number)); + EXPECT_EQ(uint64(77), group_number); + EXPECT_EQ(ZERO, flags.size()); + + group_number = 0; + EXPECT_FALSE(GetFieldTrialInfo("Group77.2", &flags, &group_number)); + EXPECT_EQ(ZERO, group_number); + EXPECT_EQ(ZERO, flags.size()); + + EXPECT_FALSE(GetFieldTrialInfo("Invalid77", &flags, &group_number)); + EXPECT_EQ(ZERO, group_number); + EXPECT_EQ(ZERO, flags.size()); + + EXPECT_FALSE(GetFieldTrialInfo("Invalid77", &flags, NULL)); + EXPECT_EQ(ZERO, flags.size()); + + EXPECT_TRUE(GetFieldTrialInfo("Group77 ", &flags, &group_number)); + EXPECT_EQ(uint64(77), group_number); + EXPECT_EQ(ZERO, flags.size()); + + group_number = 0; + flags.clear(); + EXPECT_EQ(uint64(9999), GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); + EXPECT_TRUE(GetFieldTrialInfo("Group77 foo:6", &flags, &group_number)); + EXPECT_EQ(uint64(77), group_number); + EXPECT_EQ(uint64(1), flags.size()); + EXPECT_EQ(uint64(6), GetUInt64ValueForFlagWithDefault("foo", 9999, flags)); + + group_number = 0; + flags.clear(); + EXPECT_TRUE(GetFieldTrialInfo( + "Group77 bar:1 baz:7 cat:dogs", &flags, &group_number)); + EXPECT_EQ(uint64(77), group_number); + EXPECT_EQ(uint64(3), flags.size()); + EXPECT_EQ(true, GetBoolValueForFlagWithDefault("bar", false, flags)); + EXPECT_EQ(uint64(7), GetUInt64ValueForFlagWithDefault("baz", 0, flags)); + EXPECT_EQ("dogs", GetStringValueForFlagWithDefault("cat", "", flags)); + EXPECT_EQ("default", GetStringValueForFlagWithDefault( + "moose", "default", flags)); + + group_number = 0; + flags.clear(); + EXPECT_FALSE(GetFieldTrialInfo( + "Group77 bar:1 baz:7 cat:dogs DISABLED", &flags, &group_number)); + EXPECT_EQ(ZERO, group_number); + EXPECT_EQ(ZERO, flags.size()); +} + +class SearchTest : public BrowserWithTestWindowTest { + protected: + virtual void SetUp() OVERRIDE { + BrowserWithTestWindowTest::SetUp(); + TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( + profile(), &TemplateURLServiceFactory::BuildInstanceFor); + TemplateURLService* template_url_service = + TemplateURLServiceFactory::GetForProfile(profile()); + ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); + + TemplateURLData data; + data.SetURL("http://foo.com/url?bar={searchTerms}"); + data.instant_url = "http://foo.com/instant?foo=foo#foo=foo"; + data.alternate_urls.push_back("http://foo.com/alt#quux={searchTerms}"); + data.search_terms_replacement_key = "strk"; + + TemplateURL* template_url = new TemplateURL(profile(), data); + // Takes ownership of |template_url|. + template_url_service->Add(template_url); + template_url_service->SetDefaultSearchProvider(template_url); + } +}; + +struct SearchTestCase { + const char* url; + bool expected_result; + const char* comment; +}; + +TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedDisabled) { + const SearchTestCase kTestCases[] = { + {"chrome-search://foo/bar", true, ""}, + {"http://foo.com/instant", true, ""}, + {"http://foo.com/instant?foo=bar", true, ""}, + {"https://foo.com/instant", true, ""}, + {"https://foo.com/instant#foo=bar", true, ""}, + {"HtTpS://fOo.CoM/instant", true, ""}, + {"http://foo.com:80/instant", true, ""}, + {"invalid URL", false, "Invalid URL"}, + {"unknown://scheme/path", false, "Unknown scheme"}, + {"ftp://foo.com/instant", false, "Non-HTTP scheme"}, + {"http://sub.foo.com/instant", false, "Non-exact host"}, + {"http://foo.com:26/instant", false, "Non-default port"}, + {"http://foo.com/instant/bar", false, "Non-exact path"}, + {"http://foo.com/Instant", false, "Case sensitive path"}, + {"http://foo.com/", false, "Non-exact path"}, + {"https://foo.com/", false, "Non-exact path"}, + {"https://foo.com/url?strk", false, "Non-extended mode"}, + {"https://foo.com/alt?strk", false, "Non-extended mode"}, + }; + + for (size_t i = 0; i < arraysize(kTestCases); ++i) { + const SearchTestCase& test = kTestCases[i]; + EXPECT_EQ(test.expected_result, + ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) + << test.url << " " << test.comment; + } +} + +TEST_F(SearchTest, ShouldAssignURLToInstantRendererExtendedEnabled) { + EnableInstantExtendedAPIForTesting(); + + const SearchTestCase kTestCases[] = { + {chrome::kChromeSearchLocalOmniboxPopupURL, true, ""}, + {"https://foo.com/instant?strk", true, ""}, + {"https://foo.com/instant#strk", true, ""}, + {"https://foo.com/instant?strk=0", true, ""}, + {"https://foo.com/url?strk", true, ""}, + {"https://foo.com/alt?strk", true, ""}, + {"http://foo.com/instant", false, "Non-HTTPS"}, + {"http://foo.com/instant?strk", false, "Non-HTTPS"}, + {"http://foo.com/instant?strk=1", false, "Non-HTTPS"}, + {"https://foo.com/instant", false, "No search terms replacement"}, + {"https://foo.com/?strk", false, "Non-exact path"}, + }; + + for (size_t i = 0; i < arraysize(kTestCases); ++i) { + const SearchTestCase& test = kTestCases[i]; + EXPECT_EQ(test.expected_result, + ShouldAssignURLToInstantRenderer(GURL(test.url), profile())) + << test.url << " " << test.comment; + } +} + +TEST_F(SearchTest, CoerceCommandLineURLToTemplateURL) { + TemplateURL* template_url = + TemplateURLServiceFactory::GetForProfile(profile())-> + GetDefaultSearchProvider(); + EXPECT_EQ( + GURL("https://foo.com/instant?bar=bar#bar=bar"), + CoerceCommandLineURLToTemplateURL( + GURL("http://myserver.com:9000/dev?bar=bar#bar=bar"), + template_url->instant_url_ref(), kDisableStartMargin)); +} + +const SearchTestCase kInstantNTPTestCases[] = { + {"https://foo.com/instant?strk", true, "Valid Instant URL"}, + {"https://foo.com/instant#strk", true, "Valid Instant URL"}, + {"https://foo.com/url?strk", true, "Valid search URL"}, + {"https://foo.com/url#strk", true, "Valid search URL"}, + {"https://foo.com/alt?strk", true, "Valid alternative URL"}, + {"https://foo.com/alt#strk", true, "Valid alternative URL"}, + {"https://foo.com/url?strk&bar=", true, "No query terms"}, + {"https://foo.com/url?strk&q=abc", true, "No query terms key"}, + {"https://foo.com/url?strk#bar=abc", true, "Query terms key in ref"}, + {"https://foo.com/url?strk&bar=abc", false, "Has query terms"}, + {"http://foo.com/instant?strk=1", false, "Insecure URL"}, + {"https://foo.com/instant", false, "No search terms replacement"}, + {"chrome://blank/", false, "Chrome scheme"}, + {"chrome-search//foo", false, "Chrome-search scheme"}, + {chrome::kChromeSearchLocalOmniboxPopupURL, false, "Local omnibox popup"}, + {"https://bar.com/instant?strk=1", false, "Random non-search page"}, +}; + +TEST_F(SearchTest, InstantNTPExtendedEnabled) { + EnableInstantExtendedAPIForTesting(); + AddTab(browser(), GURL("chrome://blank")); + for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { + const SearchTestCase& test = kInstantNTPTestCases[i]; + NavigateAndCommitActiveTab(GURL(test.url)); + const content::WebContents* contents = + browser()->tab_strip_model()->GetWebContentsAt(0); + EXPECT_EQ(test.expected_result, IsInstantNTP(contents)) + << test.url << " " << test.comment; + } +} + +TEST_F(SearchTest, InstantNTPExtendedDisabled) { + AddTab(browser(), GURL("chrome://blank")); + for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { + const SearchTestCase& test = kInstantNTPTestCases[i]; + NavigateAndCommitActiveTab(GURL(test.url)); + const content::WebContents* contents = + browser()->tab_strip_model()->GetWebContentsAt(0); + EXPECT_FALSE(IsInstantNTP(contents)) << test.url << " " << test.comment; + } +} + +TEST_F(SearchTest, InstantNTPCustomNavigationEntry) { + EnableInstantExtendedAPIForTesting(); + AddTab(browser(), GURL("chrome://blank")); + for (size_t i = 0; i < arraysize(kInstantNTPTestCases); ++i) { + const SearchTestCase& test = kInstantNTPTestCases[i]; + NavigateAndCommitActiveTab(GURL(test.url)); + content::WebContents* contents = + browser()->tab_strip_model()->GetWebContentsAt(0); + content::NavigationController& controller = contents->GetController(); + controller.SetTransientEntry( + controller.CreateNavigationEntry(GURL("chrome://blank"), + content::Referrer(), + content::PAGE_TRANSITION_LINK, + false, + std::string(), + contents->GetBrowserContext())); + // The active entry is chrome://blank and not an NTP. + EXPECT_FALSE(IsInstantNTP(contents)); + EXPECT_EQ(test.expected_result, + NavEntryIsInstantNTP(contents, + controller.GetLastCommittedEntry())) + << test.url << " " << test.comment; + } +} + +TEST_F(SearchTest, GetInstantURLExtendedDisabled) { + // Instant is disabled, so no Instant URL. + EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); + + // Enable Instant. + profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, true); + EXPECT_EQ(GURL("http://foo.com/instant?foo=foo#foo=foo"), + GetInstantURL(profile(), kDisableStartMargin)); + + // Override the Instant URL on the commandline. + CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kInstantURL, + "http://myserver.com:9000/dev?bar=bar#bar=bar"); + EXPECT_EQ(GURL("http://myserver.com:9000/dev?bar=bar#bar=bar"), + GetInstantURL(profile(), kDisableStartMargin)); +} + +TEST_F(SearchTest, GetInstantURLExtendedEnabled) { + EnableInstantExtendedAPIForTesting(); + + // Instant is disabled, so no Instant URL. + EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); + + // Enable Instant. Still no Instant URL because "strk" is missing. + profile()->GetPrefs()->SetBoolean(prefs::kInstantExtendedEnabled, true); + EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); + + { + // Set an Instant URL with a valid search terms replacement key. + TemplateURLService* template_url_service = + TemplateURLServiceFactory::GetForProfile(profile()); + + TemplateURLData data; + data.SetURL("http://foo.com/url?bar={searchTerms}"); + data.instant_url = "http://foo.com/instant?foo=foo#foo=foo&strk"; + data.search_terms_replacement_key = "strk"; + + TemplateURL* template_url = new TemplateURL(profile(), data); + // Takes ownership of |template_url|. + template_url_service->Add(template_url); + template_url_service->SetDefaultSearchProvider(template_url); + } + + // Now there should be a valid Instant URL. Note the HTTPS "upgrade". + EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), + GetInstantURL(profile(), kDisableStartMargin)); + + // Enable suggest. No difference. + profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, true); + EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), + GetInstantURL(profile(), kDisableStartMargin)); + + // Disable Instant. No difference, because suggest is still enabled. + profile()->GetPrefs()->SetBoolean(prefs::kInstantExtendedEnabled, false); + EXPECT_EQ(GURL("https://foo.com/instant?foo=foo#foo=foo&strk"), + GetInstantURL(profile(), kDisableStartMargin)); + + // Override the Instant URL on the commandline. Oops, forgot "strk". + CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kInstantURL, + "http://myserver.com:9000/dev?bar=bar#bar=bar"); + EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); + + // Override with "strk". For fun, put it in the query, instead of the ref. + CommandLine::ForCurrentProcess()->AppendSwitchASCII( + switches::kInstantURL, + "http://myserver.com:9000/dev?bar=bar&strk#bar=bar"); + EXPECT_EQ(GURL("http://myserver.com:9000/dev?bar=bar&strk#bar=bar"), + GetInstantURL(profile(), kDisableStartMargin)); + + // Disable suggest. No Instant URL. + profile()->GetPrefs()->SetBoolean(prefs::kSearchSuggestEnabled, false); + EXPECT_EQ(GURL(), GetInstantURL(profile(), kDisableStartMargin)); +} + +} // namespace search +} // namespace chrome diff --git a/chrome/browser/search_engines/search_terms_data.cc b/chrome/browser/search_engines/search_terms_data.cc index df6e67b..8588ac4 100644 --- a/chrome/browser/search_engines/search_terms_data.cc +++ b/chrome/browser/search_engines/search_terms_data.cc @@ -10,8 +10,8 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/google/google_util.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "content/public/browser/browser_thread.h" #include "googleurl/src/gurl.h" diff --git a/chrome/browser/sessions/session_types.cc b/chrome/browser/sessions/session_types.cc index 145390b..ee781be 100644 --- a/chrome/browser/sessions/session_types.cc +++ b/chrome/browser/sessions/session_types.cc @@ -9,7 +9,7 @@ #include "base/stl_util.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/instant/search.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/sessions/session_command.h" #include "chrome/browser/ui/browser.h" #include "content/public/browser/favicon_status.h" diff --git a/chrome/browser/sessions/session_types_unittest.cc b/chrome/browser/sessions/session_types_unittest.cc index 5051bf5..254b3a2e 100644 --- a/chrome/browser/sessions/session_types_unittest.cc +++ b/chrome/browser/sessions/session_types_unittest.cc @@ -12,7 +12,7 @@ #include "base/strings/string_number_conversions.h" #include "base/time.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/instant/search.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/sessions/session_types.h" #include "chrome/browser/sessions/session_types_test_helper.h" #include "content/public/browser/favicon_status.h" diff --git a/chrome/browser/ui/bookmarks/bookmark_context_menu_controller.cc b/chrome/browser/ui/bookmarks/bookmark_context_menu_controller.cc index 0d36f17..9fa8749 100644 --- a/chrome/browser/ui/bookmarks/bookmark_context_menu_controller.cc +++ b/chrome/browser/ui/bookmarks/bookmark_context_menu_controller.cc @@ -11,9 +11,9 @@ #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_utils.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/ui/bookmarks/bookmark_utils.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/chrome_pages.h" diff --git a/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc b/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc index e94e6b2..6dc385c 100644 --- a/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc +++ b/chrome/browser/ui/bookmarks/bookmark_tab_helper.cc @@ -7,9 +7,9 @@ #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/defaults.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/prefs/pref_service_syncable.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h" #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" #include "chrome/common/pref_names.h" diff --git a/chrome/browser/ui/bookmarks/bookmark_unittest.cc b/chrome/browser/ui/bookmarks/bookmark_unittest.cc index 139fc55..d54287a 100644 --- a/chrome/browser/ui/bookmarks/bookmark_unittest.cc +++ b/chrome/browser/ui/bookmarks/bookmark_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/instant/search.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index d3ab36a..c34edf9 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -59,7 +59,6 @@ #include "chrome/browser/file_select_helper.h" #include "chrome/browser/first_run/first_run.h" #include "chrome/browser/google/google_url_tracker.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/notifications/notification_ui_manager.h" @@ -71,6 +70,7 @@ #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_metrics.h" #include "chrome/browser/repost_form_warning_controller.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/sessions/session_service.h" #include "chrome/browser/sessions/session_service_factory.h" #include "chrome/browser/sessions/session_tab_helper.h" diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc index 5ffb7f0..ca47c0f 100644 --- a/chrome/browser/ui/browser_instant_controller.cc +++ b/chrome/browser/ui/browser_instant_controller.cc @@ -7,8 +7,8 @@ #include "base/prefs/pref_service.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_web_ui.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/themes/theme_properties.h" #include "chrome/browser/themes/theme_service.h" #include "chrome/browser/themes/theme_service_factory.h" diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm index 4464d66..46bfa53 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm @@ -14,9 +14,9 @@ #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/themes/theme_properties.h" #include "chrome/browser/themes/theme_service.h" #import "chrome/browser/themes/theme_service_factory.h" diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.mm index f5d6e21..06552cd 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.mm @@ -4,7 +4,7 @@ #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.h" -#include "chrome/browser/instant/search.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/themes/theme_properties.h" #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" diff --git a/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm b/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm index 708ecc4..bd8f66b 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm +++ b/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm @@ -10,15 +10,15 @@ #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" #include "chrome/browser/api/infobars/infobar_service.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_window.h" +#import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" -#import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" #import "chrome/browser/ui/cocoa/fast_resize_view.h" #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" #import "chrome/browser/ui/cocoa/nsview_additions.h" diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm index eae9c69..fcb2806 100644 --- a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm @@ -9,7 +9,7 @@ #include "base/stl_util.h" #include "base/sys_string_conversions.h" #include "chrome/browser/autocomplete/autocomplete_match.h" -#include "chrome/browser/instant/search.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/ui/cocoa/event_utils.h" #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm index a939fec..d6efa6d 100644 --- a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm @@ -13,8 +13,8 @@ #include "chrome/browser/autocomplete/autocomplete_input.h" #include "chrome/browser/autocomplete/autocomplete_match.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/ui/cocoa/event_utils.h" #include "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm index 4c31fb6..238d6e2 100644 --- a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac_unittest.mm @@ -4,7 +4,7 @@ #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" -#include "chrome/browser/instant/search.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" diff --git a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm index 3c27b71..1924e91 100644 --- a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm @@ -6,22 +6,22 @@ #include "base/sys_string_conversions.h" #include "base/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" -#include "chrome/browser/instant/search.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/sync/glue/session_model_associator.h" #include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" -#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" #include "chrome/browser/ui/cocoa/run_loop_testing.h" +#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" #import "chrome/browser/ui/cocoa/view_resizer_pong.h" #import "chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h" -#include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" #include "chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h" +#include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" #include "chrome/browser/ui/toolbar/wrench_menu_model.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" #include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest_mac.h" #include "testing/gtest/include/gtest/gtest.h" +#include "testing/gtest_mac.h" #include "testing/platform_test.h" #include "ui/base/l10n/l10n_util.h" diff --git a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc index 01d828c..e3cffad 100644 --- a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc +++ b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc @@ -19,9 +19,9 @@ #include "chrome/browser/bookmarks/bookmark_node_data.h" #include "chrome/browser/command_updater.h" #include "chrome/browser/defaults.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/gtk/gtk_theme_service.h" #include "chrome/browser/ui/gtk/gtk_util.h" diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc index 4446e70..a5dd85c 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc @@ -27,7 +27,6 @@ #include "chrome/browser/command_updater.h" #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" #include "chrome/browser/google/google_url_tracker.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/net/predictor.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/predictors/autocomplete_action_predictor.h" @@ -36,6 +35,7 @@ #include "chrome/browser/prerender/prerender_manager.h" #include "chrome/browser/prerender/prerender_manager_factory.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_prepopulate_data.h" #include "chrome/browser/search_engines/template_url_service.h" diff --git a/chrome/browser/ui/search/instant_browsertest.cc b/chrome/browser/ui/search/instant_browsertest.cc index 74b4947..43fdb0e 100644 --- a/chrome/browser/ui/search/instant_browsertest.cc +++ b/chrome/browser/ui/search/instant_browsertest.cc @@ -4,9 +4,9 @@ #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/history/history_service_factory.h" -#include "chrome/browser/instant/instant_service.h" -#include "chrome/browser/instant/instant_service_factory.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/instant_service.h" +#include "chrome/browser/search/instant_service_factory.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/task_manager/task_manager.h" diff --git a/chrome/browser/ui/search/instant_controller.cc b/chrome/browser/ui/search/instant_controller.cc index 783c628..c9759763 100644 --- a/chrome/browser/ui/search/instant_controller.cc +++ b/chrome/browser/ui/search/instant_controller.cc @@ -13,10 +13,10 @@ #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/history_tab_helper.h" #include "chrome/browser/history/top_sites.h" -#include "chrome/browser/instant/instant_service.h" -#include "chrome/browser/instant/instant_service_factory.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/platform_util.h" +#include "chrome/browser/search/instant_service.h" +#include "chrome/browser/search/instant_service_factory.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/search_engines/search_terms_data.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" diff --git a/chrome/browser/ui/search/instant_extended_browsertest.cc b/chrome/browser/ui/search/instant_extended_browsertest.cc index d3935ae..d0cca0e 100644 --- a/chrome/browser/ui/search/instant_extended_browsertest.cc +++ b/chrome/browser/ui/search/instant_extended_browsertest.cc @@ -16,10 +16,10 @@ #include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/history/top_sites.h" -#include "chrome/browser/instant/instant_service.h" -#include "chrome/browser/instant/instant_service_factory.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/instant_service.h" +#include "chrome/browser/search/instant_service_factory.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/themes/theme_service.h" #include "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/ui/omnibox/omnibox_view.h" diff --git a/chrome/browser/ui/search/instant_extended_manual_browsertest.cc b/chrome/browser/ui/search/instant_extended_manual_browsertest.cc index 332d311..c0e277d 100644 --- a/chrome/browser/ui/search/instant_extended_manual_browsertest.cc +++ b/chrome/browser/ui/search/instant_extended_manual_browsertest.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "base/string_util.h" -#include "chrome/browser/instant/search.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/task_manager/task_manager.h" #include "chrome/browser/task_manager/task_manager_browsertest_util.h" #include "chrome/browser/ui/browser.h" diff --git a/chrome/browser/ui/search/instant_overlay.cc b/chrome/browser/ui/search/instant_overlay.cc index c056e38..352bfbc 100644 --- a/chrome/browser/ui/search/instant_overlay.cc +++ b/chrome/browser/ui/search/instant_overlay.cc @@ -6,7 +6,7 @@ #include "base/auto_reset.h" #include "base/supports_user_data.h" -#include "chrome/browser/instant/search.h" +#include "chrome/browser/search/search.h" #include "chrome/common/url_constants.h" #include "content/public/browser/web_contents.h" diff --git a/chrome/browser/ui/search/search_delegate_unittest.cc b/chrome/browser/ui/search/search_delegate_unittest.cc index 4e4354c..777fa6b 100644 --- a/chrome/browser/ui/search/search_delegate_unittest.cc +++ b/chrome/browser/ui/search/search_delegate_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/instant/search.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/search/search_model.h" #include "chrome/browser/ui/search/search_tab_helper.h" diff --git a/chrome/browser/ui/search/search_model.cc b/chrome/browser/ui/search/search_model.cc index 74232f3..b1830e6 100644 --- a/chrome/browser/ui/search/search_model.cc +++ b/chrome/browser/ui/search/search_model.cc @@ -4,7 +4,7 @@ #include "chrome/browser/ui/search/search_model.h" -#include "chrome/browser/instant/search.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/ui/search/search_model_observer.h" namespace chrome { diff --git a/chrome/browser/ui/search/search_tab_helper.cc b/chrome/browser/ui/search/search_tab_helper.cc index c65d13d..cece414 100644 --- a/chrome/browser/ui/search/search_tab_helper.cc +++ b/chrome/browser/ui/search/search_tab_helper.cc @@ -4,7 +4,7 @@ #include "chrome/browser/ui/search/search_tab_helper.h" -#include "chrome/browser/instant/search.h" +#include "chrome/browser/search/search.h" #include "chrome/common/url_constants.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/notification_service.h" diff --git a/chrome/browser/ui/toolbar/toolbar_model_impl.cc b/chrome/browser/ui/toolbar/toolbar_model_impl.cc index c6b64f1..7b7d930 100644 --- a/chrome/browser/ui/toolbar/toolbar_model_impl.cc +++ b/chrome/browser/ui/toolbar/toolbar_model_impl.cc @@ -11,8 +11,8 @@ #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" #include "chrome/browser/autocomplete/autocomplete_input.h" #include "chrome/browser/autocomplete/autocomplete_match.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/ssl/ssl_error_info.h" #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h" #include "chrome/common/chrome_constants.h" diff --git a/chrome/browser/ui/toolbar/toolbar_model_unittest.cc b/chrome/browser/ui/toolbar/toolbar_model_unittest.cc index 8afdd5f..e130ebc 100644 --- a/chrome/browser/ui/toolbar/toolbar_model_unittest.cc +++ b/chrome/browser/ui/toolbar/toolbar_model_unittest.cc @@ -9,9 +9,9 @@ #include "base/command_line.h" #include "base/utf_string_conversions.h" #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" -#include "chrome/browser/instant/instant_service.h" -#include "chrome/browser/instant/instant_service_factory.h" -#include "chrome/browser/instant/search.h" +#include "chrome/browser/search/instant_service.h" +#include "chrome/browser/search/instant_service_factory.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" diff --git a/chrome/browser/ui/toolbar/wrench_menu_model.cc b/chrome/browser/ui/toolbar/wrench_menu_model.cc index d2f1efe..37f0f5c 100644 --- a/chrome/browser/ui/toolbar/wrench_menu_model.cc +++ b/chrome/browser/ui/toolbar/wrench_menu_model.cc @@ -16,9 +16,9 @@ #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/defaults.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/signin/signin_manager.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/signin_ui_util.h" diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc index ba42b02..046eb55 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc @@ -21,8 +21,8 @@ #include "chrome/browser/browser_shutdown.h" #include "chrome/browser/defaults.h" #include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/themes/theme_properties.h" diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_unittest.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_unittest.cc index a22620e..58f14ea 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_unittest.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_unittest.cc @@ -5,8 +5,8 @@ #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" #include "base/prefs/pref_service.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/common/pref_names.h" diff --git a/chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_views.cc b/chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_views.cc index b0ac763..d35e7a9 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_views.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_views.cc @@ -11,9 +11,9 @@ #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_utils.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/ui/bookmarks/bookmark_utils.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/chrome_pages.h" diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index bda1018..cb7eb97 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -20,7 +20,6 @@ #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/tab_helper.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/managed_mode/managed_mode.h" #include "chrome/browser/native_window_notification_source.h" #include "chrome/browser/password_manager/password_manager.h" @@ -28,6 +27,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/sessions/tab_restore_service.h" #include "chrome/browser/sessions/tab_restore_service_factory.h" #include "chrome/browser/speech/tts_controller.h" diff --git a/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc b/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc index 99a77fc..cfca04c 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc @@ -4,7 +4,7 @@ #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" -#include "chrome/browser/instant/search.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/ui/omnibox/omnibox_popup_non_view.h" #include "chrome/browser/ui/omnibox/omnibox_view.h" #include "chrome/browser/ui/views/location_bar/location_bar_view.h" diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc index 95d90f3..ef77a34 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc @@ -13,8 +13,8 @@ #include "chrome/browser/bookmarks/bookmark_node_data.h" #include "chrome/browser/chromeos/input_method/input_method_configuration.h" #include "chrome/browser/command_updater.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc index 3af8e99..fbdfd75 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc @@ -30,9 +30,9 @@ #include "chrome/browser/autocomplete/keyword_provider.h" #include "chrome/browser/bookmarks/bookmark_node_data.h" #include "chrome/browser/command_updater.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" diff --git a/chrome/browser/ui/views/reload_button.cc b/chrome/browser/ui/views/reload_button.cc index 6340886..f538a03 100644 --- a/chrome/browser/ui/views/reload_button.cc +++ b/chrome/browser/ui/views/reload_button.cc @@ -7,7 +7,7 @@ #include "base/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/command_updater.h" -#include "chrome/browser/instant/search.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/ui/search/search_model.h" #include "chrome/browser/ui/views/location_bar/location_bar_view.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/ui/views/wrench_menu.cc b/chrome/browser/ui/views/wrench_menu.cc index fce9d43..7edbf9a 100644 --- a/chrome/browser/ui/views/wrench_menu.cc +++ b/chrome/browser/ui/views/wrench_menu.cc @@ -13,8 +13,8 @@ #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" diff --git a/chrome/browser/ui/webui/favicon_source.cc b/chrome/browser/ui/webui/favicon_source.cc index 7414c43..6864120 100644 --- a/chrome/browser/ui/webui/favicon_source.cc +++ b/chrome/browser/ui/webui/favicon_source.cc @@ -9,10 +9,10 @@ #include "base/strings/string_number_conversions.h" #include "chrome/browser/favicon/favicon_service_factory.h" #include "chrome/browser/history/top_sites.h" -#include "chrome/browser/instant/instant_io_context.h" -#include "chrome/browser/instant/instant_service.h" -#include "chrome/browser/instant/instant_service_factory.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/instant_io_context.h" +#include "chrome/browser/search/instant_service.h" +#include "chrome/browser/search/instant_service_factory.h" #include "chrome/common/url_constants.h" #include "grit/locale_settings.h" #include "grit/ui_resources.h" diff --git a/chrome/browser/ui/webui/history_ui.cc b/chrome/browser/ui/webui/history_ui.cc index b07e178..fc18eba 100644 --- a/chrome/browser/ui/webui/history_ui.cc +++ b/chrome/browser/ui/webui/history_ui.cc @@ -28,11 +28,11 @@ #include "chrome/browser/history/history_types.h" #include "chrome/browser/history/web_history_service.h" #include "chrome/browser/history/web_history_service_factory.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/managed_mode/managed_mode_url_filter.h" #include "chrome/browser/managed_mode/managed_user_service.h" #include "chrome/browser/managed_mode/managed_user_service_factory.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/webui/favicon_source.h" diff --git a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc index 40dacf1..35c8db4 100644 --- a/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc +++ b/chrome/browser/ui/webui/ntp/ntp_resource_cache.cc @@ -20,9 +20,9 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/first_run/first_run.h" #include "chrome/browser/google/google_util.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/policy/browser_policy_connector.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/themes/theme_properties.h" diff --git a/chrome/browser/ui/webui/ntp/thumbnail_source.cc b/chrome/browser/ui/webui/ntp/thumbnail_source.cc index 0848da3..ac6bcbe62f 100644 --- a/chrome/browser/ui/webui/ntp/thumbnail_source.cc +++ b/chrome/browser/ui/webui/ntp/thumbnail_source.cc @@ -5,14 +5,14 @@ #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" #include "base/callback.h" -#include "base/message_loop.h" #include "base/memory/ref_counted_memory.h" -#include "chrome/browser/instant/instant_io_context.h" -#include "chrome/browser/instant/instant_service.h" -#include "chrome/browser/instant/instant_service_factory.h" +#include "base/message_loop.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/search/instant_io_context.h" +#include "chrome/browser/search/instant_service.h" +#include "chrome/browser/search/instant_service_factory.h" #include "chrome/browser/thumbnails/thumbnail_service.h" #include "chrome/browser/thumbnails/thumbnail_service_factory.h" -#include "chrome/browser/profiles/profile.h" #include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" #include "grit/theme_resources.h" diff --git a/chrome/browser/ui/webui/omnibox/omnibox_ui_handler.cc b/chrome/browser/ui/webui/omnibox/omnibox_ui_handler.cc index c81a0e2..7c43efb 100644 --- a/chrome/browser/ui/webui/omnibox/omnibox_ui_handler.cc +++ b/chrome/browser/ui/webui/omnibox/omnibox_ui_handler.cc @@ -17,7 +17,7 @@ #include "chrome/browser/autocomplete/autocomplete_input.h" #include "chrome/browser/autocomplete/autocomplete_match.h" #include "chrome/browser/autocomplete/autocomplete_provider.h" -#include "chrome/browser/instant/search.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/search_engines/template_url.h" #include "content/public/browser/web_ui.h" diff --git a/chrome/browser/ui/webui/options/browser_options_handler.cc b/chrome/browser/ui/webui/options/browser_options_handler.cc index d645c77..1e30e74 100644 --- a/chrome/browser/ui/webui/options/browser_options_handler.cc +++ b/chrome/browser/ui/webui/options/browser_options_handler.cc @@ -24,7 +24,6 @@ #include "chrome/browser/chrome_page_zoom.h" #include "chrome/browser/custom_home_pages_table_model.h" #include "chrome/browser/download/download_prefs.h" -#include "chrome/browser/instant/search.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/prefs/session_startup_pref.h" #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" @@ -35,6 +34,7 @@ #include "chrome/browser/profiles/profile_info_util.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_shortcut_manager.h" +#include "chrome/browser/search/search.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" diff --git a/chrome/browser/ui/webui/theme_source.cc b/chrome/browser/ui/webui/theme_source.cc index 53eeba7..6061c9c 100644 --- a/chrome/browser/ui/webui/theme_source.cc +++ b/chrome/browser/ui/webui/theme_source.cc @@ -7,9 +7,9 @@ #include "base/memory/ref_counted_memory.h" #include "base/message_loop.h" #include "base/strings/string_number_conversions.h" -#include "chrome/browser/instant/instant_io_context.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/resources_util.h" +#include "chrome/browser/search/instant_io_context.h" #include "chrome/browser/themes/theme_properties.h" #include "chrome/browser/themes/theme_service.h" #include "chrome/browser/themes/theme_service_factory.h" diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 803f2b2..85b6ca1 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -851,16 +851,6 @@ 'browser/infobars/infobar_tab_helper.h', 'browser/infobars/insecure_content_infobar_delegate.cc', 'browser/infobars/insecure_content_infobar_delegate.h', - 'browser/instant/instant_io_context.cc', - 'browser/instant/instant_io_context.h', - 'browser/instant/instant_service.cc', - 'browser/instant/instant_service.h', - 'browser/instant/instant_service_factory.cc', - 'browser/instant/instant_service_factory.h', - 'browser/instant/local_omnibox_popup_source.cc', - 'browser/instant/local_omnibox_popup_source.h', - 'browser/instant/search.cc', - 'browser/instant/search.h', 'browser/internal_auth.cc', 'browser/internal_auth.h', 'browser/intranet_redirect_detector.cc', @@ -1621,6 +1611,16 @@ 'browser/safe_browsing/ui_manager.h', 'browser/screensaver_window_finder_gtk.cc', 'browser/screensaver_window_finder_gtk.h', + 'browser/search/instant_io_context.cc', + 'browser/search/instant_io_context.h', + 'browser/search/instant_service.cc', + 'browser/search/instant_service.h', + 'browser/search/instant_service_factory.cc', + 'browser/search/instant_service_factory.h', + 'browser/search/local_omnibox_popup_source.cc', + 'browser/search/local_omnibox_popup_source.h', + 'browser/search/search.cc', + 'browser/search/search.h', 'browser/search_engines/search_engine_type.h', 'browser/search_engines/search_host_to_urls_map.cc', 'browser/search_engines/search_host_to_urls_map.h', @@ -1628,10 +1628,10 @@ 'browser/search_engines/search_provider_install_data.h', 'browser/search_engines/search_provider_install_state_message_filter.cc', 'browser/search_engines/search_provider_install_state_message_filter.h', - 'browser/search_engines/search_terms_data_android.cc', - 'browser/search_engines/search_terms_data_android.h', 'browser/search_engines/search_terms_data.cc', 'browser/search_engines/search_terms_data.h', + 'browser/search_engines/search_terms_data_android.cc', + 'browser/search_engines/search_terms_data_android.h', 'browser/search_engines/template_url.cc', 'browser/search_engines/template_url.h', 'browser/search_engines/template_url_fetcher.cc', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 4e862e5..c0589a9 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -857,7 +857,6 @@ 'browser/importer/importer_unittest_utils.h', 'browser/importer/safari_importer_unittest.mm', 'browser/importer/toolbar_importer_unittest.cc', - 'browser/instant/search_unittest.cc', 'browser/internal_auth_unittest.cc', 'browser/language_usage_metrics_unittest.cc', 'browser/mac/keystone_glue_unittest.mm', @@ -1037,6 +1036,7 @@ 'browser/safe_browsing/safe_browsing_util_unittest.cc', 'browser/safe_browsing/signature_util_win_unittest.cc', 'browser/safe_browsing/two_phase_uploader_unittest.cc', + 'browser/search/search_unittest.cc', 'browser/search_engines/search_host_to_urls_map_unittest.cc', 'browser/search_engines/search_provider_install_data_unittest.cc', 'browser/search_engines/template_url_fetcher_unittest.cc', @@ -2170,11 +2170,11 @@ 'browser/browser_commands_unittest.cc', 'browser/download/download_shelf_unittest.cc', - 'browser/instant/search_unittest.cc', 'browser/managed_mode/managed_user_passphrase_unittest.cc', 'browser/net/gaia/gaia_oauth_fetcher_unittest.cc', 'browser/page_cycler/page_cycler_unittest.cc', 'browser/profiles/off_the_record_profile_impl_unittest.cc', + 'browser/search/search_unittest.cc', 'browser/sync/profile_sync_service_session_unittest.cc', 'browser/sync/sync_global_error_unittest.cc', 'browser/tab_contents/render_view_context_menu_unittest.cc', -- cgit v1.1