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/extensions/extension_settings_ui_wrapper.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/file_path.h" |
| 9 #include "chrome/browser/extensions/extension_settings.h" |
| 10 #include "content/browser/browser_thread.h" |
| 11 |
| 12 ExtensionSettingsUIWrapper::ExtensionSettingsUIWrapper( |
| 13 const FilePath& base_path) |
| 14 : core_(new ExtensionSettingsUIWrapper::Core(base_path)) { |
| 15 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 16 } |
| 17 |
| 18 void ExtensionSettingsUIWrapper::RunWithStorage( |
| 19 const std::string& extension_id, const StorageCallback& callback) { |
| 20 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 21 BrowserThread::PostTask( |
| 22 BrowserThread::FILE, |
| 23 FROM_HERE, |
| 24 base::Bind( |
| 25 &ExtensionSettingsUIWrapper::Core::RunWithStorageOnFileThread, |
| 26 core_.get(), |
| 27 extension_id, |
| 28 callback)); |
| 29 } |
| 30 |
| 31 SyncableService* ExtensionSettingsUIWrapper::GetSyncableService() { |
| 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 33 return core_.get(); |
| 34 } |
| 35 |
| 36 ExtensionSettingsUIWrapper::~ExtensionSettingsUIWrapper() { |
| 37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 38 } |
| 39 |
| 40 ExtensionSettingsUIWrapper::Core::Core(const FilePath& base_path) |
| 41 : extension_settings_(NULL) { |
| 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 43 BrowserThread::PostTask( |
| 44 BrowserThread::FILE, |
| 45 FROM_HERE, |
| 46 base::Bind( |
| 47 &ExtensionSettingsUIWrapper::Core::InitOnFileThread, |
| 48 this, |
| 49 base_path)); |
| 50 } |
| 51 |
| 52 void ExtensionSettingsUIWrapper::Core::RunWithStorageOnFileThread( |
| 53 const std::string& extension_id, const StorageCallback& callback) { |
| 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 55 DCHECK(extension_settings_); |
| 56 callback.Run(extension_settings_->GetStorage(extension_id)); |
| 57 } |
| 58 |
| 59 SyncDataList ExtensionSettingsUIWrapper::Core::GetAllSyncData( |
| 60 syncable::ModelType type) const { |
| 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 62 DCHECK(extension_settings_); |
| 63 return extension_settings_->GetAllSyncData(type); |
| 64 } |
| 65 |
| 66 SyncError ExtensionSettingsUIWrapper::Core::MergeDataAndStartSyncing( |
| 67 syncable::ModelType type, |
| 68 const SyncDataList& initial_sync_data, |
| 69 SyncChangeProcessor* sync_processor) { |
| 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 71 DCHECK(extension_settings_); |
| 72 return extension_settings_->MergeDataAndStartSyncing( |
| 73 type, initial_sync_data, sync_processor); |
| 74 } |
| 75 |
| 76 SyncError ExtensionSettingsUIWrapper::Core::ProcessSyncChanges( |
| 77 const tracked_objects::Location& from_here, |
| 78 const SyncChangeList& change_list) { |
| 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 80 DCHECK(extension_settings_); |
| 81 return extension_settings_->ProcessSyncChanges(from_here, change_list); |
| 82 } |
| 83 |
| 84 void ExtensionSettingsUIWrapper::Core::StopSyncing(syncable::ModelType type) { |
| 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 86 DCHECK(extension_settings_); |
| 87 extension_settings_->StopSyncing(type); |
| 88 } |
| 89 |
| 90 ExtensionSettingsUIWrapper::Core::~Core() { |
| 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 92 BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 93 BrowserThread::DeleteSoon( |
| 94 BrowserThread::FILE, FROM_HERE, extension_settings_); |
| 95 } |
| 96 |
| 97 void ExtensionSettingsUIWrapper::Core::InitOnFileThread( |
| 98 const FilePath& base_path) { |
| 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 100 DCHECK(!extension_settings_); |
| 101 extension_settings_ = new ExtensionSettings(base_path); |
| 102 } |
OLD | NEW |