| Index: chrome/browser/search_engines/search_provider_install_data.cc
|
| diff --git a/chrome/browser/search_engines/search_provider_install_data.cc b/chrome/browser/search_engines/search_provider_install_data.cc
|
| index 64b14fdebde2dde07e9148a52bbde1b54d027017..95d5a77a0d7b84e77a60bdb67d3c6f70f2d2f22a 100644
|
| --- a/chrome/browser/search_engines/search_provider_install_data.cc
|
| +++ b/chrome/browser/search_engines/search_provider_install_data.cc
|
| @@ -10,6 +10,7 @@
|
|
|
| #include "base/basictypes.h"
|
| #include "base/bind.h"
|
| +#include "base/bind_helpers.h"
|
| #include "base/logging.h"
|
| #include "base/memory/ref_counted.h"
|
| #include "base/sequenced_task_runner_helpers.h"
|
| @@ -20,6 +21,7 @@
|
| #include "chrome/browser/search_engines/search_terms_data.h"
|
| #include "chrome/browser/search_engines/template_url.h"
|
| #include "chrome/browser/search_engines/template_url_service.h"
|
| +#include "chrome/browser/search_engines/template_url_service_factory.h"
|
| #include "chrome/browser/search_engines/util.h"
|
| #include "chrome/browser/webdata/web_data_service.h"
|
| #include "content/public/browser/browser_thread.h"
|
| @@ -36,6 +38,30 @@ typedef SearchHostToURLsMap::TemplateURLSet TemplateURLSet;
|
|
|
| namespace {
|
|
|
| +void LoadDataOnUIThread(TemplateURLService* template_url_service,
|
| + const base::Callback<void(ScopedVector<TemplateURL>,
|
| + TemplateURL*)>& callback) {
|
| + ScopedVector<TemplateURL> template_url_copies;
|
| + TemplateURL* default_provider_copy = NULL;
|
| + TemplateURLService::TemplateURLVector original_template_urls =
|
| + template_url_service->GetTemplateURLs();
|
| + TemplateURL* original_default_provider =
|
| + template_url_service->GetDefaultSearchProvider();
|
| + for (TemplateURLService::TemplateURLVector::const_iterator it =
|
| + original_template_urls.begin();
|
| + it != original_template_urls.end();
|
| + ++it) {
|
| + template_url_copies.push_back(new TemplateURL(NULL, (*it)->data()));
|
| + if (*it == original_default_provider)
|
| + default_provider_copy = template_url_copies.back();
|
| + }
|
| + BrowserThread::PostTask(BrowserThread::IO,
|
| + FROM_HERE,
|
| + base::Bind(callback,
|
| + base::Passed(template_url_copies.Pass()),
|
| + base::Unretained(default_provider_copy)));
|
| +}
|
| +
|
| // Implementation of SearchTermsData that may be used on the I/O thread.
|
| class IOThreadSearchTermsData : public SearchTermsData {
|
| public:
|
| @@ -165,9 +191,9 @@ static bool IsSameOrigin(const GURL& requested_origin,
|
| } // namespace
|
|
|
| SearchProviderInstallData::SearchProviderInstallData(
|
| - Profile* profile, content::RenderProcessHost* host)
|
| - : web_service_(WebDataService::FromBrowserContext(profile)),
|
| - load_handle_(0),
|
| + Profile* profile,
|
| + content::RenderProcessHost* host)
|
| + : template_url_service_(TemplateURLServiceFactory::GetForProfile(profile)),
|
| google_base_url_(UIThreadSearchTermsData(profile).GoogleBaseURLValue()),
|
| weak_factory_(this) {
|
| // GoogleURLObserver is responsible for killing itself when
|
| @@ -179,11 +205,6 @@ SearchProviderInstallData::SearchProviderInstallData(
|
|
|
| SearchProviderInstallData::~SearchProviderInstallData() {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| -
|
| - if (load_handle_) {
|
| - DCHECK(web_service_.get());
|
| - web_service_->CancelRequest(load_handle_);
|
| - }
|
| }
|
|
|
| void SearchProviderInstallData::CallWhenLoaded(const base::Closure& closure) {
|
| @@ -194,14 +215,24 @@ void SearchProviderInstallData::CallWhenLoaded(const base::Closure& closure) {
|
| return;
|
| }
|
|
|
| + bool do_load = closure_queue_.empty();
|
| closure_queue_.push_back(closure);
|
| - if (load_handle_)
|
| +
|
| + // If the queue wasn't empty, there was already a load in progress.
|
| + if (!do_load)
|
| return;
|
|
|
| - if (web_service_.get())
|
| - load_handle_ = web_service_->GetKeywords(this);
|
| - else
|
| + if (template_url_service_) {
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI,
|
| + FROM_HERE,
|
| + base::Bind(&LoadDataOnUIThread,
|
| + template_url_service_,
|
| + base::Bind(&SearchProviderInstallData::OnTemplateURLsLoaded,
|
| + weak_factory_.GetWeakPtr())));
|
| + } else {
|
| OnLoadFailed();
|
| + }
|
| }
|
|
|
| SearchProviderInstallData::State SearchProviderInstallData::GetInstallState(
|
| @@ -233,35 +264,17 @@ void SearchProviderInstallData::OnGoogleURLChange(
|
| google_base_url_ = google_base_url;
|
| }
|
|
|
| -void SearchProviderInstallData::OnWebDataServiceRequestDone(
|
| - WebDataService::Handle h,
|
| - const WDTypedResult* result) {
|
| +void SearchProviderInstallData::OnTemplateURLsLoaded(
|
| + ScopedVector<TemplateURL> template_urls,
|
| + TemplateURL* default_provider) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
|
|
| - // Reset the load_handle so that we don't try and cancel the load in
|
| - // the destructor.
|
| - load_handle_ = 0;
|
| -
|
| - if (!result) {
|
| - // Results are null if the database went away or (most likely) wasn't
|
| - // loaded.
|
| - OnLoadFailed();
|
| - return;
|
| - }
|
| + template_urls_ = template_urls.Pass();
|
|
|
| - TemplateURL* default_search_provider = NULL;
|
| - int new_resource_keyword_version = 0;
|
| - std::vector<TemplateURL*> extracted_template_urls;
|
| - GetSearchProvidersUsingKeywordResult(*result, NULL, NULL,
|
| - &extracted_template_urls, &default_search_provider,
|
| - &new_resource_keyword_version, NULL);
|
| - template_urls_.get().insert(template_urls_.get().begin(),
|
| - extracted_template_urls.begin(),
|
| - extracted_template_urls.end());
|
| IOThreadSearchTermsData search_terms_data(google_base_url_);
|
| provider_map_.reset(new SearchHostToURLsMap());
|
| provider_map_->Init(template_urls_.get(), search_terms_data);
|
| - SetDefault(default_search_provider);
|
| + SetDefault(default_provider);
|
| NotifyLoaded();
|
| }
|
|
|
|
|