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 91936db382f3c15ae9de9bcf0ce4eb82689a2827..47967e9e3393c4fba63a7aba75fb1e031d4d2fa3 100644 |
--- a/chrome/browser/search_engines/template_url_service.cc |
+++ b/chrome/browser/search_engines/template_url_service.cc |
@@ -31,7 +31,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 "components/rappor/rappor_service.h" |
#include "components/search_engines/search_engines_pref_names.h" |
#include "components/search_engines/template_url.h" |
@@ -220,7 +220,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), |
@@ -235,8 +234,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_); |
} |
@@ -538,7 +537,7 @@ TemplateURL* TemplateURLService::GetTemplateURLForHost( |
} |
bool TemplateURLService::Add(TemplateURL* template_url) { |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
if (!AddNoNotify(template_url, true)) |
return false; |
NotifyObservers(); |
@@ -570,7 +569,7 @@ void TemplateURLService::AddExtensionControlledTURL( |
DCHECK(!FindTemplateURLForExtension(info->extension_id, info->type)); |
template_url->extension_info_.swap(info); |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
if (AddNoNotify(template_url, true)) { |
if (template_url->extension_info_->wants_to_be_default_engine) |
UpdateExtensionDefaultSearchEngine(); |
@@ -594,7 +593,7 @@ 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::BatchModeScoper scoper(web_data_service_.get()); |
RemoveNoNotify(url); |
UpdateExtensionDefaultSearchEngine(); |
NotifyObservers(); |
@@ -615,7 +614,7 @@ void TemplateURLService::RemoveAutoGeneratedForOriginBetween( |
base::Time created_before) { |
GURL o(origin.GetOrigin()); |
bool should_notify = false; |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::BatchModeScoper 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() || |
@@ -670,8 +669,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, |
@@ -753,7 +752,7 @@ void TemplateURLService::RepairPrepopulatedSearchEngines() { |
ActionsFromPrepopulateData actions(CreateActionsFromCurrentPrepopulateData( |
&prepopulated_urls, template_urls_, default_search_provider_)); |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
// Remove items. |
for (std::vector<TemplateURL*>::iterator i = actions.removed_engines.begin(); |
@@ -808,11 +807,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(); |
} |
@@ -826,7 +827,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. |
@@ -836,7 +837,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; |
} |
@@ -845,7 +846,7 @@ void TemplateURLService::OnWebDataServiceRequestDone( |
int new_resource_keyword_version = 0; |
GetSearchProvidersUsingKeywordResult( |
*result, |
- service_.get(), |
+ web_data_service_.get(), |
prefs_, |
&template_urls, |
(default_search_provider_source_ == DefaultSearchManager::FROM_USER) ? |
@@ -854,7 +855,7 @@ void TemplateURLService::OnWebDataServiceRequestDone( |
&new_resource_keyword_version, |
&pre_sync_deletes_); |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
PatchMissingSyncGUIDs(&template_urls); |
SetTemplateURLs(&template_urls); |
@@ -870,7 +871,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( |
@@ -919,13 +920,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( |
@@ -967,7 +968,7 @@ syncer::SyncError TemplateURLService::ProcessSyncChanges( |
base::AutoReset<DefaultSearchChangeOrigin> change_origin(&dsp_change_origin_, |
DSP_CHANGE_SYNC_UNINTENTIONAL); |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
syncer::SyncChangeList new_changes; |
syncer::SyncError error; |
@@ -1126,7 +1127,7 @@ syncer::SyncMergeResult TemplateURLService::MergeDataAndStartSyncing( |
GetAllSyncData(syncer::SEARCH_ENGINES)); |
SyncDataMap sync_data_map = CreateGUIDToSyncDataMap(initial_sync_data); |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::BatchModeScoper 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(); |
@@ -1459,7 +1460,7 @@ void TemplateURLService::Init(const Initializer* initializers, |
ChangeToLoadedState(); |
// Add specific initializers, if any. |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
for (int i(0); i < num_initializers; ++i) { |
DCHECK(initializers[i].keyword); |
DCHECK(initializers[i].url); |
@@ -1698,8 +1699,8 @@ bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl, |
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( |
@@ -1802,7 +1803,7 @@ void TemplateURLService::AddTabToSearchVisit(const TemplateURL& t_url) { |
} |
void TemplateURLService::GoogleBaseURLChanged() { |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::BatchModeScoper scoper(web_data_service_.get()); |
bool something_changed = false; |
for (TemplateURLVector::iterator i(template_urls_.begin()); |
i != template_urls_.end(); ++i) { |
@@ -1899,7 +1900,7 @@ bool TemplateURLService::ApplyDefaultSearchChangeNoMetrics( |
// a change. |
TemplateURL* previous_default_search_engine = default_search_provider_; |
- WebDataService::KeywordBatchModeScoper keyword_scoper(service_.get()); |
+ KeywordWebDataService::BatchModeScoper 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 |
@@ -2029,8 +2030,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_. |
@@ -2056,8 +2057,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, |
@@ -2139,8 +2140,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; |
@@ -2332,8 +2333,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()); |
} |
} |
} |