Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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. | |
| 4 | |
| 5 #include "chrome/browser/sync/glue/search_engine_data_type_controller.h" | |
| 6 | |
| 7 #include "base/metrics/histogram.h" | |
| 8 #include "chrome/browser/profiles/profile.h" | |
| 9 #include "chrome/browser/search_engines/template_url_service.h" | |
| 10 #include "chrome/browser/search_engines/template_url_service_factory.h" | |
| 11 #include "chrome/browser/sync/api/syncable_service.h" | |
| 12 #include "chrome/browser/sync/glue/generic_change_processor.h" | |
| 13 #include "chrome/browser/sync/profile_sync_factory.h" | |
| 14 #include "chrome/browser/sync/profile_sync_service.h" | |
| 15 #include "chrome/common/chrome_notification_types.h" | |
| 16 #include "content/common/notification_source.h" | |
| 17 | |
| 18 namespace browser_sync { | |
| 19 | |
| 20 SearchEngineDataTypeController::SearchEngineDataTypeController( | |
| 21 ProfileSyncFactory* profile_sync_factory, | |
| 22 Profile* profile, | |
| 23 ProfileSyncService* sync_service) | |
| 24 : FrontendDataTypeController(profile_sync_factory, | |
| 25 profile, | |
| 26 sync_service) { | |
| 27 } | |
| 28 | |
| 29 SearchEngineDataTypeController::~SearchEngineDataTypeController() { | |
| 30 } | |
| 31 | |
| 32 syncable::ModelType SearchEngineDataTypeController::type() const { | |
| 33 return syncable::SEARCH_ENGINES; | |
| 34 } | |
| 35 | |
| 36 void SearchEngineDataTypeController::Observe( | |
| 37 int type, | |
| 38 const NotificationSource& source, | |
| 39 const NotificationDetails& details) { | |
| 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 41 DCHECK_EQ(chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, type); | |
| 42 registrar_.RemoveAll(); | |
| 43 DCHECK_EQ(state_, MODEL_STARTING); | |
| 44 state_ = ASSOCIATING; | |
| 45 Associate(); | |
| 46 } | |
| 47 | |
| 48 // We want to start the bookmark model before we begin associating. | |
|
Nicolas Zea
2011/08/19 18:32:39
Rewrite comment
SteveT
2011/08/22 18:33:42
Done.
| |
| 49 bool SearchEngineDataTypeController::StartModels() { | |
| 50 // If the TemplateURLService is loaded, continue with association. | |
| 51 TemplateURLService* turl_service = | |
| 52 TemplateURLServiceFactory::GetForProfile(profile_); | |
| 53 if (turl_service && turl_service->loaded()) { | |
| 54 return true; // Continue to Associate(). | |
| 55 } | |
| 56 | |
| 57 // Add an observer and continue when the bookmarks model is loaded. | |
|
Nicolas Zea
2011/08/19 18:32:39
here too
SteveT
2011/08/22 18:33:42
Done.
| |
| 58 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, | |
| 59 Source<Profile>(sync_service_->profile())); | |
| 60 return false; // Don't continue Start. | |
| 61 } | |
| 62 | |
| 63 // Cleanup for our extra registrar usage. | |
| 64 void SearchEngineDataTypeController::CleanUpState() { | |
| 65 registrar_.RemoveAll(); | |
| 66 } | |
| 67 | |
| 68 void SearchEngineDataTypeController::CreateSyncComponents() { | |
| 69 ProfileSyncFactory::SyncComponents sync_components = | |
| 70 profile_sync_factory_->CreateSearchEngineSyncComponents(sync_service_, | |
| 71 this); | |
| 72 set_model_associator(sync_components.model_associator); | |
| 73 set_change_processor(sync_components.change_processor); | |
| 74 } | |
| 75 | |
| 76 void SearchEngineDataTypeController::RecordUnrecoverableError( | |
| 77 const tracked_objects::Location& from_here, | |
| 78 const std::string& message) { | |
| 79 UMA_HISTOGRAM_COUNTS("Sync.SearchEngineRunFailures", 1); | |
|
Nicolas Zea
2011/08/19 18:32:39
note: you're going to have to add these to histogr
SteveT
2011/08/22 18:33:42
Noted.
| |
| 80 } | |
| 81 | |
| 82 void SearchEngineDataTypeController::RecordAssociationTime( | |
| 83 base::TimeDelta time) { | |
| 84 UMA_HISTOGRAM_TIMES("Sync.SearchEngineAssociationTime", time); | |
| 85 } | |
| 86 | |
| 87 void SearchEngineDataTypeController::RecordStartFailure(StartResult result) { | |
| 88 UMA_HISTOGRAM_ENUMERATION("Sync.SearchEngineStartFailures", | |
| 89 result, | |
| 90 MAX_START_RESULT); | |
| 91 } | |
| 92 | |
| 93 } // namespace browser_sync | |
| OLD | NEW |