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

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

Issue 8361027: Re-commit 106660 with the crashing test disabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync 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/public/browser/notification_observer.h"
17 #include "content/public/browser/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 content::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 content::NotificationSource& source,
46 const content::NotificationDetails& details) OVERRIDE;
30 47
31 private: 48 private:
49 // Observer which sends events to a target profile iff the profile isn't the
50 // originating profile for the event.
51 class DefaultObserver;
52
53 // Called when a profile is created.
54 void OnProfileCreated(Profile* profile);
55
56 // Called when a profile is destroyed.
57 void OnProfileDestroyed(Profile* profile);
58
59 // Creates a scoped DefaultObserver and adds it as an Observer.
60 void SetDefaultObserver(
61 Profile* profile, scoped_ptr<DefaultObserver>* observer);
62
63 // If a scoped DefaultObserver exists, clears it and removes it as an
64 // Observer.
65 void ClearDefaultObserver(scoped_ptr<DefaultObserver>* observer);
66
67 // The (original) Profile this Frontend belongs to. Note that we don't store
68 // the incognito version of the profile because it will change as it's
69 // created and destroyed during the lifetime of Chrome.
70 Profile* const profile_;
71
72 // List of observers to settings changes.
73 scoped_refptr<ObserverListThreadSafe<ExtensionSettingsObserver> > observers_;
74
75 // The default original and incognito mode profile observers.
76 scoped_ptr<DefaultObserver> original_profile_observer;
77 scoped_ptr<DefaultObserver> incognito_profile_observer_;
78
32 // Ref-counted container for the ExtensionSettingsBackend object. 79 // Ref-counted container for the ExtensionSettingsBackend object.
33 class Core : public base::RefCountedThreadSafe<Core> { 80 class Core;
34 public: 81 scoped_refptr<Core> core_;
35 // Constructed on UI thread.
36 Core();
37 82
38 // Does any FILE thread specific initialization, such as construction of 83 // For profile created/destroyed notifications.
39 // |backend_|. Must be called before any call to 84 content::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 85
59 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsFrontend); 86 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsFrontend);
60 }; 87 };
61 88
62 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_FRONTEND_H_ 89 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_FRONTEND_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_settings_backend.cc ('k') | chrome/browser/extensions/extension_settings_frontend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698