diff options
author | shishir@chromium.org <shishir@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-02 03:05:58 +0000 |
---|---|---|
committer | shishir@chromium.org <shishir@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-02 03:05:58 +0000 |
commit | 9f1b3c0ee0cd6d899c380d68ff9aec32e87471a9 (patch) | |
tree | f3b5c7f6191b14de98809f52f7a2390c4cac5171 | |
parent | c7893dcb2c31af076f8051af5bbaaebb18460273 (diff) | |
download | chromium_src-9f1b3c0ee0cd6d899c380d68ff9aec32e87471a9.zip chromium_src-9f1b3c0ee0cd6d899c380d68ff9aec32e87471a9.tar.gz chromium_src-9f1b3c0ee0cd6d899c380d68ff9aec32e87471a9.tar.bz2 |
Moving and renaming the NetworkActionPredictor into chrome/browser/predictors
BUG=
TEST=Same as before since this is just a move and renaming.
Review URL: http://codereview.chromium.org/9610006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134865 0039d316-1c4b-4281-b951-d872f2087c98
35 files changed, 527 insertions, 508 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc index b8f9c7f..24cbfdf 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.cc +++ b/chrome/browser/autocomplete/autocomplete_edit.cc @@ -17,8 +17,6 @@ #include "chrome/browser/autocomplete/autocomplete_popup_model.h" #include "chrome/browser/autocomplete/autocomplete_popup_view.h" #include "chrome/browser/autocomplete/keyword_provider.h" -#include "chrome/browser/autocomplete/network_action_predictor.h" -#include "chrome/browser/autocomplete/network_action_predictor_factory.h" #include "chrome/browser/autocomplete/search_provider.h" #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/command_updater.h" @@ -27,6 +25,8 @@ #include "chrome/browser/instant/instant_controller.h" #include "chrome/browser/net/predictor.h" #include "chrome/browser/net/url_fixer_upper.h" +#include "chrome/browser/predictors/autocomplete_action_predictor.h" +#include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prerender/prerender_field_trial.h" #include "chrome/browser/prerender/prerender_manager.h" @@ -227,39 +227,38 @@ void AutocompleteEditModel::OnChanged() { const AutocompleteMatch& current_match = user_input_in_progress_ ? CurrentMatch() : AutocompleteMatch(); - NetworkActionPredictor::Action recommended_action = - NetworkActionPredictor::ACTION_NONE; - NetworkActionPredictor* network_action_predictor = + AutocompleteActionPredictor::Action recommended_action = + AutocompleteActionPredictor::ACTION_NONE; + AutocompleteActionPredictor* action_predictor = user_input_in_progress_ ? - NetworkActionPredictorFactory::GetForProfile(profile_) : NULL; - if (network_action_predictor) { - network_action_predictor->RegisterTransitionalMatches(user_text_, - result()); - // Confer with the NetworkActionPredictor to determine what action, if any, - // we should take. Get the recommended action here even if we don't need it - // so we can get stats for anyone who is opted in to UMA, but only get it if - // the user has actually typed something to avoid constructing it before - // it's needed. Note: This event is triggered as part of startup when the - // initial tab transitions to the start page. + AutocompleteActionPredictorFactory::GetForProfile(profile_) : NULL; + if (action_predictor) { + action_predictor->RegisterTransitionalMatches(user_text_, result()); + // Confer with the AutocompleteActionPredictor to determine what action, if + // any, we should take. Get the recommended action here even if we don't + // need it so we can get stats for anyone who is opted in to UMA, but only + // get it if the user has actually typed something to avoid constructing it + // before it's needed. Note: This event is triggered as part of startup when + // the initial tab transitions to the start page. recommended_action = - network_action_predictor->RecommendAction(user_text_, current_match); + action_predictor->RecommendAction(user_text_, current_match); } UMA_HISTOGRAM_ENUMERATION("NetworkActionPredictor.Action", recommended_action, - NetworkActionPredictor::LAST_PREDICT_ACTION); + AutocompleteActionPredictor::LAST_PREDICT_ACTION); string16 suggested_text; if (DoInstant(current_match, &suggested_text)) { SetSuggestedText(suggested_text, instant_complete_behavior_); } else { switch (recommended_action) { - case NetworkActionPredictor::ACTION_PRERENDER: + case AutocompleteActionPredictor::ACTION_PRERENDER: DoPrerender(current_match); break; - case NetworkActionPredictor::ACTION_PRECONNECT: + case AutocompleteActionPredictor::ACTION_PRECONNECT: DoPreconnect(current_match); break; - case NetworkActionPredictor::ACTION_NONE: + case AutocompleteActionPredictor::ACTION_NONE: break; default: NOTREACHED() << "Unexpected recommended action: " << recommended_action; @@ -416,10 +415,10 @@ void AutocompleteEditModel::Revert() { view_->SetWindowTextAndCaretPos(permanent_text_, has_focus_ ? permanent_text_.length() : 0, false, true); - NetworkActionPredictor* network_action_predictor = - NetworkActionPredictorFactory::GetForProfile(profile_); - if (network_action_predictor) - network_action_predictor->ClearTransitionalMatches(); + AutocompleteActionPredictor* action_predictor = + AutocompleteActionPredictorFactory::GetForProfile(profile_); + if (action_predictor) + action_predictor->ClearTransitionalMatches(); } void AutocompleteEditModel::StartAutocomplete( @@ -1125,7 +1124,7 @@ void AutocompleteEditModel::DoPreconnect(const AutocompleteMatch& match) { if (profile_->GetNetworkPredictor()) { profile_->GetNetworkPredictor()->AnticipateOmniboxUrl( match.destination_url, - NetworkActionPredictor::IsPreconnectable(match)); + AutocompleteActionPredictor::IsPreconnectable(match)); } // We could prefetch the alternate nav URL, if any, but because there // can be many of these as a user types an initial series of characters, diff --git a/chrome/browser/autocomplete/network_action_predictor_factory.cc b/chrome/browser/autocomplete/network_action_predictor_factory.cc deleted file mode 100644 index 252e920..0000000 --- a/chrome/browser/autocomplete/network_action_predictor_factory.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/autocomplete/network_action_predictor_factory.h" - -#include "chrome/browser/autocomplete/network_action_predictor.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_dependency_manager.h" - -// static -NetworkActionPredictor* NetworkActionPredictorFactory::GetForProfile( - Profile* profile) { - return static_cast<NetworkActionPredictor*>( - GetInstance()->GetServiceForProfile(profile, true)); -} - -// static -NetworkActionPredictorFactory* NetworkActionPredictorFactory::GetInstance() { - return Singleton<NetworkActionPredictorFactory>::get(); -} - -NetworkActionPredictorFactory::NetworkActionPredictorFactory() - : ProfileKeyedServiceFactory("NetworkActionPredictor", - ProfileDependencyManager::GetInstance()) { - // TODO(erg): When HistoryService is PKSFized, uncomment this. - // DependsOn(HistoryServiceFactory::GetInstance()); -} - -NetworkActionPredictorFactory::~NetworkActionPredictorFactory() {} - -ProfileKeyedService* NetworkActionPredictorFactory::BuildServiceInstanceFor( - Profile* profile) const { - return new NetworkActionPredictor(profile); -} diff --git a/chrome/browser/autocomplete/network_action_predictor_factory.h b/chrome/browser/autocomplete/network_action_predictor_factory.h deleted file mode 100644 index 0f7842b..0000000 --- a/chrome/browser/autocomplete/network_action_predictor_factory.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2011 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_AUTOCOMPLETE_NETWORK_ACTION_PREDICTOR_FACTORY_H_ -#define CHROME_BROWSER_AUTOCOMPLETE_NETWORK_ACTION_PREDICTOR_FACTORY_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/memory/singleton.h" -#include "chrome/browser/profiles/profile_keyed_service_factory.h" - -class NetworkActionPredictor; - -// Singleton that owns all NetworkActionPredictors and associates them with -// Profiles. Listens for the Profile's destruction notification and cleans up -// the associated NetworkActionPredictor. -class NetworkActionPredictorFactory : public ProfileKeyedServiceFactory { - public: - static NetworkActionPredictor* GetForProfile(Profile* profile); - - static NetworkActionPredictorFactory* GetInstance(); - - private: - friend struct DefaultSingletonTraits<NetworkActionPredictorFactory>; - - NetworkActionPredictorFactory(); - virtual ~NetworkActionPredictorFactory(); - - // ProfileKeyedServiceFactory: - virtual ProfileKeyedService* BuildServiceInstanceFor( - Profile* profile) const OVERRIDE; - - DISALLOW_COPY_AND_ASSIGN(NetworkActionPredictorFactory); -}; - -#endif // CHROME_BROWSER_AUTOCOMPLETE_NETWORK_ACTION_PREDICTOR_FACTORY_H_ diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index d966e0f..ac2fcea 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -40,12 +40,12 @@ const char* const kChromePaths[] = { chrome::kChromeUIMediaInternalsHost, chrome::kChromeUIMemoryHost, chrome::kChromeUINetInternalsHost, - chrome::kChromeUINetworkActionPredictorHost, chrome::kChromeUINetworkViewCacheHost, chrome::kChromeUINewTabHost, chrome::kChromeUIOmniboxHost, chrome::kChromeUIPluginsHost, chrome::kChromeUIPolicyHost, + chrome::kChromeUIPredictorsHost, chrome::kChromeUIPrintHost, chrome::kChromeUIProfilerHost, chrome::kChromeUIQuotaInternalsHost, diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index 343b86f..3b4d3ec 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_resources.grd @@ -76,8 +76,8 @@ <include name="IDR_KEYBOARD_MANIFEST" file="resources\keyboard\manifest.json" type="BINDATA" /> <include name="IDR_MEDIA_INTERNALS_HTML" file="resources\media_internals.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> <include name="IDR_MEDIA_INTERNALS_JS" file="resources\media_internals\media_internals.js" flattenhtml="true" type="BINDATA" /> - <include name="IDR_NETWORK_ACTION_PREDICTOR_HTML" file="resources\network_action_predictor\network_action_predictor.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> - <include name="IDR_NETWORK_ACTION_PREDICTOR_JS" file="resources\network_action_predictor\network_action_predictor.js" type="BINDATA" /> + <include name="IDR_AUTOCOMPLETE_ACTION_PREDICTOR_HTML" file="resources\predictors\autocomplete_action_predictor.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> + <include name="IDR_AUTOCOMPLETE_ACTION_PREDICTOR_JS" file="resources\predictors\autocomplete_action_predictor.js" type="BINDATA" /> <include name="IDR_NEW_INCOGNITO_TAB_THEME_CSS" file="resources\new_incognito_tab_theme.css" flattenhtml="true" type="BINDATA" /> <include name="IDR_NEW_TAB_4_HTML" file="resources\ntp4\new_tab.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_NEW_TAB_4_THEME_CSS" file="resources\ntp4\new_tab_theme.css" flattenhtml="true" type="BINDATA" /> diff --git a/chrome/browser/resources/network_action_predictor/OWNERS b/chrome/browser/predictors/OWNERS index 95b3792..95b3792 100644 --- a/chrome/browser/resources/network_action_predictor/OWNERS +++ b/chrome/browser/predictors/OWNERS diff --git a/chrome/browser/autocomplete/network_action_predictor.cc b/chrome/browser/predictors/autocomplete_action_predictor.cc index 310200e..6c2d77a 100644 --- a/chrome/browser/autocomplete/network_action_predictor.cc +++ b/chrome/browser/predictors/autocomplete_action_predictor.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/autocomplete/network_action_predictor.h" +#include "chrome/browser/predictors/autocomplete_action_predictor.h" #include <math.h> @@ -16,10 +16,10 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/autocomplete/autocomplete_match.h" -#include "chrome/browser/autocomplete/network_action_predictor_database.h" #include "chrome/browser/history/history.h" #include "chrome/browser/history/history_notifications.h" #include "chrome/browser/history/in_memory_database.h" +#include "chrome/browser/predictors/autocomplete_action_predictor_database.h" #include "chrome/browser/prerender/prerender_field_trial.h" #include "chrome/browser/prerender/prerender_manager.h" #include "chrome/browser/prerender/prerender_manager_factory.h" @@ -42,7 +42,7 @@ const size_t kMinimumUserTextLength = 1; const int kMinimumNumberOfHits = 3; COMPILE_ASSERT(arraysize(kConfidenceCutoff) == - NetworkActionPredictor::LAST_PREDICT_ACTION, + AutocompleteActionPredictor::LAST_PREDICT_ACTION, ConfidenceCutoff_count_mismatch); enum DatabaseAction { @@ -70,16 +70,16 @@ bool IsAutocompleteMatchSearchType(const AutocompleteMatch& match) { } -const int NetworkActionPredictor::kMaximumDaysToKeepEntry = 14; +const int AutocompleteActionPredictor::kMaximumDaysToKeepEntry = 14; -double NetworkActionPredictor::hit_weight_ = 1.0; +double AutocompleteActionPredictor::hit_weight_ = 1.0; -NetworkActionPredictor::NetworkActionPredictor(Profile* profile) +AutocompleteActionPredictor::AutocompleteActionPredictor(Profile* profile) : profile_(profile), - db_(new NetworkActionPredictorDatabase(profile)), + db_(new AutocompleteActionPredictorDatabase(profile)), initialized_(false) { content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, - base::Bind(&NetworkActionPredictorDatabase::Initialize, db_)); + base::Bind(&AutocompleteActionPredictorDatabase::Initialize, db_)); // Request the in-memory database from the history to force it to load so it's // available as soon as possible. @@ -91,20 +91,20 @@ NetworkActionPredictor::NetworkActionPredictor(Profile* profile) // Create local caches using the database as loaded. We will garbage collect // rows from the caches and the database once the history service is // available. - std::vector<NetworkActionPredictorDatabase::Row>* rows = - new std::vector<NetworkActionPredictorDatabase::Row>(); + std::vector<AutocompleteActionPredictorDatabase::Row>* rows = + new std::vector<AutocompleteActionPredictorDatabase::Row>(); content::BrowserThread::PostTaskAndReply( content::BrowserThread::DB, FROM_HERE, - base::Bind(&NetworkActionPredictorDatabase::GetAllRows, db_, rows), - base::Bind(&NetworkActionPredictor::CreateCaches, AsWeakPtr(), + base::Bind(&AutocompleteActionPredictorDatabase::GetAllRows, db_, rows), + base::Bind(&AutocompleteActionPredictor::CreateCaches, AsWeakPtr(), base::Owned(rows))); } -NetworkActionPredictor::~NetworkActionPredictor() { +AutocompleteActionPredictor::~AutocompleteActionPredictor() { } -void NetworkActionPredictor::RegisterTransitionalMatches( +void AutocompleteActionPredictor::RegisterTransitionalMatches( const string16& user_text, const AutocompleteResult& result) { if (user_text.length() < kMinimumUserTextLength) @@ -132,14 +132,15 @@ void NetworkActionPredictor::RegisterTransitionalMatches( } } -void NetworkActionPredictor::ClearTransitionalMatches() { +void AutocompleteActionPredictor::ClearTransitionalMatches() { transitional_matches_.clear(); } // Given a match, return a recommended action. -NetworkActionPredictor::Action NetworkActionPredictor::RecommendAction( - const string16& user_text, - const AutocompleteMatch& match) const { +AutocompleteActionPredictor::Action + AutocompleteActionPredictor::RecommendAction( + const string16& user_text, + const AutocompleteMatch& match) const { bool is_in_db = false; const double confidence = CalculateConfidence(user_text, match, &is_in_db); DCHECK(confidence >= 0.0 && confidence <= 1.0); @@ -181,15 +182,16 @@ NetworkActionPredictor::Action NetworkActionPredictor::RecommendAction( // Return true if the suggestion type warrants a TCP/IP preconnection. // i.e., it is now quite likely that the user will select the related domain. // static -bool NetworkActionPredictor::IsPreconnectable(const AutocompleteMatch& match) { +bool AutocompleteActionPredictor::IsPreconnectable( + const AutocompleteMatch& match) { return IsAutocompleteMatchSearchType(match); } -void NetworkActionPredictor::Shutdown() { +void AutocompleteActionPredictor::Shutdown() { db_->OnPredictorDestroyed(); } -void NetworkActionPredictor::Observe( +void AutocompleteActionPredictor::Observe( int type, const content::NotificationSource& source, const content::NotificationDetails& details) { @@ -234,7 +236,8 @@ void NetworkActionPredictor::Observe( } } -void NetworkActionPredictor::OnOmniboxOpenedUrl(const AutocompleteLog& log) { +void AutocompleteActionPredictor::OnOmniboxOpenedUrl( + const AutocompleteLog& log) { if (log.text.length() < kMinimumUserTextLength) return; @@ -275,7 +278,7 @@ void NetworkActionPredictor::OnOmniboxOpenedUrl(const AutocompleteLog& log) { const DBCacheKey key = { it->user_text, *url_it }; const bool is_hit = (*url_it == opened_url); - NetworkActionPredictorDatabase::Row row; + AutocompleteActionPredictorDatabase::Row row; row.user_text = key.user_text; row.url = key.url; @@ -313,9 +316,9 @@ void NetworkActionPredictor::OnOmniboxOpenedUrl(const AutocompleteLog& log) { tracked_urls_.clear(); } -void NetworkActionPredictor::DeleteOldIdsFromCaches( +void AutocompleteActionPredictor::DeleteOldIdsFromCaches( history::URLDatabase* url_db, - std::vector<NetworkActionPredictorDatabase::Row::Id>* id_list) { + std::vector<AutocompleteActionPredictorDatabase::Row::Id>* id_list) { CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(url_db); DCHECK(id_list); @@ -337,15 +340,16 @@ void NetworkActionPredictor::DeleteOldIdsFromCaches( } } -void NetworkActionPredictor::DeleteOldEntries(history::URLDatabase* url_db) { +void AutocompleteActionPredictor::DeleteOldEntries( + history::URLDatabase* url_db) { CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(!initialized_); - std::vector<NetworkActionPredictorDatabase::Row::Id> ids_to_delete; + std::vector<AutocompleteActionPredictorDatabase::Row::Id> ids_to_delete; DeleteOldIdsFromCaches(url_db, &ids_to_delete); content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, - base::Bind(&NetworkActionPredictorDatabase::DeleteRows, db_, + base::Bind(&AutocompleteActionPredictorDatabase::DeleteRows, db_, ids_to_delete)); // Register for notifications and set the |initialized_| flag. @@ -356,15 +360,15 @@ void NetworkActionPredictor::DeleteOldEntries(history::URLDatabase* url_db) { initialized_ = true; } -void NetworkActionPredictor::CreateCaches( - std::vector<NetworkActionPredictorDatabase::Row>* rows) { +void AutocompleteActionPredictor::CreateCaches( + std::vector<AutocompleteActionPredictorDatabase::Row>* rows) { CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); DCHECK(!initialized_); DCHECK(db_cache_.empty()); DCHECK(db_id_cache_.empty()); - for (std::vector<NetworkActionPredictorDatabase::Row>::const_iterator it = - rows->begin(); it != rows->end(); ++it) { + for (std::vector<AutocompleteActionPredictorDatabase::Row>::const_iterator + it = rows->begin(); it != rows->end(); ++it) { const DBCacheKey key = { it->user_text, it->url }; const DBCacheValue value = { it->number_of_hits, it->number_of_misses }; db_cache_[key] = value; @@ -382,7 +386,7 @@ void NetworkActionPredictor::CreateCaches( } } -bool NetworkActionPredictor::TryDeleteOldEntries(HistoryService* service) { +bool AutocompleteActionPredictor::TryDeleteOldEntries(HistoryService* service) { if (!service) return false; @@ -394,7 +398,7 @@ bool NetworkActionPredictor::TryDeleteOldEntries(HistoryService* service) { return true; } -double NetworkActionPredictor::CalculateConfidence( +double AutocompleteActionPredictor::CalculateConfidence( const string16& user_text, const AutocompleteMatch& match, bool* is_in_db) const { @@ -412,7 +416,7 @@ double NetworkActionPredictor::CalculateConfidence( return CalculateConfidenceForDbEntry(iter); } -double NetworkActionPredictor::CalculateConfidenceForDbEntry( +double AutocompleteActionPredictor::CalculateConfidenceForDbEntry( DBCacheMap::const_iterator iter) const { const DBCacheValue& value = iter->second; if (value.number_of_hits < kMinimumNumberOfHits) @@ -422,9 +426,9 @@ double NetworkActionPredictor::CalculateConfidenceForDbEntry( return number_of_hits / (number_of_hits + value.number_of_misses); } -void NetworkActionPredictor::AddRow( +void AutocompleteActionPredictor::AddRow( const DBCacheKey& key, - const NetworkActionPredictorDatabase::Row& row) { + const AutocompleteActionPredictorDatabase::Row& row) { if (!initialized_) return; @@ -432,15 +436,15 @@ void NetworkActionPredictor::AddRow( db_cache_[key] = value; db_id_cache_[key] = row.id; content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, - base::Bind(&NetworkActionPredictorDatabase::AddRow, db_, row)); + base::Bind(&AutocompleteActionPredictorDatabase::AddRow, db_, row)); UMA_HISTOGRAM_ENUMERATION("NetworkActionPredictor.DatabaseAction", DATABASE_ACTION_ADD, DATABASE_ACTION_COUNT); } -void NetworkActionPredictor::UpdateRow( +void AutocompleteActionPredictor::UpdateRow( DBCacheMap::iterator it, - const NetworkActionPredictorDatabase::Row& row) { + const AutocompleteActionPredictorDatabase::Row& row) { if (!initialized_) return; @@ -448,28 +452,29 @@ void NetworkActionPredictor::UpdateRow( it->second.number_of_hits = row.number_of_hits; it->second.number_of_misses = row.number_of_misses; content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, - base::Bind(&NetworkActionPredictorDatabase::UpdateRow, db_, row)); + base::Bind(&AutocompleteActionPredictorDatabase::UpdateRow, db_, row)); UMA_HISTOGRAM_ENUMERATION("NetworkActionPredictor.DatabaseAction", DATABASE_ACTION_UPDATE, DATABASE_ACTION_COUNT); } -void NetworkActionPredictor::DeleteAllRows() { +void AutocompleteActionPredictor::DeleteAllRows() { if (!initialized_) return; db_cache_.clear(); db_id_cache_.clear(); content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, - base::Bind(&NetworkActionPredictorDatabase::DeleteAllRows, db_)); + base::Bind(&AutocompleteActionPredictorDatabase::DeleteAllRows, db_)); UMA_HISTOGRAM_ENUMERATION("NetworkActionPredictor.DatabaseAction", DATABASE_ACTION_DELETE_ALL, DATABASE_ACTION_COUNT); } -void NetworkActionPredictor::DeleteRowsWithURLs(const history::URLRows& rows) { +void AutocompleteActionPredictor::DeleteRowsWithURLs( + const history::URLRows& rows) { if (!initialized_) return; - std::vector<NetworkActionPredictorDatabase::Row::Id> id_list; + std::vector<AutocompleteActionPredictorDatabase::Row::Id> id_list; for (DBCacheMap::iterator it = db_cache_.begin(); it != db_cache_.end();) { if (std::find_if(rows.begin(), rows.end(), @@ -485,29 +490,30 @@ void NetworkActionPredictor::DeleteRowsWithURLs(const history::URLRows& rows) { } content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, - base::Bind(&NetworkActionPredictorDatabase::DeleteRows, db_, id_list)); + base::Bind(&AutocompleteActionPredictorDatabase::DeleteRows, + db_, id_list)); UMA_HISTOGRAM_ENUMERATION("NetworkActionPredictor.DatabaseAction", DATABASE_ACTION_DELETE_SOME, DATABASE_ACTION_COUNT); } -void NetworkActionPredictor::BeginTransaction() { +void AutocompleteActionPredictor::BeginTransaction() { if (!initialized_) return; content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, - base::Bind(&NetworkActionPredictorDatabase::BeginTransaction, db_)); + base::Bind(&AutocompleteActionPredictorDatabase::BeginTransaction, db_)); } -void NetworkActionPredictor::CommitTransaction() { +void AutocompleteActionPredictor::CommitTransaction() { if (!initialized_) return; content::BrowserThread::PostTask(content::BrowserThread::DB, FROM_HERE, - base::Bind(&NetworkActionPredictorDatabase::CommitTransaction, db_)); + base::Bind(&AutocompleteActionPredictorDatabase::CommitTransaction, db_)); } -NetworkActionPredictor::TransitionalMatch::TransitionalMatch() { +AutocompleteActionPredictor::TransitionalMatch::TransitionalMatch() { } -NetworkActionPredictor::TransitionalMatch::~TransitionalMatch() { +AutocompleteActionPredictor::TransitionalMatch::~TransitionalMatch() { } diff --git a/chrome/browser/autocomplete/network_action_predictor.h b/chrome/browser/predictors/autocomplete_action_predictor.h index 0cf02a4..a6801ac 100644 --- a/chrome/browser/autocomplete/network_action_predictor.h +++ b/chrome/browser/predictors/autocomplete_action_predictor.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_AUTOCOMPLETE_NETWORK_ACTION_PREDICTOR_H_ -#define CHROME_BROWSER_AUTOCOMPLETE_NETWORK_ACTION_PREDICTOR_H_ +#ifndef CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_H_ +#define CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_H_ #pragma once #include <map> @@ -12,8 +12,8 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/string16.h" -#include "chrome/browser/autocomplete/network_action_predictor_database.h" #include "chrome/browser/history/history_types.h" +#include "chrome/browser/predictors/autocomplete_action_predictor_database.h" #include "chrome/browser/profiles/profile_keyed_service.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" @@ -31,16 +31,16 @@ class URLDatabase; // This class is responsible for determining the correct predictive network // action to take given for a given AutocompleteMatch and entered text. it uses -// a NetworkActionPredictorDatabase accessed asynchronously on the DB thread to -// permanently store the data used to make predictions, and keeps local caches -// of that data to be able to make predictions synchronously on the UI thread -// where it lives. It can be accessed as a weak pointer so that it can safely -// use PostTaskAndReply without fear of crashes if it is destroyed before the -// reply triggers. This is necessary during initialization. -class NetworkActionPredictor +// an AutocompleteActionPredictorDatabase accessed asynchronously on the DB +// thread to permanently store the data used to make predictions, and keeps +// local caches of that data to be able to make predictions synchronously on the +// UI thread where it lives. It can be accessed as a weak pointer so that it can +// safely use PostTaskAndReply without fear of crashes if it is destroyed before +// the reply triggers. This is necessary during initialization. +class AutocompleteActionPredictor : public ProfileKeyedService, public content::NotificationObserver, - public base::SupportsWeakPtr<NetworkActionPredictor> { + public base::SupportsWeakPtr<AutocompleteActionPredictor> { public: enum Action { ACTION_PRERENDER = 0, @@ -49,8 +49,8 @@ class NetworkActionPredictor LAST_PREDICT_ACTION = ACTION_NONE }; - explicit NetworkActionPredictor(Profile* profile); - virtual ~NetworkActionPredictor(); + explicit AutocompleteActionPredictor(Profile* profile); + virtual ~AutocompleteActionPredictor(); static void set_hit_weight(double weight) { hit_weight_ = weight; } static double get_hit_weight() { return hit_weight_; } @@ -79,8 +79,8 @@ class NetworkActionPredictor static bool IsPreconnectable(const AutocompleteMatch& match); private: - friend class NetworkActionPredictorTest; - friend class NetworkActionPredictorDOMHandler; + friend class AutocompleteActionPredictorTest; + friend class AutocompleteActionPredictorDOMHandler; struct TransitionalMatch { TransitionalMatch(); @@ -114,7 +114,7 @@ class NetworkActionPredictor }; typedef std::map<DBCacheKey, DBCacheValue> DBCacheMap; - typedef std::map<DBCacheKey, NetworkActionPredictorDatabase::Row::Id> + typedef std::map<DBCacheKey, AutocompleteActionPredictorDatabase::Row::Id> DBIdCacheMap; static const int kMaximumDaysToKeepEntry; @@ -139,7 +139,7 @@ class NetworkActionPredictor // |id_list| must not be NULL. Every row id deleted will be added to id_list. void DeleteOldIdsFromCaches( history::URLDatabase* url_db, - std::vector<NetworkActionPredictorDatabase::Row::Id>* id_list); + std::vector<AutocompleteActionPredictorDatabase::Row::Id>* id_list); // Called to delete any old or invalid entries from the database. Called after // the local caches are created once the history service is available. @@ -149,7 +149,7 @@ class NetworkActionPredictor // if the history service is available, or registers for the notification of // it becoming available. void CreateCaches( - std::vector<NetworkActionPredictorDatabase::Row>* row_buffer); + std::vector<AutocompleteActionPredictorDatabase::Row>* row_buffer); // Attempts to call DeleteOldEntries if the in-memory database has been loaded // by |service|. Returns success as a boolean. @@ -168,11 +168,11 @@ class NetworkActionPredictor // Adds a row to the database and caches. void AddRow(const DBCacheKey& key, - const NetworkActionPredictorDatabase::Row& row); + const AutocompleteActionPredictorDatabase::Row& row); // Updates a row in the database and the caches. void UpdateRow(DBCacheMap::iterator it, - const NetworkActionPredictorDatabase::Row& row); + const AutocompleteActionPredictorDatabase::Row& row); // Removes all rows from the database and caches. void DeleteAllRows(); @@ -185,7 +185,7 @@ class NetworkActionPredictor void CommitTransaction(); Profile* profile_; - scoped_refptr<NetworkActionPredictorDatabase> db_; + scoped_refptr<AutocompleteActionPredictorDatabase> db_; content::NotificationRegistrar notification_registrar_; // This is cleared after every Omnibox navigation. @@ -200,7 +200,7 @@ class NetworkActionPredictor bool initialized_; - DISALLOW_COPY_AND_ASSIGN(NetworkActionPredictor); + DISALLOW_COPY_AND_ASSIGN(AutocompleteActionPredictor); }; -#endif // CHROME_BROWSER_AUTOCOMPLETE_NETWORK_ACTION_PREDICTOR_H_ +#endif // CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_H_ diff --git a/chrome/browser/autocomplete/network_action_predictor_database.cc b/chrome/browser/predictors/autocomplete_action_predictor_database.cc index a1454f4..7fe9add 100644 --- a/chrome/browser/autocomplete/network_action_predictor_database.cc +++ b/chrome/browser/predictors/autocomplete_action_predictor_database.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/autocomplete/network_action_predictor_database.h" +#include "chrome/browser/predictors/autocomplete_action_predictor_database.h" #include "base/bind.h" #include "base/file_util.h" @@ -17,14 +17,14 @@ namespace { -const char kNetworkActionPredictorTableName[] = "network_action_predictor"; -const FilePath::CharType kNetworkActionPredictorDatabaseName[] = +const char kAutocompleteActionPredictorTableName[] = "network_action_predictor"; +const FilePath::CharType kAutocompleteActionPredictorDatabaseName[] = FILE_PATH_LITERAL("Network Action Predictor"); // The maximum length allowed for strings in the database. const size_t kMaxDataLength = 2048; -void BindRowToStatement(const NetworkActionPredictorDatabase::Row& row, +void BindRowToStatement(const AutocompleteActionPredictorDatabase::Row& row, sql::Statement* statement) { DCHECK(guid::IsValidGUID(row.id)); statement->BindString(0, row.id); @@ -35,7 +35,7 @@ void BindRowToStatement(const NetworkActionPredictorDatabase::Row& row, } bool StepAndInitializeRow(sql::Statement* statement, - NetworkActionPredictorDatabase::Row* row) { + AutocompleteActionPredictorDatabase::Row* row) { if (!statement->Step()) return false; @@ -56,7 +56,7 @@ void LogDatabaseStats(const FilePath& db_path, sql::Connection* db) { sql::Statement count_statement(db->GetUniqueStatement( base::StringPrintf("SELECT count(id) FROM %s", - kNetworkActionPredictorTableName).c_str())); + kAutocompleteActionPredictorTableName).c_str())); if (!count_statement.Step()) return; UMA_HISTOGRAM_COUNTS("NetworkActionPredictor.DatabaseRowCount", @@ -65,12 +65,12 @@ void LogDatabaseStats(const FilePath& db_path, sql::Connection* db) { } -NetworkActionPredictorDatabase::Row::Row() +AutocompleteActionPredictorDatabase::Row::Row() : number_of_hits(0), number_of_misses(0) { } -NetworkActionPredictorDatabase::Row::Row(const Row::Id& id, +AutocompleteActionPredictorDatabase::Row::Row(const Row::Id& id, const string16& user_text, const GURL& url, int number_of_hits, @@ -82,14 +82,16 @@ NetworkActionPredictorDatabase::Row::Row(const Row::Id& id, number_of_misses(number_of_misses) { } -NetworkActionPredictorDatabase::NetworkActionPredictorDatabase(Profile* profile) - : db_path_(profile->GetPath().Append(kNetworkActionPredictorDatabaseName)) { +AutocompleteActionPredictorDatabase::AutocompleteActionPredictorDatabase( + Profile* profile) + : db_path_(profile->GetPath().Append( + kAutocompleteActionPredictorDatabaseName)) { } -NetworkActionPredictorDatabase::~NetworkActionPredictorDatabase() { +AutocompleteActionPredictorDatabase::~AutocompleteActionPredictorDatabase() { } -void NetworkActionPredictorDatabase::Initialize() { +void AutocompleteActionPredictorDatabase::Initialize() { CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); if (canceled_.IsSet()) @@ -101,13 +103,13 @@ void NetworkActionPredictorDatabase::Initialize() { return; } - if (!db_.DoesTableExist(kNetworkActionPredictorTableName)) + if (!db_.DoesTableExist(kAutocompleteActionPredictorTableName)) CreateTable(); LogDatabaseStats(db_path_, &db_); } -void NetworkActionPredictorDatabase::GetRow(const Row::Id& id, Row* row) { +void AutocompleteActionPredictorDatabase::GetRow(const Row::Id& id, Row* row) { CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); if (canceled_.IsSet()) @@ -116,16 +118,16 @@ void NetworkActionPredictorDatabase::GetRow(const Row::Id& id, Row* row) { sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, base::StringPrintf( "SELECT * FROM %s WHERE id=?", - kNetworkActionPredictorTableName).c_str())); + kAutocompleteActionPredictorTableName).c_str())); statement.BindString(0, id); bool success = StepAndInitializeRow(&statement, row); DCHECK(success) << "Failed to get row " << id << " from " - << kNetworkActionPredictorTableName; + << kAutocompleteActionPredictorTableName; } -void NetworkActionPredictorDatabase::GetAllRows( - std::vector<NetworkActionPredictorDatabase::Row>* row_buffer) { +void AutocompleteActionPredictorDatabase::GetAllRows( + std::vector<AutocompleteActionPredictorDatabase::Row>* row_buffer) { CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); CHECK(row_buffer); row_buffer->clear(); @@ -135,15 +137,15 @@ void NetworkActionPredictorDatabase::GetAllRows( sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, base::StringPrintf( - "SELECT * FROM %s", kNetworkActionPredictorTableName).c_str())); + "SELECT * FROM %s", kAutocompleteActionPredictorTableName).c_str())); Row row; while (StepAndInitializeRow(&statement, &row)) row_buffer->push_back(row); } -void NetworkActionPredictorDatabase::AddRow( - const NetworkActionPredictorDatabase::Row& row) { +void AutocompleteActionPredictorDatabase::AddRow( + const AutocompleteActionPredictorDatabase::Row& row) { CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); if (canceled_.IsSet()) @@ -153,16 +155,17 @@ void NetworkActionPredictorDatabase::AddRow( base::StringPrintf( "INSERT INTO %s " "(id, user_text, url, number_of_hits, number_of_misses) " - "VALUES (?,?,?,?,?)", kNetworkActionPredictorTableName).c_str())); + "VALUES (?,?,?,?,?)", + kAutocompleteActionPredictorTableName).c_str())); BindRowToStatement(row, &statement); bool success = statement.Run(); DCHECK(success) << "Failed to insert row " << row.id << " into " - << kNetworkActionPredictorTableName; + << kAutocompleteActionPredictorTableName; } -void NetworkActionPredictorDatabase::UpdateRow( - const NetworkActionPredictorDatabase::Row& row) { +void AutocompleteActionPredictorDatabase::UpdateRow( + const AutocompleteActionPredictorDatabase::Row& row) { CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); if (canceled_.IsSet()) @@ -172,14 +175,14 @@ void NetworkActionPredictorDatabase::UpdateRow( base::StringPrintf( "UPDATE %s " "SET id=?, user_text=?, url=?, number_of_hits=?, number_of_misses=? " - "WHERE id=?1", kNetworkActionPredictorTableName).c_str())); + "WHERE id=?1", kAutocompleteActionPredictorTableName).c_str())); BindRowToStatement(row, &statement); statement.Run(); DCHECK_GT(db_.GetLastChangeCount(), 0); } -void NetworkActionPredictorDatabase::DeleteRow(const Row::Id& id) { +void AutocompleteActionPredictorDatabase::DeleteRow(const Row::Id& id) { CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); if (canceled_.IsSet()) @@ -188,7 +191,7 @@ void NetworkActionPredictorDatabase::DeleteRow(const Row::Id& id) { DeleteRows(std::vector<Row::Id>(1, id)); } -void NetworkActionPredictorDatabase::DeleteRows( +void AutocompleteActionPredictorDatabase::DeleteRows( const std::vector<Row::Id>& id_list) { CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); @@ -197,7 +200,7 @@ void NetworkActionPredictorDatabase::DeleteRows( sql::Statement statement(db_.GetUniqueStatement(base::StringPrintf( "DELETE FROM %s WHERE id=?", - kNetworkActionPredictorTableName).c_str())); + kAutocompleteActionPredictorTableName).c_str())); db_.BeginTransaction(); for (std::vector<Row::Id>::const_iterator it = id_list.begin(); @@ -209,7 +212,7 @@ void NetworkActionPredictorDatabase::DeleteRows( db_.CommitTransaction(); } -void NetworkActionPredictorDatabase::DeleteAllRows() { +void AutocompleteActionPredictorDatabase::DeleteAllRows() { CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); if (canceled_.IsSet()) @@ -217,12 +220,12 @@ void NetworkActionPredictorDatabase::DeleteAllRows() { sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, base::StringPrintf("DELETE FROM %s", - kNetworkActionPredictorTableName).c_str())); + kAutocompleteActionPredictorTableName).c_str())); statement.Run(); } -void NetworkActionPredictorDatabase::BeginTransaction() { +void AutocompleteActionPredictorDatabase::BeginTransaction() { CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); if (canceled_.IsSet()) @@ -231,7 +234,7 @@ void NetworkActionPredictorDatabase::BeginTransaction() { db_.BeginTransaction(); } -void NetworkActionPredictorDatabase::CommitTransaction() { +void AutocompleteActionPredictorDatabase::CommitTransaction() { CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::DB)); if (canceled_.IsSet()) @@ -240,18 +243,19 @@ void NetworkActionPredictorDatabase::CommitTransaction() { db_.CommitTransaction(); } -void NetworkActionPredictorDatabase::OnPredictorDestroyed() { +void AutocompleteActionPredictorDatabase::OnPredictorDestroyed() { canceled_.Set(); } -void NetworkActionPredictorDatabase::CreateTable() { +void AutocompleteActionPredictorDatabase::CreateTable() { bool success = db_.Execute(base::StringPrintf( "CREATE TABLE %s ( " "id TEXT PRIMARY KEY, " "user_text TEXT, " "url TEXT, " "number_of_hits INTEGER, " - "number_of_misses INTEGER)", kNetworkActionPredictorTableName).c_str()); - DCHECK(success) << "Failed to create " << kNetworkActionPredictorTableName - << " table."; + "number_of_misses INTEGER)", + kAutocompleteActionPredictorTableName).c_str()); + DCHECK(success) << "Failed to create " + << kAutocompleteActionPredictorTableName << " table."; } diff --git a/chrome/browser/autocomplete/network_action_predictor_database.h b/chrome/browser/predictors/autocomplete_action_predictor_database.h index 4ffdf43..38783f2 100644 --- a/chrome/browser/autocomplete/network_action_predictor_database.h +++ b/chrome/browser/predictors/autocomplete_action_predictor_database.h @@ -1,9 +1,9 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_AUTOCOMPLETE_NETWORK_ACTION_PREDICTOR_DATABASE_H_ -#define CHROME_BROWSER_AUTOCOMPLETE_NETWORK_ACTION_PREDICTOR_DATABASE_H_ +#ifndef CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_DATABASE_H_ +#define CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_DATABASE_H_ #pragma once #include <ostream> @@ -20,8 +20,8 @@ class Profile; -// This manages the network action predictor table within the SQLite database -// passed in to the constructor. It expects the following scheme: +// This manages the autocomplete action predictor table within the SQLite +// database passed in to the constructor. It expects the following scheme: // // network_action_predictor // id A unique id. @@ -34,8 +34,8 @@ class Profile; // // Ref-counted as it is created and destroyed on a different thread to the DB // thread that is required for all methods performing database access. -class NetworkActionPredictorDatabase - : public base::RefCountedThreadSafe<NetworkActionPredictorDatabase> { +class AutocompleteActionPredictorDatabase + : public base::RefCountedThreadSafe<AutocompleteActionPredictorDatabase> { public: struct Row { // TODO(dominich): Make this 64-bit integer as an optimization. This @@ -60,7 +60,7 @@ class NetworkActionPredictorDatabase int number_of_misses; }; - explicit NetworkActionPredictorDatabase(Profile* profile); + explicit AutocompleteActionPredictorDatabase(Profile* profile); // Opens the database file from the profile path. Separated from the // constructor to ease construction/destruction of this object on one thread @@ -83,9 +83,9 @@ class NetworkActionPredictorDatabase void OnPredictorDestroyed(); private: - friend class NetworkActionPredictorDatabaseTest; - friend class base::RefCountedThreadSafe<NetworkActionPredictorDatabase>; - virtual ~NetworkActionPredictorDatabase(); + friend class AutocompleteActionPredictorDatabaseTest; + friend class base::RefCountedThreadSafe<AutocompleteActionPredictorDatabase>; + virtual ~AutocompleteActionPredictorDatabase(); void CreateTable(); @@ -95,11 +95,11 @@ class NetworkActionPredictorDatabase FilePath db_path_; sql::Connection db_; - // Set when the NetworkActionPredictor is destroyed so we can cancel any + // Set when the AutocompleteActionPredictor is destroyed so we can cancel any // posted database requests. base::CancellationFlag canceled_; - DISALLOW_COPY_AND_ASSIGN(NetworkActionPredictorDatabase); + DISALLOW_COPY_AND_ASSIGN(AutocompleteActionPredictorDatabase); }; -#endif // CHROME_BROWSER_AUTOCOMPLETE_NETWORK_ACTION_PREDICTOR_DATABASE_H_ +#endif // CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_DATABASE_H_ diff --git a/chrome/browser/autocomplete/network_action_predictor_database_unittest.cc b/chrome/browser/predictors/autocomplete_action_predictor_database_unittest.cc index 0863dc8..5d26efb 100644 --- a/chrome/browser/autocomplete/network_action_predictor_database_unittest.cc +++ b/chrome/browser/predictors/autocomplete_action_predictor_database_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,7 +7,7 @@ #include "base/message_loop.h" #include "base/time.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/autocomplete/network_action_predictor_database.h" +#include "chrome/browser/predictors/autocomplete_action_predictor_database.h" #include "chrome/test/base/testing_profile.h" #include "content/test/test_browser_thread.h" #include "sql/statement.h" @@ -20,16 +20,16 @@ using content::BrowserThread; namespace { -struct NetworkActionPredictorDatabase::Row test_db[] = { - NetworkActionPredictorDatabase::Row( +struct AutocompleteActionPredictorDatabase::Row test_db[] = { + AutocompleteActionPredictorDatabase::Row( "BD85DBA2-8C29-49F9-84AE-48E1E90880DF", ASCIIToUTF16("goog"), GURL("http://www.google.com/"), 1, 0), - NetworkActionPredictorDatabase::Row( + AutocompleteActionPredictorDatabase::Row( "BD85DBA2-8C29-49F9-84AE-48E1E90880E0", ASCIIToUTF16("slash"), GURL("http://slashdot.org/"), 3, 2), - NetworkActionPredictorDatabase::Row( + AutocompleteActionPredictorDatabase::Row( "BD85DBA2-8C29-49F9-84AE-48E1E90880E1", ASCIIToUTF16("news"), GURL("http://slashdot.org/"), 0, 1), @@ -37,10 +37,10 @@ struct NetworkActionPredictorDatabase::Row test_db[] = { } // end namespace -class NetworkActionPredictorDatabaseTest : public testing::Test { +class AutocompleteActionPredictorDatabaseTest : public testing::Test { public: - NetworkActionPredictorDatabaseTest(); - virtual ~NetworkActionPredictorDatabaseTest(); + AutocompleteActionPredictorDatabaseTest(); + virtual ~AutocompleteActionPredictorDatabaseTest(); virtual void SetUp(); virtual void TearDown(); @@ -49,15 +49,15 @@ class NetworkActionPredictorDatabaseTest : public testing::Test { void AddAll(); - bool RowsAreEqual(const NetworkActionPredictorDatabase::Row& lhs, - const NetworkActionPredictorDatabase::Row& rhs) const; + bool RowsAreEqual(const AutocompleteActionPredictorDatabase::Row& lhs, + const AutocompleteActionPredictorDatabase::Row& rhs) const; TestingProfile* profile() { return &profile_; } protected: // Test functions that can be run against this text fixture or - // NetworkActionPredictorDatabaseReopenTest that inherits from this. + // AutocompleteActionPredictorDatabaseReopenTest that inherits from this. void TestAddRow(); void TestGetRow(); void TestUpdateRow(); @@ -67,57 +67,59 @@ class NetworkActionPredictorDatabaseTest : public testing::Test { private: TestingProfile profile_; - scoped_refptr<NetworkActionPredictorDatabase> db_; + scoped_refptr<AutocompleteActionPredictorDatabase> db_; MessageLoop loop_; content::TestBrowserThread db_thread_; }; -class NetworkActionPredictorDatabaseReopenTest - : public NetworkActionPredictorDatabaseTest { +class AutocompleteActionPredictorDatabaseReopenTest + : public AutocompleteActionPredictorDatabaseTest { public: virtual void SetUp() { // By calling SetUp twice, we make sure that the table already exists for // this fixture. - NetworkActionPredictorDatabaseTest::SetUp(); - NetworkActionPredictorDatabaseTest::TearDown(); - NetworkActionPredictorDatabaseTest::SetUp(); + AutocompleteActionPredictorDatabaseTest::SetUp(); + AutocompleteActionPredictorDatabaseTest::TearDown(); + AutocompleteActionPredictorDatabaseTest::SetUp(); } }; -NetworkActionPredictorDatabaseTest::NetworkActionPredictorDatabaseTest() +AutocompleteActionPredictorDatabaseTest:: +AutocompleteActionPredictorDatabaseTest() : loop_(MessageLoop::TYPE_DEFAULT), db_thread_(BrowserThread::DB, &loop_) { } -NetworkActionPredictorDatabaseTest::~NetworkActionPredictorDatabaseTest() { +AutocompleteActionPredictorDatabaseTest:: +~AutocompleteActionPredictorDatabaseTest() { } -void NetworkActionPredictorDatabaseTest::SetUp() { - db_ = new NetworkActionPredictorDatabase(&profile_); +void AutocompleteActionPredictorDatabaseTest::SetUp() { + db_ = new AutocompleteActionPredictorDatabase(&profile_); db_->Initialize(); } -void NetworkActionPredictorDatabaseTest::TearDown() { +void AutocompleteActionPredictorDatabaseTest::TearDown() { db_ = NULL; } -size_t NetworkActionPredictorDatabaseTest::CountRecords() const { +size_t AutocompleteActionPredictorDatabaseTest::CountRecords() const { sql::Statement s(db_->db_.GetUniqueStatement( "SELECT count(*) FROM network_action_predictor")); EXPECT_TRUE(s.Step()); return static_cast<size_t>(s.ColumnInt(0)); } -void NetworkActionPredictorDatabaseTest::AddAll() { +void AutocompleteActionPredictorDatabaseTest::AddAll() { for (size_t i = 0; i < arraysize(test_db); ++i) db_->AddRow(test_db[i]); EXPECT_EQ(arraysize(test_db), CountRecords()); } -bool NetworkActionPredictorDatabaseTest::RowsAreEqual( - const NetworkActionPredictorDatabase::Row& lhs, - const NetworkActionPredictorDatabase::Row& rhs) const { +bool AutocompleteActionPredictorDatabaseTest::RowsAreEqual( + const AutocompleteActionPredictorDatabase::Row& lhs, + const AutocompleteActionPredictorDatabase::Row& rhs) const { return (lhs.id == rhs.id && lhs.user_text == rhs.user_text && lhs.url == rhs.url && @@ -125,7 +127,7 @@ bool NetworkActionPredictorDatabaseTest::RowsAreEqual( lhs.number_of_misses == rhs.number_of_misses); } -void NetworkActionPredictorDatabaseTest::TestAddRow() { +void AutocompleteActionPredictorDatabaseTest::TestAddRow() { EXPECT_EQ(0U, CountRecords()); db_->AddRow(test_db[0]); EXPECT_EQ(1U, CountRecords()); @@ -135,22 +137,22 @@ void NetworkActionPredictorDatabaseTest::TestAddRow() { EXPECT_EQ(3U, CountRecords()); } -void NetworkActionPredictorDatabaseTest::TestGetRow() { +void AutocompleteActionPredictorDatabaseTest::TestGetRow() { db_->AddRow(test_db[0]); - NetworkActionPredictorDatabase::Row row; + AutocompleteActionPredictorDatabase::Row row; db_->GetRow(test_db[0].id, &row); EXPECT_TRUE(RowsAreEqual(test_db[0], row)) << "Expected: Row with id " << test_db[0].id << "\n" << "Got: Row with id " << row.id; } -void NetworkActionPredictorDatabaseTest::TestUpdateRow() { +void AutocompleteActionPredictorDatabaseTest::TestUpdateRow() { AddAll(); - NetworkActionPredictorDatabase::Row row = test_db[1]; + AutocompleteActionPredictorDatabase::Row row = test_db[1]; row.number_of_hits = row.number_of_hits + 1; db_->UpdateRow(row); - NetworkActionPredictorDatabase::Row updated_row; + AutocompleteActionPredictorDatabase::Row updated_row; db_->GetRow(test_db[1].id, &updated_row); EXPECT_TRUE(RowsAreEqual(row, updated_row)) @@ -158,77 +160,77 @@ void NetworkActionPredictorDatabaseTest::TestUpdateRow() { << "Got: Row with id " << updated_row.id; } -void NetworkActionPredictorDatabaseTest::TestDeleteRow() { +void AutocompleteActionPredictorDatabaseTest::TestDeleteRow() { AddAll(); db_->DeleteRow(test_db[2].id); EXPECT_EQ(arraysize(test_db) - 1, CountRecords()); } -void NetworkActionPredictorDatabaseTest::TestDeleteRows() { +void AutocompleteActionPredictorDatabaseTest::TestDeleteRows() { AddAll(); - std::vector<NetworkActionPredictorDatabase::Row::Id> id_list; + std::vector<AutocompleteActionPredictorDatabase::Row::Id> id_list; id_list.push_back(test_db[0].id); id_list.push_back(test_db[2].id); db_->DeleteRows(id_list); EXPECT_EQ(arraysize(test_db) - 2, CountRecords()); - NetworkActionPredictorDatabase::Row row; + AutocompleteActionPredictorDatabase::Row row; db_->GetRow(test_db[1].id, &row); EXPECT_TRUE(RowsAreEqual(test_db[1], row)); } -void NetworkActionPredictorDatabaseTest::TestDeleteAllRows() { +void AutocompleteActionPredictorDatabaseTest::TestDeleteAllRows() { AddAll(); db_->DeleteAllRows(); EXPECT_EQ(0U, CountRecords()); } -// NetworkActionPredictorDatabaseTest tests -TEST_F(NetworkActionPredictorDatabaseTest, AddRow) { +// AutocompleteActionPredictorDatabaseTest tests +TEST_F(AutocompleteActionPredictorDatabaseTest, AddRow) { TestAddRow(); } -TEST_F(NetworkActionPredictorDatabaseTest, GetRow) { +TEST_F(AutocompleteActionPredictorDatabaseTest, GetRow) { TestGetRow(); } -TEST_F(NetworkActionPredictorDatabaseTest, UpdateRow) { +TEST_F(AutocompleteActionPredictorDatabaseTest, UpdateRow) { TestUpdateRow(); } -TEST_F(NetworkActionPredictorDatabaseTest, DeleteRow) { +TEST_F(AutocompleteActionPredictorDatabaseTest, DeleteRow) { TestDeleteRow(); } -TEST_F(NetworkActionPredictorDatabaseTest, DeleteRows) { +TEST_F(AutocompleteActionPredictorDatabaseTest, DeleteRows) { TestDeleteRows(); } -TEST_F(NetworkActionPredictorDatabaseTest, DeleteAllRows) { +TEST_F(AutocompleteActionPredictorDatabaseTest, DeleteAllRows) { TestDeleteAllRows(); } -// NetworkActionPredictorDatabaseReopenTest tests -TEST_F(NetworkActionPredictorDatabaseReopenTest, AddRow) { +// AutocompleteActionPredictorDatabaseReopenTest tests +TEST_F(AutocompleteActionPredictorDatabaseReopenTest, AddRow) { TestAddRow(); } -TEST_F(NetworkActionPredictorDatabaseReopenTest, GetRow) { +TEST_F(AutocompleteActionPredictorDatabaseReopenTest, GetRow) { TestGetRow(); } -TEST_F(NetworkActionPredictorDatabaseReopenTest, UpdateRow) { +TEST_F(AutocompleteActionPredictorDatabaseReopenTest, UpdateRow) { TestUpdateRow(); } -TEST_F(NetworkActionPredictorDatabaseReopenTest, DeleteRow) { +TEST_F(AutocompleteActionPredictorDatabaseReopenTest, DeleteRow) { TestDeleteRow(); } -TEST_F(NetworkActionPredictorDatabaseReopenTest, DeleteRows) { +TEST_F(AutocompleteActionPredictorDatabaseReopenTest, DeleteRows) { TestDeleteRows(); } -TEST_F(NetworkActionPredictorDatabaseReopenTest, DeleteAllRows) { +TEST_F(AutocompleteActionPredictorDatabaseReopenTest, DeleteAllRows) { TestDeleteAllRows(); } diff --git a/chrome/browser/predictors/autocomplete_action_predictor_factory.cc b/chrome/browser/predictors/autocomplete_action_predictor_factory.cc new file mode 100644 index 0000000..9d49228 --- /dev/null +++ b/chrome/browser/predictors/autocomplete_action_predictor_factory.cc @@ -0,0 +1,37 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" + +#include "chrome/browser/predictors/autocomplete_action_predictor.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_dependency_manager.h" + +// static +AutocompleteActionPredictor* AutocompleteActionPredictorFactory::GetForProfile( + Profile* profile) { + return static_cast<AutocompleteActionPredictor*>( + GetInstance()->GetServiceForProfile(profile, true)); +} + +// static +AutocompleteActionPredictorFactory* + AutocompleteActionPredictorFactory::GetInstance() { + return Singleton<AutocompleteActionPredictorFactory>::get(); +} + +AutocompleteActionPredictorFactory::AutocompleteActionPredictorFactory() + : ProfileKeyedServiceFactory("AutocompleteActionPredictor", + ProfileDependencyManager::GetInstance()) { + // TODO(erg): When HistoryService is PKSFized, uncomment this. + // DependsOn(HistoryServiceFactory::GetInstance()); +} + +AutocompleteActionPredictorFactory::~AutocompleteActionPredictorFactory() {} + +ProfileKeyedService* + AutocompleteActionPredictorFactory::BuildServiceInstanceFor( + Profile* profile) const { + return new AutocompleteActionPredictor(profile); +} diff --git a/chrome/browser/predictors/autocomplete_action_predictor_factory.h b/chrome/browser/predictors/autocomplete_action_predictor_factory.h new file mode 100644 index 0000000..d52e4e3 --- /dev/null +++ b/chrome/browser/predictors/autocomplete_action_predictor_factory.h @@ -0,0 +1,37 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_FACTORY_H_ +#define CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_FACTORY_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/memory/singleton.h" +#include "chrome/browser/profiles/profile_keyed_service_factory.h" + +class AutocompleteActionPredictor; + +// Singleton that owns all AutocompleteActionPredictors and associates them with +// Profiles. Listens for the Profile's destruction notification and cleans up +// the associated AutocompleteActionPredictor. +class AutocompleteActionPredictorFactory : public ProfileKeyedServiceFactory { + public: + static AutocompleteActionPredictor* GetForProfile(Profile* profile); + + static AutocompleteActionPredictorFactory* GetInstance(); + + private: + friend struct DefaultSingletonTraits<AutocompleteActionPredictorFactory>; + + AutocompleteActionPredictorFactory(); + virtual ~AutocompleteActionPredictorFactory(); + + // ProfileKeyedServiceFactory: + virtual ProfileKeyedService* BuildServiceInstanceFor( + Profile* profile) const OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(AutocompleteActionPredictorFactory); +}; + +#endif // CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_FACTORY_H_ diff --git a/chrome/browser/autocomplete/network_action_predictor_unittest.cc b/chrome/browser/predictors/autocomplete_action_predictor_unittest.cc index e5ce30b..b2231a9 100644 --- a/chrome/browser/autocomplete/network_action_predictor_unittest.cc +++ b/chrome/browser/predictors/autocomplete_action_predictor_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/autocomplete/network_action_predictor.h" +#include "chrome/browser/predictors/autocomplete_action_predictor.h" #include "base/command_line.h" #include "base/memory/ref_counted.h" @@ -32,56 +32,56 @@ struct TestUrlInfo { string16 user_text; int number_of_hits; int number_of_misses; - NetworkActionPredictor::Action expected_action; + AutocompleteActionPredictor::Action expected_action; } test_url_db[] = { { GURL("http://www.testsite.com/a.html"), ASCIIToUTF16("Test - site - just a test"), 1, ASCIIToUTF16("j"), 5, 0, - NetworkActionPredictor::ACTION_PRERENDER }, + AutocompleteActionPredictor::ACTION_PRERENDER }, { GURL("http://www.testsite.com/b.html"), ASCIIToUTF16("Test - site - just a test"), 1, ASCIIToUTF16("ju"), 3, 0, - NetworkActionPredictor::ACTION_PRERENDER }, + AutocompleteActionPredictor::ACTION_PRERENDER }, { GURL("http://www.testsite.com/c.html"), ASCIIToUTF16("Test - site - just a test"), 5, ASCIIToUTF16("just"), 3, 1, - NetworkActionPredictor::ACTION_PRECONNECT }, + AutocompleteActionPredictor::ACTION_PRECONNECT }, { GURL("http://www.testsite.com/d.html"), ASCIIToUTF16("Test - site - just a test"), 5, ASCIIToUTF16("just"), 3, 0, - NetworkActionPredictor::ACTION_PRERENDER }, + AutocompleteActionPredictor::ACTION_PRERENDER }, { GURL("http://www.testsite.com/e.html"), ASCIIToUTF16("Test - site - just a test"), 8, ASCIIToUTF16("just"), 3, 1, - NetworkActionPredictor::ACTION_PRECONNECT }, + AutocompleteActionPredictor::ACTION_PRECONNECT }, { GURL("http://www.testsite.com/f.html"), ASCIIToUTF16("Test - site - just a test"), 8, ASCIIToUTF16("just"), 3, 0, - NetworkActionPredictor::ACTION_PRERENDER }, + AutocompleteActionPredictor::ACTION_PRERENDER }, { GURL("http://www.testsite.com/g.html"), ASCIIToUTF16("Test - site - just a test"), 12, ASCIIToUTF16(""), 5, 0, - NetworkActionPredictor::ACTION_NONE }, + AutocompleteActionPredictor::ACTION_NONE }, { GURL("http://www.testsite.com/h.html"), ASCIIToUTF16("Test - site - just a test"), 21, ASCIIToUTF16("just a test"), 2, 0, - NetworkActionPredictor::ACTION_NONE }, + AutocompleteActionPredictor::ACTION_NONE }, { GURL("http://www.testsite.com/i.html"), ASCIIToUTF16("Test - site - just a test"), 28, ASCIIToUTF16("just a test"), 2, 0, - NetworkActionPredictor::ACTION_NONE } + AutocompleteActionPredictor::ACTION_NONE } }; } // end namespace -class NetworkActionPredictorTest : public testing::Test { +class AutocompleteActionPredictorTest : public testing::Test { public: - NetworkActionPredictorTest() + AutocompleteActionPredictorTest() : loop_(MessageLoop::TYPE_DEFAULT), ui_thread_(BrowserThread::UI, &loop_), db_thread_(BrowserThread::DB, &loop_), file_thread_(BrowserThread::FILE, &loop_), - predictor_(new NetworkActionPredictor(&profile_)) { + predictor_(new AutocompleteActionPredictor(&profile_)) { } void SetUp() { @@ -103,10 +103,10 @@ class NetworkActionPredictorTest : public testing::Test { } protected: - typedef NetworkActionPredictor::DBCacheKey DBCacheKey; - typedef NetworkActionPredictor::DBCacheValue DBCacheValue; - typedef NetworkActionPredictor::DBCacheMap DBCacheMap; - typedef NetworkActionPredictor::DBIdCacheMap DBIdCacheMap; + typedef AutocompleteActionPredictor::DBCacheKey DBCacheKey; + typedef AutocompleteActionPredictor::DBCacheValue DBCacheValue; + typedef AutocompleteActionPredictor::DBCacheMap DBCacheMap; + typedef AutocompleteActionPredictor::DBIdCacheMap DBIdCacheMap; void AddAllRowsToHistory() { for (size_t i = 0; i < arraysize(test_url_db); ++i) @@ -131,9 +131,9 @@ class NetworkActionPredictorTest : public testing::Test { return url_db->AddURL(row); } - NetworkActionPredictorDatabase::Row CreateRowFromTestUrlInfo( + AutocompleteActionPredictorDatabase::Row CreateRowFromTestUrlInfo( const TestUrlInfo& test_row) const { - NetworkActionPredictorDatabase::Row row; + AutocompleteActionPredictorDatabase::Row row; row.id = guid::GenerateGUID(); row.user_text = test_row.user_text; row.url = test_row.url; @@ -148,18 +148,18 @@ class NetworkActionPredictorTest : public testing::Test { } std::string AddRow(const TestUrlInfo& test_row) { - NetworkActionPredictor::DBCacheKey key = { test_row.user_text, + AutocompleteActionPredictor::DBCacheKey key = { test_row.user_text, test_row.url }; - NetworkActionPredictorDatabase::Row row = + AutocompleteActionPredictorDatabase::Row row = CreateRowFromTestUrlInfo(test_row); predictor_->AddRow(key, row); return row.id; } - void UpdateRow(NetworkActionPredictor::DBCacheKey key, - const NetworkActionPredictorDatabase::Row& row) { - NetworkActionPredictor::DBCacheMap::iterator it = + void UpdateRow(AutocompleteActionPredictor::DBCacheKey key, + const AutocompleteActionPredictorDatabase::Row& row) { + AutocompleteActionPredictor::DBCacheMap::iterator it = db_cache()->find(key); ASSERT_TRUE(it != db_cache()->end()); @@ -175,7 +175,7 @@ class NetworkActionPredictorTest : public testing::Test { } void DeleteOldIdsFromCaches( - std::vector<NetworkActionPredictorDatabase::Row::Id>* id_list) { + std::vector<AutocompleteActionPredictorDatabase::Row::Id>* id_list) { HistoryService* history_service = profile_.GetHistoryService(Profile::EXPLICIT_ACCESS); ASSERT_TRUE(history_service); @@ -186,13 +186,13 @@ class NetworkActionPredictorTest : public testing::Test { predictor_->DeleteOldIdsFromCaches(url_db, id_list); } - NetworkActionPredictor* predictor() { return predictor_.get(); } + AutocompleteActionPredictor* predictor() { return predictor_.get(); } DBCacheMap* db_cache() { return &predictor_->db_cache_; } DBIdCacheMap* db_id_cache() { return &predictor_->db_id_cache_; } static int maximum_days_to_keep_entry() { - return NetworkActionPredictor::kMaximumDaysToKeepEntry; + return AutocompleteActionPredictor::kMaximumDaysToKeepEntry; } private: @@ -201,11 +201,11 @@ class NetworkActionPredictorTest : public testing::Test { content::TestBrowserThread db_thread_; content::TestBrowserThread file_thread_; TestingProfile profile_; - scoped_ptr<NetworkActionPredictor> predictor_; + scoped_ptr<AutocompleteActionPredictor> predictor_; }; -TEST_F(NetworkActionPredictorTest, AddRow) { +TEST_F(AutocompleteActionPredictorTest, AddRow) { // Add a test entry to the predictor. std::string guid = AddRow(test_url_db[0]); @@ -224,7 +224,7 @@ TEST_F(NetworkActionPredictorTest, AddRow) { EXPECT_EQ(guid, id_it->second); } -TEST_F(NetworkActionPredictorTest, UpdateRow) { +TEST_F(AutocompleteActionPredictorTest, UpdateRow) { ASSERT_NO_FATAL_FAILURE(AddAllRows()); EXPECT_EQ(arraysize(test_url_db), db_cache()->size()); @@ -238,7 +238,7 @@ TEST_F(NetworkActionPredictorTest, UpdateRow) { DBIdCacheMap::const_iterator id_it = db_id_cache()->find(key); EXPECT_TRUE(id_it != db_id_cache()->end()); - NetworkActionPredictorDatabase::Row update_row; + AutocompleteActionPredictorDatabase::Row update_row; update_row.id = id_it->second; update_row.user_text = key.user_text; update_row.url = key.url; @@ -260,7 +260,7 @@ TEST_F(NetworkActionPredictorTest, UpdateRow) { EXPECT_EQ(id_it->second, update_id_it->second); } -TEST_F(NetworkActionPredictorTest, DeleteAllRows) { +TEST_F(AutocompleteActionPredictorTest, DeleteAllRows) { ASSERT_NO_FATAL_FAILURE(AddAllRows()); EXPECT_EQ(arraysize(test_url_db), db_cache()->size()); @@ -272,7 +272,7 @@ TEST_F(NetworkActionPredictorTest, DeleteAllRows) { EXPECT_TRUE(db_id_cache()->empty()); } -TEST_F(NetworkActionPredictorTest, DeleteRowsWithURLs) { +TEST_F(AutocompleteActionPredictorTest, DeleteRowsWithURLs) { ASSERT_NO_FATAL_FAILURE(AddAllRows()); EXPECT_EQ(arraysize(test_url_db), db_cache()->size()); @@ -296,9 +296,9 @@ TEST_F(NetworkActionPredictorTest, DeleteRowsWithURLs) { } } -TEST_F(NetworkActionPredictorTest, DeleteOldIdsFromCaches) { - std::vector<NetworkActionPredictorDatabase::Row::Id> expected; - std::vector<NetworkActionPredictorDatabase::Row::Id> all_ids; +TEST_F(AutocompleteActionPredictorTest, DeleteOldIdsFromCaches) { + std::vector<AutocompleteActionPredictorDatabase::Row::Id> expected; + std::vector<AutocompleteActionPredictorDatabase::Row::Id> all_ids; for (size_t i = 0; i < arraysize(test_url_db); ++i) { std::string row_id = AddRow(test_url_db[i]); @@ -313,13 +313,13 @@ TEST_F(NetworkActionPredictorTest, DeleteOldIdsFromCaches) { ASSERT_TRUE(AddRowToHistory(test_url_db[i])); } - std::vector<NetworkActionPredictorDatabase::Row::Id> id_list; + std::vector<AutocompleteActionPredictorDatabase::Row::Id> id_list; DeleteOldIdsFromCaches(&id_list); EXPECT_EQ(expected.size(), id_list.size()); EXPECT_EQ(all_ids.size() - expected.size(), db_cache()->size()); EXPECT_EQ(all_ids.size() - expected.size(), db_id_cache()->size()); - for (std::vector<NetworkActionPredictorDatabase::Row::Id>::iterator it = + for (std::vector<AutocompleteActionPredictorDatabase::Row::Id>::iterator it = all_ids.begin(); it != all_ids.end(); ++it) { bool in_expected = @@ -330,7 +330,7 @@ TEST_F(NetworkActionPredictorTest, DeleteOldIdsFromCaches) { } } -TEST_F(NetworkActionPredictorTest, RecommendActionURL) { +TEST_F(AutocompleteActionPredictorTest, RecommendActionURL) { ASSERT_NO_FATAL_FAILURE(AddAllRows()); AutocompleteMatch match; @@ -344,7 +344,7 @@ TEST_F(NetworkActionPredictorTest, RecommendActionURL) { } } -TEST_F(NetworkActionPredictorTest, RecommendActionSearch) { +TEST_F(AutocompleteActionPredictorTest, RecommendActionSearch) { ASSERT_NO_FATAL_FAILURE(AddAllRows()); AutocompleteMatch match; @@ -352,10 +352,10 @@ TEST_F(NetworkActionPredictorTest, RecommendActionSearch) { for (size_t i = 0; i < arraysize(test_url_db); ++i) { match.destination_url = GURL(test_url_db[i].url); - NetworkActionPredictor::Action expected_action = + AutocompleteActionPredictor::Action expected_action = (test_url_db[i].expected_action == - NetworkActionPredictor::ACTION_PRERENDER) ? - NetworkActionPredictor::ACTION_PRECONNECT : + AutocompleteActionPredictor::ACTION_PRERENDER) ? + AutocompleteActionPredictor::ACTION_PRECONNECT : test_url_db[i].expected_action; EXPECT_EQ(expected_action, predictor()->RecommendAction(test_url_db[i].user_text, match)) diff --git a/chrome/browser/prerender/prerender_field_trial.cc b/chrome/browser/prerender/prerender_field_trial.cc index ab43ff2..0b45277 100644 --- a/chrome/browser/prerender/prerender_field_trial.cc +++ b/chrome/browser/prerender/prerender_field_trial.cc @@ -8,8 +8,8 @@ #include "base/logging.h" #include "base/metrics/field_trial.h" #include "base/metrics/histogram.h" -#include "chrome/browser/autocomplete/network_action_predictor.h" #include "chrome/browser/metrics/metrics_service.h" +#include "chrome/browser/predictors/autocomplete_action_predictor.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prerender/prerender_manager.h" #include "chrome/browser/profiles/profile.h" @@ -217,9 +217,9 @@ void ConfigureOmniboxPrerender() { kEightProbability); const int group = weighting_trial->group(); if (group == kOmniboxWeightFourGroup) - NetworkActionPredictor::set_hit_weight(4.0); + AutocompleteActionPredictor::set_hit_weight(4.0); else if (group == kOmniboxWeightEightGroup) - NetworkActionPredictor::set_hit_weight(8.0); + AutocompleteActionPredictor::set_hit_weight(8.0); } bool IsOmniboxEnabled(Profile* profile) { diff --git a/chrome/browser/prerender/prerender_histograms.cc b/chrome/browser/prerender/prerender_histograms.cc index 01eb772..773a6ed 100644 --- a/chrome/browser/prerender/prerender_histograms.cc +++ b/chrome/browser/prerender/prerender_histograms.cc @@ -9,7 +9,7 @@ #include "base/metrics/field_trial.h" #include "base/metrics/histogram.h" #include "base/stringprintf.h" -#include "chrome/browser/autocomplete/network_action_predictor.h" +#include "chrome/browser/predictors/autocomplete_action_predictor.h" #include "chrome/browser/prerender/prerender_field_trial.h" #include "chrome/browser/prerender/prerender_manager.h" #include "chrome/browser/prerender/prerender_util.h" @@ -48,7 +48,7 @@ std::string GetHistogramName(Origin origin, uint8 experiment_id, case ORIGIN_OMNIBOX: return ComposeHistogramName( StringPrintf("omnibox_%.1f", - NetworkActionPredictor::get_hit_weight()).c_str(), + AutocompleteActionPredictor::get_hit_weight()).c_str(), name); case ORIGIN_LINK_REL_PRERENDER: return ComposeHistogramName("web", name); @@ -153,7 +153,7 @@ void PrerenderHistograms::RecordPrerenderStarted(Origin origin) const { if (OriginIsOmnibox(origin)) { UMA_HISTOGRAM_COUNTS( StringPrintf("Prerender.OmniboxPrerenderCount_%.1f%s", - NetworkActionPredictor::get_hit_weight(), + AutocompleteActionPredictor::get_hit_weight(), PrerenderManager::GetModeString()).c_str(), 1); } @@ -163,7 +163,7 @@ void PrerenderHistograms::RecordUsedPrerender(Origin origin) const { if (OriginIsOmnibox(origin)) { UMA_HISTOGRAM_COUNTS( StringPrintf("Prerender.OmniboxNavigationsUsedPrerenderCount_%.1f%s", - NetworkActionPredictor::get_hit_weight(), + AutocompleteActionPredictor::get_hit_weight(), PrerenderManager::GetModeString()).c_str(), 1); } diff --git a/chrome/browser/profiles/profile_dependency_manager.cc b/chrome/browser/profiles/profile_dependency_manager.cc index c02d540..383f8ea 100644 --- a/chrome/browser/profiles/profile_dependency_manager.cc +++ b/chrome/browser/profiles/profile_dependency_manager.cc @@ -8,7 +8,6 @@ #include <deque> #include <iterator> -#include "chrome/browser/autocomplete/network_action_predictor_factory.h" #include "chrome/browser/autofill/personal_data_manager_factory.h" #include "chrome/browser/background/background_contents_service_factory.h" #include "chrome/browser/content_settings/cookie_settings.h" @@ -17,6 +16,7 @@ #include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/password_manager/password_store_factory.h" #include "chrome/browser/plugin_prefs_factory.h" +#include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" #include "chrome/browser/prerender/prerender_manager_factory.h" #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h" #include "chrome/browser/profiles/profile.h" @@ -172,6 +172,7 @@ void ProfileDependencyManager::AssertFactoriesBuilt() { if (built_factories_) return; + AutocompleteActionPredictorFactory::GetInstance(); ChromeURLDataManagerFactory::GetInstance(); CookieSettings::Factory::GetInstance(); DownloadServiceFactory::GetInstance(); @@ -180,7 +181,6 @@ void ProfileDependencyManager::AssertFactoriesBuilt() { GesturePrefsObserverFactoryAura::GetInstance(); #endif GlobalErrorServiceFactory::GetInstance(); - NetworkActionPredictorFactory::GetInstance(); NTPResourceCacheFactory::GetInstance(); PasswordStoreFactory::GetInstance(); PersonalDataManagerFactory::GetInstance(); diff --git a/chrome/browser/ui/webui/network_action_predictor/OWNERS b/chrome/browser/resources/predictors/OWNERS index 95b3792..95b3792 100644 --- a/chrome/browser/ui/webui/network_action_predictor/OWNERS +++ b/chrome/browser/resources/predictors/OWNERS diff --git a/chrome/browser/resources/network_action_predictor/network_action_predictor.css b/chrome/browser/resources/predictors/autocomplete_action_predictor.css index 5fc7f5a..5fc7f5a 100644 --- a/chrome/browser/resources/network_action_predictor/network_action_predictor.css +++ b/chrome/browser/resources/predictors/autocomplete_action_predictor.css diff --git a/chrome/browser/resources/network_action_predictor/network_action_predictor.html b/chrome/browser/resources/predictors/autocomplete_action_predictor.html index 735be08..a4beade7 100644 --- a/chrome/browser/resources/network_action_predictor/network_action_predictor.html +++ b/chrome/browser/resources/predictors/autocomplete_action_predictor.html @@ -2,10 +2,10 @@ <html> <head> <meta charset="utf-8"> - <title>Network Action Predictor</title> - <link rel="stylesheet" href="network_action_predictor.css"> + <title>Autocomplete Action Predictor</title> + <link rel="stylesheet" href="autocomplete_action_predictor.css"> <script src="chrome://resources/js/util.js"></script> - <script src="chrome://network-action-predictor/network_action_predictor.js"> + <script src="chrome://predictors/autocomplete_action_predictor.js"> </script> </head> <body> @@ -31,7 +31,7 @@ </table> </div> <div id="disabledMode" hidden> - <p>Network Action Predictor is disabled.</p> + <p>Autocomplete Action Predictor is disabled.</p> </div> <script src="chrome://resources/js/jstemplate_compiled.js"></script> </body> diff --git a/chrome/browser/resources/network_action_predictor/network_action_predictor.js b/chrome/browser/resources/predictors/autocomplete_action_predictor.js index 8a6fe77..5a722e8 100644 --- a/chrome/browser/resources/network_action_predictor/network_action_predictor.js +++ b/chrome/browser/resources/predictors/autocomplete_action_predictor.js @@ -5,16 +5,16 @@ /** * Requests the database from the backend. */ -function requestNetworkActionPredictorDb() { +function requestAutocompleteActionPredictorDb() { console.debug('Requesting NAP DB'); - chrome.send('requestNetworkActionPredictorDb'); + chrome.send('requestAutocompleteActionPredictorDb'); } /** * Callback from backend with the database contents. Sets up some globals and * calls to create the UI. - * @param {Dictionary} database Information about NetworkActionPredictor + * @param {Dictionary} database Information about AutocompleteActionPredictor * including the database as a flattened list, a boolean indicating if the * system is enabled and the current hit weight. */ @@ -32,7 +32,7 @@ function updateDatabaseTable(database) { /** * Updates the table from the database. - * @param {Dictionary} database Information about NetworkActionPredictor + * @param {Dictionary} database Information about AutocompleteActionPredictor * including the database as a flattened list, a boolean indicating if the * system is enabled and the current hit weight. */ @@ -77,6 +77,5 @@ function updateDatabaseView(database) { $('countBanner').textContent += ' Hit Weight: ' + database.hit_weight; } -document.addEventListener('DOMContentLoaded', requestNetworkActionPredictorDb); - - +document.addEventListener('DOMContentLoaded', + requestAutocompleteActionPredictorDb); diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc index 1a46458..23e432a 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc @@ -34,7 +34,7 @@ #include "chrome/browser/ui/webui/inspect_ui.h" #include "chrome/browser/ui/webui/media/media_internals_ui.h" #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h" -#include "chrome/browser/ui/webui/network_action_predictor/network_action_predictor_ui.h" +#include "chrome/browser/ui/webui/predictors/autocomplete_action_predictor_ui.h" #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" #include "chrome/browser/ui/webui/omnibox/omnibox_ui.h" #include "chrome/browser/ui/webui/options2/options_ui2.h" @@ -191,10 +191,10 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, return &NewWebUI<MediaInternalsUI>; if (url.host() == chrome::kChromeUINetInternalsHost) return &NewWebUI<NetInternalsUI>; - if (url.host() == chrome::kChromeUINetworkActionPredictorHost) - return &NewWebUI<NetworkActionPredictorUI>; if (url.host() == chrome::kChromeUIOmniboxHost) return &NewWebUI<OmniboxUI>; + if (url.host() == chrome::kChromeUIPredictorsHost) + return &NewWebUI<AutocompleteActionPredictorUI>; if (url.host() == chrome::kChromeUIProfilerHost) return &NewWebUI<ProfilerUI>; if (url.host() == chrome::kChromeUIQuotaInternalsHost) diff --git a/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.cc b/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.cc deleted file mode 100644 index e4c9a19..0000000 --- a/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.cc +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.h" - -#include "base/bind.h" -#include "base/values.h" -#include "chrome/browser/autocomplete/network_action_predictor.h" -#include "chrome/browser/autocomplete/network_action_predictor_factory.h" -#include "chrome/browser/profiles/profile.h" -#include "content/public/browser/web_ui.h" - -NetworkActionPredictorDOMHandler::NetworkActionPredictorDOMHandler( - Profile* profile) { - network_action_predictor_ = - NetworkActionPredictorFactory::GetForProfile(profile); -} - -NetworkActionPredictorDOMHandler::~NetworkActionPredictorDOMHandler() { } - -void NetworkActionPredictorDOMHandler::RegisterMessages() { - web_ui()->RegisterMessageCallback("requestNetworkActionPredictorDb", - base::Bind( - &NetworkActionPredictorDOMHandler::RequestNetworkActionPredictorDb, - base::Unretained(this))); -} - -void NetworkActionPredictorDOMHandler::RequestNetworkActionPredictorDb( - const base::ListValue* args) { - const bool enabled = (network_action_predictor_ != NULL); - base::DictionaryValue dict; - dict.SetBoolean("enabled", enabled); - - if (enabled) { - base::ListValue* db = new base::ListValue(); - for (NetworkActionPredictor::DBCacheMap::const_iterator it = - network_action_predictor_->db_cache_.begin(); - it != network_action_predictor_->db_cache_.end(); - ++it) { - base::DictionaryValue* entry = new base::DictionaryValue(); - entry->SetString("user_text", it->first.user_text); - entry->SetString("url", it->first.url.spec()); - entry->SetInteger("hit_count", it->second.number_of_hits); - entry->SetInteger("miss_count", it->second.number_of_misses); - entry->SetDouble("confidence", - network_action_predictor_->CalculateConfidenceForDbEntry(it)); - db->Append(entry); - } - dict.Set("db", db); - dict.SetDouble("hit_weight", NetworkActionPredictor::get_hit_weight()); - } - - web_ui()->CallJavascriptFunction("updateDatabaseTable", dict); -} diff --git a/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.h b/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.h deleted file mode 100644 index 2c9fc2a..0000000 --- a/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_WEBUI_NETWORK_ACTION_PREDICTOR_NETWORK_ACTION_PREDICTOR_DOM_HANDLER_H_ -#define CHROME_BROWSER_UI_WEBUI_NETWORK_ACTION_PREDICTOR_NETWORK_ACTION_PREDICTOR_DOM_HANDLER_H_ -#pragma once - -#include "base/compiler_specific.h" -#include "content/public/browser/web_ui_message_handler.h" - -namespace base { -class ListValue; -} - -class NetworkActionPredictor; -class Profile; - -// The handler for Javascript messages for about:network-action-predictor. -class NetworkActionPredictorDOMHandler : public content::WebUIMessageHandler { - public: - explicit NetworkActionPredictorDOMHandler(Profile* profile); - virtual ~NetworkActionPredictorDOMHandler(); - - // WebUIMessageHandler implementation. - virtual void RegisterMessages() OVERRIDE; - - private: - // Synchronously fetches the database from NetworkActionPredictor and calls - // into JS with the resulting DictionaryValue. - void RequestNetworkActionPredictorDb(const base::ListValue* args); - - NetworkActionPredictor* network_action_predictor_; - - DISALLOW_COPY_AND_ASSIGN(NetworkActionPredictorDOMHandler); -}; - -#endif // CHROME_BROWSER_UI_WEBUI_NETWORK_ACTION_PREDICTOR_NETWORK_ACTION_PREDICTOR_DOM_HANDLER_H_ diff --git a/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_ui.cc b/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_ui.cc deleted file mode 100644 index 7fe40b4..0000000 --- a/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_ui.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/webui/network_action_predictor/network_action_predictor_ui.h" - -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/webui/chrome_url_data_manager.h" -#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" -#include "chrome/browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.h" -#include "chrome/common/url_constants.h" -#include "content/public/browser/web_contents.h" -#include "content/public/browser/web_ui.h" -#include "grit/browser_resources.h" - -namespace { - -ChromeWebUIDataSource* CreateNetworkActionPredictorUIHTMLSource() { - ChromeWebUIDataSource* source = - new ChromeWebUIDataSource(chrome::kChromeUINetworkActionPredictorHost); - source->add_resource_path("network_action_predictor.js", - IDR_NETWORK_ACTION_PREDICTOR_JS); - source->set_default_resource(IDR_NETWORK_ACTION_PREDICTOR_HTML); - return source; -} - -} // namespace - -NetworkActionPredictorUI::NetworkActionPredictorUI(content::WebUI* web_ui) - : WebUIController(web_ui) { - Profile* profile = Profile::FromWebUI(web_ui); - web_ui->AddMessageHandler(new NetworkActionPredictorDOMHandler(profile)); - ChromeURLDataManager::AddDataSource(profile, - CreateNetworkActionPredictorUIHTMLSource()); -} diff --git a/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_ui.h b/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_ui.h deleted file mode 100644 index c047542..0000000 --- a/chrome/browser/ui/webui/network_action_predictor/network_action_predictor_ui.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_WEBUI_NETWORK_ACTION_PREDICTOR_NETWORK_ACTION_PREDICTOR_UI_H_ -#define CHROME_BROWSER_UI_WEBUI_NETWORK_ACTION_PREDICTOR_NETWORK_ACTION_PREDICTOR_UI_H_ -#pragma once - -#include "content/public/browser/web_ui_controller.h" - -class NetworkActionPredictorUI : public content::WebUIController { - public: - explicit NetworkActionPredictorUI(content::WebUI* web_ui); - - private: - DISALLOW_COPY_AND_ASSIGN(NetworkActionPredictorUI); -}; - -#endif // CHROME_BROWSER_UI_WEBUI_NETWORK_ACTION_PREDICTOR_NETWORK_ACTION_PREDICTOR_UI_H_ diff --git a/chrome/browser/ui/webui/predictors/OWNERS b/chrome/browser/ui/webui/predictors/OWNERS new file mode 100644 index 0000000..95b3792 --- /dev/null +++ b/chrome/browser/ui/webui/predictors/OWNERS @@ -0,0 +1 @@ +dominich@chromium.org diff --git a/chrome/browser/ui/webui/predictors/autocomplete_action_predictor_dom_handler.cc b/chrome/browser/ui/webui/predictors/autocomplete_action_predictor_dom_handler.cc new file mode 100644 index 0000000..a774303 --- /dev/null +++ b/chrome/browser/ui/webui/predictors/autocomplete_action_predictor_dom_handler.cc @@ -0,0 +1,60 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/webui/predictors/autocomplete_action_predictor_dom_handler.h" + +#include "base/bind.h" +#include "base/values.h" +#include "chrome/browser/predictors/autocomplete_action_predictor.h" +#include "chrome/browser/predictors/autocomplete_action_predictor_factory.h" +#include "chrome/browser/profiles/profile.h" +#include "content/public/browser/web_ui.h" + +AutocompleteActionPredictorDOMHandler::AutocompleteActionPredictorDOMHandler( + Profile* profile) { + autocomplete_action_predictor_ = + AutocompleteActionPredictorFactory::GetForProfile(profile); +} + +AutocompleteActionPredictorDOMHandler::~AutocompleteActionPredictorDOMHandler() +{ +} + +void AutocompleteActionPredictorDOMHandler::RegisterMessages() { + web_ui()->RegisterMessageCallback("requestAutocompleteActionPredictorDb", + base::Bind( + &AutocompleteActionPredictorDOMHandler:: + RequestAutocompleteActionPredictorDb, + base::Unretained(this))); +} + +void + AutocompleteActionPredictorDOMHandler::RequestAutocompleteActionPredictorDb( + const base::ListValue* args) { + const bool enabled = (autocomplete_action_predictor_ != NULL); + base::DictionaryValue dict; + dict.SetBoolean("enabled", enabled); + + if (enabled) { + base::ListValue* db = new base::ListValue(); + for (AutocompleteActionPredictor::DBCacheMap::const_iterator it = + autocomplete_action_predictor_->db_cache_.begin(); + it != autocomplete_action_predictor_->db_cache_.end(); + ++it) { + base::DictionaryValue* entry = new base::DictionaryValue(); + entry->SetString("user_text", it->first.user_text); + entry->SetString("url", it->first.url.spec()); + entry->SetInteger("hit_count", it->second.number_of_hits); + entry->SetInteger("miss_count", it->second.number_of_misses); + entry->SetDouble("confidence", + autocomplete_action_predictor_->CalculateConfidenceForDbEntry(it)); + db->Append(entry); + } + dict.Set("db", db); + dict.SetDouble("hit_weight", + AutocompleteActionPredictor::get_hit_weight()); + } + + web_ui()->CallJavascriptFunction("updateDatabaseTable", dict); +} diff --git a/chrome/browser/ui/webui/predictors/autocomplete_action_predictor_dom_handler.h b/chrome/browser/ui/webui/predictors/autocomplete_action_predictor_dom_handler.h new file mode 100644 index 0000000..f27ca9e --- /dev/null +++ b/chrome/browser/ui/webui/predictors/autocomplete_action_predictor_dom_handler.h @@ -0,0 +1,39 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_WEBUI_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_DOM_HANDLER_H_ +#define CHROME_BROWSER_UI_WEBUI_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_DOM_HANDLER_H_ +#pragma once + +#include "base/compiler_specific.h" +#include "content/public/browser/web_ui_message_handler.h" + +namespace base { +class ListValue; +} + +class AutocompleteActionPredictor; +class Profile; + +// The handler for Javascript messages for about:predictors. +class AutocompleteActionPredictorDOMHandler + : public content::WebUIMessageHandler { + public: + explicit AutocompleteActionPredictorDOMHandler(Profile* profile); + virtual ~AutocompleteActionPredictorDOMHandler(); + + // WebUIMessageHandler implementation. + virtual void RegisterMessages() OVERRIDE; + + private: + // Synchronously fetches the database from AutocompleteActionPredictor and + // calls into JS with the resulting DictionaryValue. + void RequestAutocompleteActionPredictorDb(const base::ListValue* args); + + AutocompleteActionPredictor* autocomplete_action_predictor_; + + DISALLOW_COPY_AND_ASSIGN(AutocompleteActionPredictorDOMHandler); +}; + +#endif // CHROME_BROWSER_UI_WEBUI_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_DOM_HANDLER_H_ diff --git a/chrome/browser/ui/webui/predictors/autocomplete_action_predictor_ui.cc b/chrome/browser/ui/webui/predictors/autocomplete_action_predictor_ui.cc new file mode 100644 index 0000000..65b05fd --- /dev/null +++ b/chrome/browser/ui/webui/predictors/autocomplete_action_predictor_ui.cc @@ -0,0 +1,35 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/webui/predictors/autocomplete_action_predictor_ui.h" + +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/webui/chrome_url_data_manager.h" +#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" +#include "chrome/browser/ui/webui/predictors/autocomplete_action_predictor_dom_handler.h" +#include "chrome/common/url_constants.h" +#include "content/public/browser/web_contents.h" +#include "content/public/browser/web_ui.h" +#include "grit/browser_resources.h" + +namespace { + +ChromeWebUIDataSource* CreateAutocompleteActionPredictorUIHTMLSource() { + ChromeWebUIDataSource* source = + new ChromeWebUIDataSource(chrome::kChromeUIPredictorsHost); + source->add_resource_path("autocomplete_action_predictor.js", + IDR_AUTOCOMPLETE_ACTION_PREDICTOR_JS); + source->set_default_resource(IDR_AUTOCOMPLETE_ACTION_PREDICTOR_HTML); + return source; +} + +} // namespace + +AutocompleteActionPredictorUI::AutocompleteActionPredictorUI( + content::WebUI* web_ui) : WebUIController(web_ui) { + Profile* profile = Profile::FromWebUI(web_ui); + web_ui->AddMessageHandler(new AutocompleteActionPredictorDOMHandler(profile)); + ChromeURLDataManager::AddDataSource(profile, + CreateAutocompleteActionPredictorUIHTMLSource()); +} diff --git a/chrome/browser/ui/webui/predictors/autocomplete_action_predictor_ui.h b/chrome/browser/ui/webui/predictors/autocomplete_action_predictor_ui.h new file mode 100644 index 0000000..ddd3217e --- /dev/null +++ b/chrome/browser/ui/webui/predictors/autocomplete_action_predictor_ui.h @@ -0,0 +1,19 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_WEBUI_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_UI_H_ +#define CHROME_BROWSER_UI_WEBUI_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_UI_H_ +#pragma once + +#include "content/public/browser/web_ui_controller.h" + +class AutocompleteActionPredictorUI : public content::WebUIController { + public: + explicit AutocompleteActionPredictorUI(content::WebUI* web_ui); + + private: + DISALLOW_COPY_AND_ASSIGN(AutocompleteActionPredictorUI); +}; + +#endif // CHROME_BROWSER_UI_WEBUI_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_UI_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 5617415..41d7cbd 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -131,12 +131,6 @@ 'browser/autocomplete/history_url_provider.h', 'browser/autocomplete/keyword_provider.cc', 'browser/autocomplete/keyword_provider.h', - 'browser/autocomplete/network_action_predictor.cc', - 'browser/autocomplete/network_action_predictor.h', - 'browser/autocomplete/network_action_predictor_database.cc', - 'browser/autocomplete/network_action_predictor_database.h', - 'browser/autocomplete/network_action_predictor_factory.cc', - 'browser/autocomplete/network_action_predictor_factory.h', 'browser/autocomplete/search_provider.cc', 'browser/autocomplete/search_provider.h', 'browser/autocomplete/shortcuts_provider.cc', @@ -1625,6 +1619,12 @@ 'browser/policy/user_policy_disk_cache.h', 'browser/policy/user_policy_token_cache.cc', 'browser/policy/user_policy_token_cache.h', + 'browser/predictors/autocomplete_action_predictor.cc', + 'browser/predictors/autocomplete_action_predictor.h', + 'browser/predictors/autocomplete_action_predictor_database.cc', + 'browser/predictors/autocomplete_action_predictor_database.h', + 'browser/predictors/autocomplete_action_predictor_factory.cc', + 'browser/predictors/autocomplete_action_predictor_factory.h', 'browser/preferences_mac.cc', 'browser/preferences_mac.h', 'browser/prefs/browser_prefs.cc', @@ -3696,10 +3696,6 @@ 'browser/ui/webui/metrics_handler.h', 'browser/ui/webui/net_internals/net_internals_ui.cc', 'browser/ui/webui/net_internals/net_internals_ui.h', - 'browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.cc', - 'browser/ui/webui/network_action_predictor/network_action_predictor_dom_handler.h', - 'browser/ui/webui/network_action_predictor/network_action_predictor_ui.cc', - 'browser/ui/webui/network_action_predictor/network_action_predictor_ui.h', 'browser/ui/webui/ntp/app_launcher_handler.cc', 'browser/ui/webui/ntp/app_launcher_handler.h', 'browser/ui/webui/ntp/favicon_webui_handler.cc', @@ -3824,6 +3820,10 @@ 'browser/ui/webui/plugins_ui.h', 'browser/ui/webui/policy_ui.cc', 'browser/ui/webui/policy_ui.h', + 'browser/ui/webui/predictors/autocomplete_action_predictor_dom_handler.cc', + 'browser/ui/webui/predictors/autocomplete_action_predictor_dom_handler.h', + 'browser/ui/webui/predictors/autocomplete_action_predictor_ui.cc', + 'browser/ui/webui/predictors/autocomplete_action_predictor_ui.h', 'browser/ui/webui/print_preview/print_preview_data_source.cc', 'browser/ui/webui/print_preview/print_preview_data_source.h', 'browser/ui/webui/print_preview/print_preview_handler.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index f7ec452..671401d 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1142,8 +1142,6 @@ 'browser/autocomplete/history_quick_provider_unittest.cc', 'browser/autocomplete/history_url_provider_unittest.cc', 'browser/autocomplete/keyword_provider_unittest.cc', - 'browser/autocomplete/network_action_predictor_unittest.cc', - 'browser/autocomplete/network_action_predictor_database_unittest.cc', 'browser/autocomplete/search_provider_unittest.cc', 'browser/autocomplete/shortcuts_provider_unittest.cc', 'browser/autocomplete_history_manager_unittest.cc', @@ -1542,6 +1540,8 @@ 'browser/policy/testing_policy_url_fetcher_factory.h', 'browser/policy/url_blacklist_manager_unittest.cc', 'browser/policy/user_policy_cache_unittest.cc', + 'browser/predictors/autocomplete_action_predictor_database_unittest.cc', + 'browser/predictors/autocomplete_action_predictor_unittest.cc', 'browser/preferences_mock_mac.cc', 'browser/preferences_mock_mac.h', 'browser/prefs/command_line_pref_store_unittest.cc', diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc index e9c4f97..19ebc08 100644 --- a/chrome/common/url_constants.cc +++ b/chrome/common/url_constants.cc @@ -155,11 +155,11 @@ const char kChromeUIMediaInternalsHost[] = "media-internals"; const char kChromeUIMemoryHost[] = "memory"; const char kChromeUIMemoryRedirectHost[] = "memory-redirect"; const char kChromeUINetInternalsHost[] = "net-internals"; -const char kChromeUINetworkActionPredictorHost[] = "network-action-predictor"; const char kChromeUINewTabHost[] = "newtab"; const char kChromeUIOmniboxHost[] = "omnibox"; const char kChromeUIPluginsHost[] = "plugins"; const char kChromeUIPolicyHost[] = "policy"; +const char kChromeUIPredictorsHost[] = "predictors"; const char kChromeUIPrintHost[] = "print"; const char kChromeUIProfilerHost[] = "profiler"; const char kChromeUIQuotaInternalsHost[] = "quota-internals"; diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h index fe73d77..493c1c6 100644 --- a/chrome/common/url_constants.h +++ b/chrome/common/url_constants.h @@ -151,11 +151,11 @@ extern const char kChromeUIMediaInternalsHost[]; extern const char kChromeUIMemoryHost[]; extern const char kChromeUIMemoryRedirectHost[]; extern const char kChromeUINetInternalsHost[]; -extern const char kChromeUINetworkActionPredictorHost[]; extern const char kChromeUINewTabHost[]; extern const char kChromeUIOmniboxHost[]; extern const char kChromeUIPluginsHost[]; extern const char kChromeUIPolicyHost[]; +extern const char kChromeUIPredictorsHost[]; extern const char kChromeUIPrintHost[]; extern const char kChromeUIProfilerHost[]; extern const char kChromeUIQuotaInternalsHost[]; |