Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(704)

Side by Side Diff: chrome/browser/extensions/extension_settings_frontend.h

Issue 8177022: Add onChanged events to the extension settings API, both from sync and between (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: profile fix, comments Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_FRONTEND_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_FRONTEND_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_FRONTEND_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_FRONTEND_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/callback.h"
9 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/callback.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/observer_list_threadsafe.h"
14 #include "chrome/browser/extensions/extension_settings_observer.h"
12 #include "chrome/browser/sync/api/syncable_service.h" 15 #include "chrome/browser/sync/api/syncable_service.h"
16 #include "content/common/notification_observer.h"
17 #include "content/common/notification_registrar.h"
13 18
14 class FilePath; 19 class FilePath;
20 class Profile;
15 class ExtensionSettingsBackend; 21 class ExtensionSettingsBackend;
16 class ExtensionSettingsStorage; 22 class ExtensionSettingsStorage;
17 23
18 // The component of extension settings which runs on the UI thread, as opposed 24 // The component of extension settings which runs on the UI thread, as opposed
19 // to ExtensionSettingsBackend which lives on the FILE thread. 25 // to ExtensionSettingsBackend which lives on the FILE thread.
20 class ExtensionSettingsFrontend { 26 class ExtensionSettingsFrontend : public NotificationObserver {
21 public: 27 public:
22 explicit ExtensionSettingsFrontend(const FilePath& base_path); 28 explicit ExtensionSettingsFrontend(Profile* profile);
29 virtual ~ExtensionSettingsFrontend();
23 30
24 typedef base::Callback<void(ExtensionSettingsBackend*)> BackendCallback; 31 typedef base::Callback<void(ExtensionSettingsBackend*)> BackendCallback;
25 32
26 // Runs |callback| on the FILE thread with the extension settings. 33 // Runs |callback| on the FILE thread with the extension settings.
27 void RunWithBackend(const BackendCallback& callback); 34 void RunWithBackend(const BackendCallback& callback);
28 35
29 ~ExtensionSettingsFrontend(); 36 // Adds an observer to settings changes.
37 void AddObserver(ExtensionSettingsObserver* observer);
38
39 // Removes an observer to settings changes.
40 void RemoveObserver(ExtensionSettingsObserver* observer);
41
42 // NotificationObserver implementation.
43 virtual void Observe(
44 int type,
45 const NotificationSource& source,
46 const NotificationDetails& details) OVERRIDE;
30 47
31 private: 48 private:
49 // Called when a profile is created.
50 void OnProfileCreated(Profile* profile);
51
52 // Called when a profile is destroyed.
53 void OnProfileDestroyed(Profile* profile);
54
55 // The Profile this Frontend belongs to. Note that we don't store the
56 // incognito version of the profile because it will change as its created
57 // and destroyed during the lifetime of Chrome.
58 Profile* const profile_;
59
60 // List of observers to settings changes.
61 scoped_refptr<ObserverListThreadSafe<ExtensionSettingsObserver> > observers_;
62
63 // The "Normal" mode profile observer and "incognito" mode profile observer.
64 // This class listens to all PROFILE_{CREATED,DESTROYED} events but we're only
akalin 2011/10/19 19:09:49 Ah, I see. I think this comment (after the first
not at google - send to devlin 2011/10/19 22:59:36 Done.
65 // interested in those for the Profile given on construction and its incognito
66 // version.
67 class DefaultObserver;
68 scoped_ptr<DefaultObserver> profile_observer_;
69 scoped_ptr<DefaultObserver> incognito_profile_observer_;
70
32 // Ref-counted container for the ExtensionSettingsBackend object. 71 // Ref-counted container for the ExtensionSettingsBackend object.
33 class Core : public base::RefCountedThreadSafe<Core> { 72 class Core;
34 public: 73 scoped_refptr<Core> core_;
35 // Constructed on UI thread.
36 Core();
37 74
38 // Does any FILE thread specific initialization, such as construction of 75 // For profile created/destroyed notifications.
39 // |backend_|. Must be called before any call to 76 NotificationRegistrar registrar_;
40 // RunWithBackendOnFileThread().
41 void InitOnFileThread(const FilePath& base_path);
42
43 // Runs |callback| with the extension backend.
44 void RunWithBackendOnFileThread(const BackendCallback& callback);
45
46 private:
47 // Can be destroyed on either the UI or FILE thread.
48 virtual ~Core();
49 friend class base::RefCountedThreadSafe<Core>;
50
51 // Lives on the FILE thread.
52 ExtensionSettingsBackend* backend_;
53
54 DISALLOW_COPY_AND_ASSIGN(Core);
55 };
56
57 scoped_refptr<Core> core_;
58 77
59 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsFrontend); 78 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsFrontend);
60 }; 79 };
61 80
62 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_FRONTEND_H_ 81 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_FRONTEND_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698