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/profile_sync_components_factory.h"
11 #include "chrome/browser/sync/profile_sync_service.h"
12 #include "sync/api/syncable_service.h"
14 using content::BrowserThread;
16 namespace browser_sync {
18 SearchEngineDataTypeController::SearchEngineDataTypeController(
19 ProfileSyncComponentsFactory* profile_sync_factory,
21 ProfileSyncService* sync_service)
22 : UIDataTypeController(syncer::SEARCH_ENGINES,
28 SearchEngineDataTypeController::~SearchEngineDataTypeController() {}
30 // We want to start the TemplateURLService before we begin associating.
31 bool SearchEngineDataTypeController::StartModels() {
32 // If the TemplateURLService is loaded, continue with association. We force
33 // a load here to prevent the rest of Sync from waiting on
34 // TemplateURLService's lazy load.
35 TemplateURLService* turl_service =
36 TemplateURLServiceFactory::GetForProfile(profile_);
39 if (turl_service->loaded()) {
40 return true; // Continue to Associate().
43 // Register a callback and continue when the TemplateURLService is loaded.
44 template_url_subscription_ = turl_service->RegisterOnLoadedCallback(
45 base::Bind(&SearchEngineDataTypeController::OnTemplateURLServiceLoaded,
48 return false; // Don't continue Start.
51 void SearchEngineDataTypeController::OnTemplateURLServiceLoaded() {
52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
53 DCHECK_EQ(state_, MODEL_STARTING);
54 template_url_subscription_.reset();
58 } // namespace browser_sync