blob: ca7bb9e413ff235e0ab13dfa87647debd7cd44cb [file] [log] [blame]
[email protected]0850e842013-01-19 03:44:311// Copyright (c) 2013 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_MANAGED_MODE_MANAGED_USER_SERVICE_H_
6#define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_
7
[email protected]0d9a1da82013-03-14 21:52:078#include <set>
[email protected]0850e842013-01-19 03:44:319#include <vector>
10
11#include "base/prefs/public/pref_change_registrar.h"
12#include "base/string16.h"
13#include "chrome/browser/extensions/management_policy.h"
14#include "chrome/browser/managed_mode/managed_mode_url_filter.h"
15#include "chrome/browser/profiles/profile_keyed_service.h"
[email protected]bfd8cf982013-03-04 15:24:0016#include "chrome/browser/ui/webui/managed_user_passphrase_dialog.h"
[email protected]0850e842013-01-19 03:44:3117#include "content/public/browser/notification_observer.h"
18#include "content/public/browser/notification_registrar.h"
[email protected]bfd8cf982013-03-04 15:24:0019#include "content/public/browser/web_contents.h"
[email protected]0850e842013-01-19 03:44:3120
21class ManagedModeURLFilter;
22class ManagedModeSiteList;
[email protected]c753f142013-02-10 13:14:0423class PrefRegistrySyncable;
[email protected]0850e842013-01-19 03:44:3124class Profile;
25
26// This class handles all the information related to a given managed profile
27// (e.g. the installed content packs, the default URL filtering behavior, or
28// manual whitelist/blacklist overrides).
29class ManagedUserService : public ProfileKeyedService,
30 public extensions::ManagementPolicy::Provider,
31 public content::NotificationObserver {
32 public:
33 typedef std::vector<string16> CategoryList;
34
[email protected]5e022292013-02-06 16:42:1735 enum ManualBehavior {
36 MANUAL_NONE = 0,
37 MANUAL_ALLOW,
38 MANUAL_BLOCK
39 };
40
[email protected]0850e842013-01-19 03:44:3141 explicit ManagedUserService(Profile* profile);
42 virtual ~ManagedUserService();
43
44 bool ProfileIsManaged() const;
[email protected]bb25b402013-02-20 11:15:2045 bool IsElevated() const;
[email protected]0850e842013-01-19 03:44:3146
[email protected]c753f142013-02-10 13:14:0447 static void RegisterUserPrefs(PrefRegistrySyncable* registry);
[email protected]0850e842013-01-19 03:44:3148
49 // Returns the URL filter for the IO thread, for filtering network requests
50 // (in ManagedModeResourceThrottle).
51 scoped_refptr<const ManagedModeURLFilter> GetURLFilterForIOThread();
52
53 // Returns the URL filter for the UI thread, for filtering navigations and
54 // classifying sites in the history view.
55 ManagedModeURLFilter* GetURLFilterForUIThread();
56
57 // Returns the URL's category, obtained from the installed content packs.
58 int GetCategory(const GURL& url);
59
60 // Returns the list of all known human-readable category names, sorted by ID
61 // number. Called in the critical path of drawing the history UI, so needs to
62 // be fast.
63 void GetCategoryNames(CategoryList* list);
64
[email protected]5e022292013-02-06 16:42:1765 // These methods allow querying and modifying the manual filtering behavior.
66 // The manual behavior is set by the user and overrides all other settings
67 // (whitelists or the default behavior).
[email protected]0850e842013-01-19 03:44:3168
[email protected]5e022292013-02-06 16:42:1769 // Returns the manual behavior for the given host.
70 ManualBehavior GetManualBehaviorForHost(const std::string& hostname);
[email protected]0850e842013-01-19 03:44:3171
[email protected]5e022292013-02-06 16:42:1772 // Sets the manual behavior for the given host.
73 void SetManualBehaviorForHosts(const std::vector<std::string>& hostnames,
74 ManualBehavior behavior);
[email protected]0850e842013-01-19 03:44:3175
[email protected]5e022292013-02-06 16:42:1776 // Returns the manual behavior for the given URL.
77 ManualBehavior GetManualBehaviorForURL(const GURL& url);
[email protected]0850e842013-01-19 03:44:3178
[email protected]5e022292013-02-06 16:42:1779 // Sets the manual behavior for the given URL.
80 void SetManualBehaviorForURLs(const std::vector<GURL>& url,
81 ManualBehavior behavior);
[email protected]0850e842013-01-19 03:44:3182
[email protected]bfd8cf982013-03-04 15:24:0083 // Handles the request to authorize as the custodian of the managed user.
84 void RequestAuthorization(content::WebContents* web_contents,
85 const PassphraseCheckedCallback& callback);
86
[email protected]0d9a1da82013-03-14 21:52:0787 // Handles the request to authorize as the custodian of the managed user.
88 // Also determines the active web contents to be passed to the passphrase
89 // dialog.
90 void RequestAuthorization(const PassphraseCheckedCallback& callback);
91
[email protected]bb25b402013-02-20 11:15:2092 void SetElevated(bool is_elevated);
[email protected]0850e842013-01-19 03:44:3193
[email protected]0d9a1da82013-03-14 21:52:0794 // Add an elevation for a specific extension which allows the managed user to
95 // install/uninstall this specific extension.
96 void AddElevationForExtension(const std::string& extension_id);
97
98 // Remove the elevation for a specific extension.
99 void RemoveElevationForExtension(const std::string& extension_id);
100
[email protected]0850e842013-01-19 03:44:31101 // Initializes this object. This method does nothing if the profile is not
[email protected]ce019142013-02-12 18:08:10102 // managed.
[email protected]0850e842013-01-19 03:44:31103 void Init();
104
[email protected]ce019142013-02-12 18:08:10105 // extensions::ManagementPolicy::Provider implementation:
[email protected]0850e842013-01-19 03:44:31106 virtual std::string GetDebugPolicyProviderName() const OVERRIDE;
107 virtual bool UserMayLoad(const extensions::Extension* extension,
108 string16* error) const OVERRIDE;
109 virtual bool UserMayModifySettings(const extensions::Extension* extension,
110 string16* error) const OVERRIDE;
111
112 // content::NotificationObserver implementation:
113 virtual void Observe(int type,
114 const content::NotificationSource& source,
115 const content::NotificationDetails& details) OVERRIDE;
116
117 private:
118 friend class ManagedUserServiceExtensionTest;
119
120 // A bridge from ManagedMode (which lives on the UI thread) to the
121 // ManagedModeURLFilters, one of which lives on the IO thread. This class
122 // mediates access to them and makes sure they are kept in sync.
123 class URLFilterContext {
124 public:
125 URLFilterContext();
126 ~URLFilterContext();
127
128 ManagedModeURLFilter* ui_url_filter() const;
129 ManagedModeURLFilter* io_url_filter() const;
130
131 void SetDefaultFilteringBehavior(
132 ManagedModeURLFilter::FilteringBehavior behavior);
133 void LoadWhitelists(ScopedVector<ManagedModeSiteList> site_lists);
[email protected]5e022292013-02-06 16:42:17134 void SetManualHosts(scoped_ptr<std::map<std::string, bool> > host_map);
135 void SetManualURLs(scoped_ptr<std::map<GURL, bool> > url_map);
[email protected]0850e842013-01-19 03:44:31136
137 private:
138 // ManagedModeURLFilter is refcounted because the IO thread filter is used
139 // both by ProfileImplIOData and OffTheRecordProfileIOData (to filter
140 // network requests), so they both keep a reference to it.
141 // Clients should not keep references to the UI thread filter, however
142 // (the filter will live as long as the profile lives, and afterwards it
143 // should not be used anymore either).
144 scoped_refptr<ManagedModeURLFilter> ui_url_filter_;
145 scoped_refptr<ManagedModeURLFilter> io_url_filter_;
146
147 DISALLOW_COPY_AND_ASSIGN(URLFilterContext);
148 };
149
150 // Internal implementation for ExtensionManagementPolicy::Delegate methods.
151 // If |error| is not NULL, it will be filled with an error message if the
152 // requested extension action (install, modify status, etc.) is not permitted.
[email protected]0d9a1da82013-03-14 21:52:07153 bool ExtensionManagementPolicyImpl(const std::string& extension_id,
154 string16* error) const;
[email protected]0850e842013-01-19 03:44:31155
156 // Returns a list of all installed and enabled site lists in the current
157 // managed profile.
158 ScopedVector<ManagedModeSiteList> GetActiveSiteLists();
159
160 void OnDefaultFilteringBehaviorChanged();
161
162 void UpdateSiteLists();
163
[email protected]5e022292013-02-06 16:42:17164 // Updates the manual overrides for hosts in the URL filters when the
165 // corresponding preference is changed.
166 void UpdateManualHosts();
[email protected]0850e842013-01-19 03:44:31167
[email protected]5e022292013-02-06 16:42:17168 // Updates the manual overrides for URLs in the URL filters when the
169 // corresponding preference is changed.
170 void UpdateManualURLs();
[email protected]0850e842013-01-19 03:44:31171
172 // Owns us via the ProfileKeyedService mechanism.
173 Profile* profile_;
174
175 // If ManagedUserService is in an elevated state, a custodian user has
176 // authorized making changes (to install additional content packs, for
177 // example).
178 bool is_elevated_;
179
180 content::NotificationRegistrar registrar_;
181 PrefChangeRegistrar pref_change_registrar_;
182
[email protected]0d9a1da82013-03-14 21:52:07183 // Stores the extension ids of the extensions which currently can be modified
184 // by the managed user.
185 std::set<std::string> elevated_for_extensions_;
186
[email protected]0850e842013-01-19 03:44:31187 URLFilterContext url_filter_context_;
188};
189
190#endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_