Index: chrome/browser/search_engines/template_url_service.cc |
diff --git a/chrome/browser/search_engines/template_url_service.cc b/chrome/browser/search_engines/template_url_service.cc |
index 6b8967fe4082bbe02dafcf5f215beb9aaced7f20..4556af2fb647c28b26c8392bed400bd3b78b2bde 100644 |
--- a/chrome/browser/search_engines/template_url_service.cc |
+++ b/chrome/browser/search_engines/template_url_service.cc |
@@ -33,7 +33,7 @@ |
#include "chrome/browser/search_engines/template_url_service_observer.h" |
#include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
#include "chrome/browser/search_engines/util.h" |
-#include "chrome/browser/webdata/web_data_service.h" |
+#include "chrome/browser/webdata/web_data_service_factory.h" |
#include "chrome/common/env_vars.h" |
#include "components/search_engines/search_engines_pref_names.h" |
#include "components/search_engines/template_url.h" |
@@ -243,7 +243,6 @@ TemplateURLService::TemplateURLService(const Initializer* initializers, |
loaded_(false), |
load_failed_(false), |
load_handle_(0), |
- service_(NULL), |
default_search_provider_(NULL), |
next_id_(kInvalidTemplateURLID + 1), |
time_provider_(&base::Time::Now), |
@@ -258,8 +257,8 @@ TemplateURLService::TemplateURLService(const Initializer* initializers, |
} |
TemplateURLService::~TemplateURLService() { |
- // |service_| should be deleted during Shutdown(). |
- DCHECK(!service_); |
+ // |web_data_service_| should be deleted during Shutdown(). |
+ DCHECK(!web_data_service_); |
STLDeleteElements(&template_urls_); |
} |
@@ -561,7 +560,8 @@ TemplateURL* TemplateURLService::GetTemplateURLForHost( |
} |
bool TemplateURLService::Add(TemplateURL* template_url) { |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
Peter Kasting
2014/06/30 22:50:01
Nit: If you rename KeywordBatchModeScoper to Batch
hashimoto
2014/07/01 01:06:50
Sounds good.
Done.
Also renamed KeywordWebDataSer
|
+ web_data_service_.get()); |
if (!AddNoNotify(template_url, true)) |
return false; |
NotifyObservers(); |
@@ -593,7 +593,8 @@ void TemplateURLService::AddExtensionControlledTURL( |
DCHECK(!FindTemplateURLForExtension(info->extension_id, info->type)); |
template_url->extension_info_.swap(info); |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
+ web_data_service_.get()); |
if (AddNoNotify(template_url, true)) { |
if (template_url->extension_info_->wants_to_be_default_engine) |
UpdateExtensionDefaultSearchEngine(); |
@@ -617,7 +618,8 @@ void TemplateURLService::RemoveExtensionControlledTURL( |
// UpdateExtensionDefaultSearchEngine will cause it to be reset. |
if (default_search_provider_ == url) |
default_search_provider_ = NULL; |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
+ web_data_service_.get()); |
RemoveNoNotify(url); |
UpdateExtensionDefaultSearchEngine(); |
NotifyObservers(); |
@@ -638,7 +640,8 @@ void TemplateURLService::RemoveAutoGeneratedForOriginBetween( |
base::Time created_before) { |
GURL o(origin.GetOrigin()); |
bool should_notify = false; |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
+ web_data_service_.get()); |
for (size_t i = 0; i < template_urls_.size();) { |
if (template_urls_[i]->date_created() >= created_after && |
(created_before.is_null() || |
@@ -693,8 +696,8 @@ void TemplateURLService::IncrementUsageCount(TemplateURL* url) { |
return; |
++url->data_.usage_count; |
- if (service_) |
- service_->UpdateKeyword(url->data()); |
+ if (web_data_service_) |
+ web_data_service_->UpdateKeyword(url->data()); |
} |
void TemplateURLService::ResetTemplateURL(TemplateURL* url, |
@@ -776,7 +779,8 @@ void TemplateURLService::RepairPrepopulatedSearchEngines() { |
ActionsFromPrepopulateData actions(CreateActionsFromCurrentPrepopulateData( |
&prepopulated_urls, template_urls_, default_search_provider_)); |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
+ web_data_service_.get()); |
// Remove items. |
for (std::vector<TemplateURL*>::iterator i = actions.removed_engines.begin(); |
@@ -832,11 +836,13 @@ void TemplateURLService::Load() { |
if (loaded_ || load_handle_) |
return; |
- if (!service_) |
- service_ = WebDataService::FromBrowserContext(profile_); |
+ if (!web_data_service_) { |
+ web_data_service_ = WebDataServiceFactory::GetKeywordWebDataForProfile( |
+ profile_, Profile::EXPLICIT_ACCESS); |
+ } |
- if (service_) |
- load_handle_ = service_->GetKeywords(this); |
+ if (web_data_service_) |
+ load_handle_ = web_data_service_->GetKeywords(this); |
else |
ChangeToLoadedState(); |
} |
@@ -850,7 +856,7 @@ scoped_ptr<TemplateURLService::Subscription> |
} |
void TemplateURLService::OnWebDataServiceRequestDone( |
- WebDataService::Handle h, |
+ KeywordWebDataService::Handle h, |
const WDTypedResult* result) { |
// Reset the load_handle so that we don't try and cancel the load in |
// the destructor. |
@@ -860,7 +866,7 @@ void TemplateURLService::OnWebDataServiceRequestDone( |
// Results are null if the database went away or (most likely) wasn't |
// loaded. |
load_failed_ = true; |
- service_ = NULL; |
+ web_data_service_ = NULL; |
ChangeToLoadedState(); |
return; |
} |
@@ -869,7 +875,7 @@ void TemplateURLService::OnWebDataServiceRequestDone( |
int new_resource_keyword_version = 0; |
GetSearchProvidersUsingKeywordResult( |
*result, |
- service_.get(), |
+ web_data_service_.get(), |
GetPrefs(), |
&template_urls, |
(default_search_provider_source_ == DefaultSearchManager::FROM_USER) ? |
@@ -878,7 +884,8 @@ void TemplateURLService::OnWebDataServiceRequestDone( |
&new_resource_keyword_version, |
&pre_sync_deletes_); |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
+ web_data_service_.get()); |
PatchMissingSyncGUIDs(&template_urls); |
SetTemplateURLs(&template_urls); |
@@ -894,7 +901,7 @@ void TemplateURLService::OnWebDataServiceRequestDone( |
visits_to_add_.clear(); |
if (new_resource_keyword_version) |
- service_->SetBuiltinKeywordVersion(new_resource_keyword_version); |
+ web_data_service_->SetBuiltinKeywordVersion(new_resource_keyword_version); |
if (default_search_provider_) { |
UMA_HISTOGRAM_ENUMERATION( |
@@ -937,13 +944,13 @@ void TemplateURLService::Observe(int type, |
void TemplateURLService::Shutdown() { |
// This check has to be done at Shutdown() instead of in the dtor to ensure |
- // that no clients of WebDataService are holding ptrs to it after the first |
- // phase of the KeyedService Shutdown() process. |
+ // that no clients of KeywordWebDataService are holding ptrs to it after the |
+ // first phase of the KeyedService Shutdown() process. |
if (load_handle_) { |
- DCHECK(service_.get()); |
- service_->CancelRequest(load_handle_); |
+ DCHECK(web_data_service_.get()); |
+ web_data_service_->CancelRequest(load_handle_); |
} |
- service_ = NULL; |
+ web_data_service_ = NULL; |
} |
syncer::SyncDataList TemplateURLService::GetAllSyncData( |
@@ -985,7 +992,8 @@ syncer::SyncError TemplateURLService::ProcessSyncChanges( |
base::AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_, |
DSP_CHANGE_SYNC_UNINTENTIONAL); |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
+ web_data_service_.get()); |
syncer::SyncChangeList new_changes; |
syncer::SyncError error; |
@@ -1143,7 +1151,8 @@ syncer::SyncMergeResult TemplateURLService::MergeDataAndStartSyncing( |
GetAllSyncData(syncer::SEARCH_ENGINES)); |
SyncDataMap sync_data_map = CreateGUIDToSyncDataMap(initial_sync_data); |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
+ web_data_service_.get()); |
merge_result.set_num_items_before_association(local_data_map.size()); |
for (SyncDataMap::const_iterator iter = sync_data_map.begin(); |
@@ -1475,7 +1484,8 @@ void TemplateURLService::Init(const Initializer* initializers, |
ChangeToLoadedState(); |
// Add specific initializers, if any. |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
+ web_data_service_.get()); |
for (int i(0); i < num_initializers; ++i) { |
DCHECK(initializers[i].keyword); |
DCHECK(initializers[i].url); |
@@ -1723,8 +1733,8 @@ bool TemplateURLService::UpdateNoNotify( |
if (!existing_turl->sync_guid().empty()) |
guid_to_template_map_[existing_turl->sync_guid()] = existing_turl; |
- if (service_) |
- service_->UpdateKeyword(existing_turl->data()); |
+ if (web_data_service_) |
+ web_data_service_->UpdateKeyword(existing_turl->data()); |
// Inform sync of the update. |
ProcessTemplateURLChange( |
@@ -1831,7 +1841,8 @@ void TemplateURLService::AddTabToSearchVisit(const TemplateURL& t_url) { |
} |
void TemplateURLService::GoogleBaseURLChanged(const GURL& old_base_url) { |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
+ web_data_service_.get()); |
bool something_changed = false; |
for (TemplateURLVector::iterator i(template_urls_.begin()); |
i != template_urls_.end(); ++i) { |
@@ -1930,7 +1941,8 @@ bool TemplateURLService::ApplyDefaultSearchChangeNoMetrics( |
// a change. |
TemplateURL* previous_default_search_engine = default_search_provider_; |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::KeywordBatchModeScoper keyword_scoper( |
+ web_data_service_.get()); |
if (default_search_provider_source_ == DefaultSearchManager::FROM_POLICY || |
source == DefaultSearchManager::FROM_POLICY) { |
// We do this both to remove any no-longer-applicable policy-defined DSE as |
@@ -2065,8 +2077,8 @@ bool TemplateURLService::AddNoNotify(TemplateURL* template_url, |
if (newly_adding && |
(template_url->GetType() != |
TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) { |
- if (service_) |
- service_->AddKeyword(template_url->data()); |
+ if (web_data_service_) |
+ web_data_service_->AddKeyword(template_url->data()); |
// Inform sync of the addition. Note that this will assign a GUID to |
// template_url and add it to the guid_to_template_map_. |
@@ -2092,8 +2104,8 @@ void TemplateURLService::RemoveNoNotify(TemplateURL* template_url) { |
template_urls_.erase(i); |
if (template_url->GetType() != TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) { |
- if (service_) |
- service_->RemoveKeyword(template_url->id()); |
+ if (web_data_service_) |
+ web_data_service_->RemoveKeyword(template_url->id()); |
// Inform sync of the deletion. |
ProcessTemplateURLChange(FROM_HERE, |
@@ -2177,8 +2189,8 @@ void TemplateURLService::UpdateProvidersCreatedByPolicy( |
RemoveFromMaps(template_url); |
i = template_urls->erase(i); |
- if (service_) |
- service_->RemoveKeyword(template_url->id()); |
+ if (web_data_service_) |
+ web_data_service_->RemoveKeyword(template_url->id()); |
delete template_url; |
} else { |
++i; |
@@ -2371,8 +2383,8 @@ void TemplateURLService::PatchMissingSyncGUIDs( |
(template_url->GetType() != |
TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION)) { |
template_url->data_.sync_guid = base::GenerateGUID(); |
- if (service_) |
- service_->UpdateKeyword(template_url->data()); |
+ if (web_data_service_) |
+ web_data_service_->UpdateKeyword(template_url->data()); |
} |
} |
} |