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

Side by Side Diff: chrome/browser/managed_mode/managed_mode.h

Issue 11826059: Add ManagedUserService for profile-specific managed user data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win fix Created 7 years, 11 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_MANAGED_MODE_MANAGED_MODE_H_ 5 #ifndef CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_H_
6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_H_ 6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/singleton.h" 16 #include "base/memory/singleton.h"
16 #include "chrome/browser/extensions/management_policy.h"
17 #include "chrome/browser/ui/browser_list_observer.h" 17 #include "chrome/browser/ui/browser_list_observer.h"
18 #include "content/public/browser/notification_observer.h" 18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h" 19 #include "content/public/browser/notification_registrar.h"
20 20
21 class Browser; 21 class Browser;
22 template<typename T> 22 template<typename T>
23 struct DefaultSingletonTraits; 23 struct DefaultSingletonTraits;
24 class ManagedModeSiteList; 24 class ManagedModeSiteList;
25 class ManagedModeURLFilter; 25 class ManagedModeURLFilter;
26 class PrefChangeRegistrar; 26 class PrefChangeRegistrar;
27 class PrefServiceSimple; 27 class PrefServiceSimple;
28 class PrefServiceSyncable; 28 class PrefServiceSyncable;
29 class Profile; 29 class Profile;
30 30
31 namespace policy{ 31 namespace policy {
32 class URLBlacklist; 32 class URLBlacklist;
33 } 33 }
34 34
35 // Managed mode allows one person to manage the Chrome experience for another 35 // Managed mode locks the UI to a certain managed user profile, preventing the
36 // person by pre-configuring and then locking a managed User profile. 36 // user from accessing other profiles.
37 // The ManagedMode class provides methods to check whether the browser is in 37 // The ManagedMode class provides methods to check whether the browser is in
38 // managed mode, and to attempt to enter or leave managed mode. 38 // managed mode, and to attempt to enter or leave managed mode.
39 // Except where otherwise noted, this class should be used on the UI thread. 39 // Except where otherwise noted, this class should be used on the UI thread.
40 class ManagedMode : public chrome::BrowserListObserver, 40 class ManagedMode : public chrome::BrowserListObserver,
41 public extensions::ManagementPolicy::Provider,
42 public content::NotificationObserver { 41 public content::NotificationObserver {
43 public: 42 public:
44 typedef base::Callback<void(bool)> EnterCallback; 43 typedef base::Callback<void(bool)> EnterCallback;
45 44
46 static void RegisterPrefs(PrefServiceSimple* prefs); 45 static void RegisterPrefs(PrefServiceSimple* prefs);
47 static void RegisterUserPrefs(PrefServiceSyncable* prefs);
48 46
49 // Initializes the singleton, setting the managed_profile_. Must be called 47 // Initializes the singleton, setting the managed_profile_. Must be called
50 // after g_browser_process and the LocalState have been created. 48 // after g_browser_process and the LocalState have been created.
51 static void Init(Profile* profile); 49 static void Init(Profile* profile);
52 static bool IsInManagedMode(); 50 static bool IsInManagedMode();
53 51
54 // Calls |callback| with the argument true iff managed mode was entered 52 // Calls |callback| with the argument true iff managed mode was entered
55 // sucessfully. 53 // sucessfully.
56 static void EnterManagedMode(Profile* profile, const EnterCallback& callback); 54 static void EnterManagedMode(Profile* profile, const EnterCallback& callback);
57 static void LeaveManagedMode(); 55 static void LeaveManagedMode();
58 56
59 // Returns the URL filter for the IO thread, for filtering network requests
60 // (in ChromeNetworkDelegate).
61 // This method should only be called on the IO thread.
62 static const ManagedModeURLFilter* GetURLFilterForIOThread();
63
64 // Returns the URL filter for the UI thread, for filtering navigations and
65 // classifying sites in the history view.
66 // This method should only be called on the UI thread.
67 static const ManagedModeURLFilter* GetURLFilterForUIThread();
68
69 // The functions that handle manual whitelists use |url_pattern| or lists
70 // of "url patterns". An "url pattern" is a pattern in the format used by the
71 // policy::URLBlacklist filter. A description of the format used can be found
72 // here: http://dev.chromium.org/administrators/url-blacklist-filter-format.
73 // They all receive the |is_whitelist| parameter which dictates whether they
74 // act on the whitelist (for |is_whitelist| == true) or on the blacklist (for
75 // |is_whitelist| == false).
76
77 // Checks if the |url_pattern| is in the manual whitelist.
78 static bool IsInManualList(const bool is_whitelist,
79 const std::string& url_pattern);
80
81 // Appends |list| to the manual white/black list (according to |is_whitelist|)
82 // both in URL filter and in preferences.
83 static void AddToManualList(const bool is_whitelist,
84 const base::ListValue& list);
85
86 // Removes |list| from the manual white/black list (according to
87 // |is_whitelist|) both in URL filter and in preferences.
88 static void RemoveFromManualList(const bool is_whitelist,
89 const base::ListValue& list);
90
91 // Updates the whitelist and the blacklist from the prefs.
92 static void UpdateManualLists();
93
94 // Returns the profile blacklist.
95 static scoped_ptr<base::ListValue> GetBlacklist();
96
97 // ExtensionManagementPolicy::Provider implementation:
98 virtual std::string GetDebugPolicyProviderName() const OVERRIDE;
99 virtual bool UserMayLoad(const extensions::Extension* extension,
100 string16* error) const OVERRIDE;
101 virtual bool UserMayModifySettings(const extensions::Extension* extension,
102 string16* error) const OVERRIDE;
103
104 // chrome::BrowserListObserver implementation: 57 // chrome::BrowserListObserver implementation:
105 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; 58 virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
106 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; 59 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
107 60
108 // content::NotificationObserver implementation: 61 // content::NotificationObserver implementation:
109 virtual void Observe(int type, 62 virtual void Observe(int type,
110 const content::NotificationSource& source, 63 const content::NotificationSource& source,
111 const content::NotificationDetails& details) OVERRIDE; 64 const content::NotificationDetails& details) OVERRIDE;
112 65
113 protected: 66 protected:
114 ManagedMode(); 67 ManagedMode();
115 virtual ~ManagedMode(); 68 virtual ~ManagedMode();
116 void EnterManagedModeImpl(Profile* profile, const EnterCallback& callback); 69 void EnterManagedModeImpl(Profile* profile, const EnterCallback& callback);
117 70
118 // The managed profile. This is NULL iff we are not in managed mode. 71 // The managed profile. This is NULL iff we are not in managed mode.
119 Profile* managed_profile_; 72 Profile* managed_profile_;
120 73
121 private: 74 private:
122 class URLFilterContext;
123
124 friend class Singleton<ManagedMode, LeakySingletonTraits<ManagedMode> >; 75 friend class Singleton<ManagedMode, LeakySingletonTraits<ManagedMode> >;
125 friend struct DefaultSingletonTraits<ManagedMode>; 76 friend struct DefaultSingletonTraits<ManagedMode>;
126 FRIEND_TEST_ALL_PREFIXES(ExtensionApiTest, ManagedModeOnChange); 77 FRIEND_TEST_ALL_PREFIXES(ExtensionApiTest, ManagedModeOnChange);
127 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, 78 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest,
128 ManagedModeProhibitsModification); 79 ManagedModeProhibitsModification);
129 FRIEND_TEST_ALL_PREFIXES(ManagedModeContentPackTest, InstallContentPacks); 80 FRIEND_TEST_ALL_PREFIXES(ManagedModeContentPackTest, InstallContentPacks);
130 81
131 static ManagedMode* GetInstance(); 82 static ManagedMode* GetInstance();
132 83
133 virtual void InitImpl(Profile* profile); 84 virtual void InitImpl(Profile* profile);
134 85
135 // Internal implementation for ExtensionManagementPolicy::Delegate methods.
136 // If |error| is not NULL, it will be filled with an error message if the
137 // requested extension action (install, modify status, etc.) is not permitted.
138 bool ExtensionManagementPolicyImpl(string16* error) const;
139
140 void LeaveManagedModeImpl(); 86 void LeaveManagedModeImpl();
141 87
142 ManagedModeURLFilter* GetURLFilterForIOThreadImpl();
143 ManagedModeURLFilter* GetURLFilterForUIThreadImpl();
144
145 void FinalizeEnter(bool result); 88 void FinalizeEnter(bool result);
146 89
147 // Platform-specific methods that confirm whether we can enter or leave 90 // Platform-specific methods that confirm whether we can enter or leave
148 // managed mode. 91 // managed mode.
149 virtual bool PlatformConfirmEnter(); 92 virtual bool PlatformConfirmEnter();
150 virtual bool PlatformConfirmLeave(); 93 virtual bool PlatformConfirmLeave();
151 94
152 virtual bool IsInManagedModeImpl() const; 95 virtual bool IsInManagedModeImpl() const;
153 96
154 // Enables or disables managed mode and registers or unregisters it with the 97 // Enables or disables managed mode and registers or unregisters it with the
155 // ManagementPolicy. If |newly_managed_profile| is NULL, managed mode will 98 // ManagementPolicy. If |newly_managed_profile| is NULL, managed mode will
156 // be disabled. Otherwise, managed mode will be enabled for that profile 99 // be disabled. Otherwise, managed mode will be enabled for that profile
157 // (typically |managed_profile_|, but other values are possible during 100 // (typically |managed_profile_|, but other values are possible during
158 // testing). 101 // testing).
159 virtual void SetInManagedMode(Profile* newly_managed_profile); 102 virtual void SetInManagedMode(Profile* newly_managed_profile);
160 103
161 // Returns a list of all installed and enabled site lists in the current
162 // managed profile.
163 // This method should only be called if managed mode is active.
164 ScopedVector<ManagedModeSiteList> GetActiveSiteLists();
165
166 void OnDefaultFilteringBehaviorChanged();
167
168 void UpdateManualListsImpl();
169
170 // Returns a copy of the manual whitelist which is stored in each profile.
171 scoped_ptr<base::ListValue> GetWhitelist();
172
173 // The following functions use |is_whitelist| to select between the whitelist
174 // and the blacklist as the target of the function. If |is_whitelist| is true
175 // |url_pattern| is added to the whitelist, otherwise it is added to the
176 // blacklist.
177
178 void RemoveFromManualListImpl(const bool is_whitelist,
179 const base::ListValue& whitelist);
180
181 // Adds the |url_pattern| to the manual lists in the URL filter. This is used
182 // by AddToManualListImpl().
183 void AddURLPatternToManualList(const bool is_whitelist,
184 const std::string& url_pattern);
185
186 void AddToManualListImpl(const bool is_whitelist,
187 const base::ListValue& whitelist);
188
189 bool IsInManualListImpl(const bool is_whitelist,
190 const std::string& url_pattern);
191
192 content::NotificationRegistrar registrar_; 104 content::NotificationRegistrar registrar_;
193 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
194
195 scoped_ptr<URLFilterContext> io_url_filter_context_;
196 scoped_ptr<URLFilterContext> ui_url_filter_context_;
197
198 std::set<Browser*> browsers_to_close_; 105 std::set<Browser*> browsers_to_close_;
199 std::vector<EnterCallback> callbacks_; 106 std::vector<EnterCallback> callbacks_;
200 107
201 DISALLOW_COPY_AND_ASSIGN(ManagedMode); 108 DISALLOW_COPY_AND_ASSIGN(ManagedMode);
202 }; 109 };
203 110
204 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_H_ 111 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698