1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/sync/glue/search_engine_data_type_controller.h"
7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/search_engines/template_url_service_factory.h"
10 #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"
11 #include "chrome/browser/sync/profile_sync_service.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "sync/api/syncable_service.h"
15 using content::BrowserThread;
17 namespace browser_sync {
19 SearchEngineDataTypeController::SearchEngineDataTypeController(
20 SyncApiComponentFactory* sync_factory,
22 const DisableTypeCallback& disable_callback)
23 : UIDataTypeController(
24 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
25 base::Bind(&ChromeReportUnrecoverableError),
27 syncer::SEARCH_ENGINES,
32 SearchEngineDataTypeController::~SearchEngineDataTypeController() {}
34 // We want to start the TemplateURLService before we begin associating.
35 bool SearchEngineDataTypeController::StartModels() {
36 // If the TemplateURLService is loaded, continue with association. We force
37 // a load here to prevent the rest of Sync from waiting on
38 // TemplateURLService's lazy load.
39 TemplateURLService* turl_service =
40 TemplateURLServiceFactory::GetForProfile(profile_);
43 if (turl_service->loaded()) {
44 return true; // Continue to Associate().
47 // Register a callback and continue when the TemplateURLService is loaded.
48 template_url_subscription_ = turl_service->RegisterOnLoadedCallback(
49 base::Bind(&SearchEngineDataTypeController::OnTemplateURLServiceLoaded,
52 return false; // Don't continue Start.
55 void SearchEngineDataTypeController::OnTemplateURLServiceLoaded() {
56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
57 DCHECK_EQ(state_, MODEL_STARTING);
58 template_url_subscription_.reset();
62 } // namespace browser_sync