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/extension_setting_data_type_controller.h" |
| 6 |
| 7 #include "base/metrics/histogram.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/extension_settings_ui_wrapper.h" |
| 10 #include "chrome/browser/profiles/profile.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 "content/browser/browser_thread.h" |
| 15 |
| 16 namespace browser_sync { |
| 17 |
| 18 ExtensionSettingDataTypeController::ExtensionSettingDataTypeController( |
| 19 ProfileSyncFactory* profile_sync_factory, |
| 20 Profile* profile, |
| 21 ProfileSyncService* profile_sync_service) |
| 22 : NonFrontendDataTypeController(profile_sync_factory, profile), |
| 23 extension_settings_ui_wrapper_( |
| 24 profile->GetExtensionService()->extension_settings()), |
| 25 profile_sync_service_(profile_sync_service), |
| 26 extension_settings_(NULL) { |
| 27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 28 } |
| 29 |
| 30 ExtensionSettingDataTypeController::~ExtensionSettingDataTypeController() {} |
| 31 |
| 32 syncable::ModelType ExtensionSettingDataTypeController::type() const { |
| 33 return syncable::EXTENSION_SETTINGS; |
| 34 } |
| 35 |
| 36 browser_sync::ModelSafeGroup |
| 37 ExtensionSettingDataTypeController::model_safe_group() const { |
| 38 return browser_sync::GROUP_FILE; |
| 39 } |
| 40 |
| 41 bool ExtensionSettingDataTypeController::StartModels() { |
| 42 return true; |
| 43 } |
| 44 |
| 45 bool ExtensionSettingDataTypeController::StartAssociationAsync() { |
| 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 47 DCHECK_EQ(state(), ASSOCIATING); |
| 48 extension_settings_ui_wrapper_->RunWithSettings( |
| 49 base::Bind( |
| 50 &ExtensionSettingDataTypeController:: |
| 51 StartAssociationWithExtensionSettings, |
| 52 this)); |
| 53 return true; |
| 54 } |
| 55 |
| 56 void ExtensionSettingDataTypeController::StartAssociationWithExtensionSettings( |
| 57 ExtensionSettings* extension_settings) { |
| 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 59 extension_settings_ = extension_settings; |
| 60 // Calls CreateSyncComponents, which expects extension_settings_ to be |
| 61 // non-NULL. |
| 62 StartAssociation(); |
| 63 } |
| 64 |
| 65 void ExtensionSettingDataTypeController::CreateSyncComponents() { |
| 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 67 DCHECK_EQ(state(), ASSOCIATING); |
| 68 DCHECK(extension_settings_); |
| 69 ProfileSyncFactory::SyncComponents sync_components = |
| 70 profile_sync_factory()->CreateExtensionSettingSyncComponents( |
| 71 extension_settings_, profile_sync_service_, this); |
| 72 set_model_associator(sync_components.model_associator); |
| 73 set_change_processor(sync_components.change_processor); |
| 74 } |
| 75 |
| 76 bool ExtensionSettingDataTypeController::StopAssociationAsync() { |
| 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 78 DCHECK_EQ(state(), STOPPING); |
| 79 if (!BrowserThread::PostTask( |
| 80 BrowserThread::FILE, |
| 81 FROM_HERE, |
| 82 base::Bind( |
| 83 &ExtensionSettingDataTypeController::StopAssociation, |
| 84 this))) { |
| 85 NOTREACHED(); |
| 86 } |
| 87 return true; |
| 88 } |
| 89 |
| 90 void ExtensionSettingDataTypeController::RecordUnrecoverableError( |
| 91 const tracked_objects::Location& from_here, |
| 92 const std::string& message) { |
| 93 UMA_HISTOGRAM_COUNTS("Sync.ExtensionSettingRunFailures", 1); |
| 94 } |
| 95 |
| 96 void ExtensionSettingDataTypeController::RecordAssociationTime( |
| 97 base::TimeDelta time) { |
| 98 UMA_HISTOGRAM_TIMES("Sync.ExtensionSettingAssociationTime", time); |
| 99 } |
| 100 |
| 101 void ExtensionSettingDataTypeController::RecordStartFailure( |
| 102 StartResult result) { |
| 103 UMA_HISTOGRAM_ENUMERATION( |
| 104 "Sync.ExtensionSettingStartFailures", result, MAX_START_RESULT); |
| 105 } |
| 106 |
| 107 } // namespace browser_sync |
OLD | NEW |