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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_UI_WRAPPER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_UI_WRAPPER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/callback.h" |
| 12 #include "chrome/browser/sync/api/syncable_service.h" |
| 13 |
| 14 class FilePath; |
| 15 class ExtensionSettings; |
| 16 class ExtensionSettingsStorage; |
| 17 |
| 18 // Wrapper for an ExtensionSettings object for dealing with thread ownership. |
| 19 // This class lives on the UI thread while ExtensionSettings object live on |
| 20 // the FILE thread. |
| 21 class ExtensionSettingsUIWrapper { |
| 22 public: |
| 23 explicit ExtensionSettingsUIWrapper(const FilePath& base_path); |
| 24 |
| 25 typedef base::Callback<void(ExtensionSettings*)> SettingsCallback; |
| 26 |
| 27 // Runs |callback| on the FILE thread with the extension settings. |
| 28 void RunWithSettings(const SettingsCallback& callback); |
| 29 |
| 30 ~ExtensionSettingsUIWrapper(); |
| 31 |
| 32 private: |
| 33 // Ref-counted container for the ExtensionSettings object. |
| 34 class Core : public base::RefCountedThreadSafe<Core> { |
| 35 public: |
| 36 // Constructed on UI thread. |
| 37 explicit Core(const FilePath& base_path); |
| 38 |
| 39 // Runs |callback| with extension settings. |
| 40 void RunWithSettingsOnFileThread(const SettingsCallback& callback); |
| 41 |
| 42 private: |
| 43 // Can be destroyed on either the UI or FILE thread. |
| 44 virtual ~Core(); |
| 45 friend class base::RefCountedThreadSafe<Core>; |
| 46 |
| 47 // Does any FILE thread specific initialization, such as construction of |
| 48 // |extension_settings_|. |
| 49 void InitOnFileThread(const FilePath& base_path); |
| 50 |
| 51 // Lives on the FILE thread. |
| 52 ExtensionSettings* extension_settings_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(Core); |
| 55 }; |
| 56 |
| 57 scoped_refptr<Core> core_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsUIWrapper); |
| 60 }; |
| 61 |
| 62 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_UI_WRAPPER_H_ |
OLD | NEW |