Chromium Code Reviews| Index: chrome/browser/extensions/extension_settings_ui_wrapper.h |
| diff --git a/chrome/browser/extensions/extension_settings_ui_wrapper.h b/chrome/browser/extensions/extension_settings_ui_wrapper.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..aa54d1a4ffb74efb8032805c6b9fa91027ded6ae |
| --- /dev/null |
| +++ b/chrome/browser/extensions/extension_settings_ui_wrapper.h |
| @@ -0,0 +1,84 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_UI_WRAPPER_H_ |
| +#define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_UI_WRAPPER_H_ |
| +#pragma once |
| + |
| +#include "base/file_path.h" |
|
akalin
2011/09/20 14:53:11
forward-declare FilePath instead
not at google - send to devlin
2011/09/21 00:20:14
Done.
|
| +#include "base/memory/ref_counted.h" |
| +#include "base/callback.h" |
| +#include "chrome/browser/extensions/extension_settings.h" |
|
akalin
2011/09/20 14:53:11
forward-declare extension settings
not at google - send to devlin
2011/09/21 00:20:14
Done.
|
| +#include "chrome/browser/sync/api/syncable_service.h" |
| + |
| +// Wrapper for an ExtensionSettings object for dealing with thread ownership. |
| +// This class lives on the UI thread while ExtensionSettings object live on |
| +// the FILE thread. |
| +class ExtensionSettingsUIWrapper { |
| + public: |
| + explicit ExtensionSettingsUIWrapper(const FilePath& base_path); |
| + |
| + typedef base::Callback<void(ExtensionSettingsStorage*)> Callback; |
|
akalin
2011/09/20 14:53:11
StorageCallback would be a better name
not at google - send to devlin
2011/09/21 00:20:14
Done.
|
| + |
| + // Runs |callback| on the FILE thread with the storage area for the extension |
| + // with ID |extension_id|. |
| + void RunWithStorage( |
| + const std::string& extension_id, const Callback& callback); |
| + |
| + // Gets the SyncableService component of the ExtensionSettings. The service |
| + // itself lives on the FILE thread. |
| + SyncableService* GetSyncableService(); |
|
akalin
2011/09/20 14:53:11
Add a comment saying this is needed for ProfileSyn
not at google - send to devlin
2011/09/21 00:20:14
Done.
|
| + |
| + ~ExtensionSettingsUIWrapper(); |
| + |
| + private: |
| + // Ref-counted container for the ExtensionSettings object. Delegates |
| + // SyncableService calls. |
| + class Core : public base::RefCountedThreadSafe<Core>, public SyncableService { |
| + public: |
| + // Constructed on UI thread. |
| + explicit Core(const FilePath& base_path); |
| + |
| + // Runs |callback| with the storage area for the extension with ID |
| + // |extension_id|. Must be run on the FILE thread. |
| + void RunWithStorageOnFileThread( |
| + const std::string& extension_id, const Callback& callback); |
| + |
| + // SyncableService implementation (just delegates to |extension_settings_|). |
| + // All run on the FILE thread. |
| + // Note that when any of these methods are called, |extension_settings_| is |
| + // guaranteed to have already been created, since |extension_settings_| is |
| + // constructed on the FILE thread. |
| + virtual SyncDataList GetAllSyncData( |
| + syncable::ModelType type) const OVERRIDE; |
|
akalin
2011/09/20 14:53:11
#include base/compiler_specific.h for OVERRIDE
not at google - send to devlin
2011/09/21 00:20:14
Done.
|
| + virtual SyncError MergeDataAndStartSyncing( |
| + syncable::ModelType type, |
| + const SyncDataList& initial_sync_data, |
| + SyncChangeProcessor* sync_processor) OVERRIDE; |
| + virtual SyncError ProcessSyncChanges( |
| + const tracked_objects::Location& from_here, |
| + const SyncChangeList& change_list) OVERRIDE; |
| + virtual void StopSyncing(syncable::ModelType type) OVERRIDE; |
| + |
| + private: |
| + // Can be destroyed on either the UI or FILE thread. |
| + virtual ~Core(); |
| + friend class base::RefCountedThreadSafe<Core>; |
| + |
| + // Does any FILE thread specific initialization, such as construction of |
| + // |extension_settings_|. |
| + void InitOnFileThread(const FilePath& base_path); |
| + |
| + // Lives on the FILE thread. |
| + ExtensionSettings* extension_settings_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Core); |
| + }; |
| + |
| + scoped_refptr<Core> core_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsUIWrapper); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_UI_WRAPPER_H_ |