[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 1 | // 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] | 0d9a1da8 | 2013-03-14 21:52:07 | [diff] [blame^] | 8 | #include <set> |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 9 | #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] | bfd8cf98 | 2013-03-04 15:24:00 | [diff] [blame] | 16 | #include "chrome/browser/ui/webui/managed_user_passphrase_dialog.h" |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 17 | #include "content/public/browser/notification_observer.h" |
| 18 | #include "content/public/browser/notification_registrar.h" |
[email protected] | bfd8cf98 | 2013-03-04 15:24:00 | [diff] [blame] | 19 | #include "content/public/browser/web_contents.h" |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 20 | |
| 21 | class ManagedModeURLFilter; |
| 22 | class ManagedModeSiteList; |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 23 | class PrefRegistrySyncable; |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 24 | class 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). |
| 29 | class ManagedUserService : public ProfileKeyedService, |
| 30 | public extensions::ManagementPolicy::Provider, |
| 31 | public content::NotificationObserver { |
| 32 | public: |
| 33 | typedef std::vector<string16> CategoryList; |
| 34 | |
[email protected] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 35 | enum ManualBehavior { |
| 36 | MANUAL_NONE = 0, |
| 37 | MANUAL_ALLOW, |
| 38 | MANUAL_BLOCK |
| 39 | }; |
| 40 | |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 41 | explicit ManagedUserService(Profile* profile); |
| 42 | virtual ~ManagedUserService(); |
| 43 | |
| 44 | bool ProfileIsManaged() const; |
[email protected] | bb25b40 | 2013-02-20 11:15:20 | [diff] [blame] | 45 | bool IsElevated() const; |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 46 | |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 47 | static void RegisterUserPrefs(PrefRegistrySyncable* registry); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 48 | |
| 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] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 65 | // 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] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 68 | |
[email protected] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 69 | // Returns the manual behavior for the given host. |
| 70 | ManualBehavior GetManualBehaviorForHost(const std::string& hostname); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 71 | |
[email protected] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 72 | // Sets the manual behavior for the given host. |
| 73 | void SetManualBehaviorForHosts(const std::vector<std::string>& hostnames, |
| 74 | ManualBehavior behavior); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 75 | |
[email protected] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 76 | // Returns the manual behavior for the given URL. |
| 77 | ManualBehavior GetManualBehaviorForURL(const GURL& url); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 78 | |
[email protected] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 79 | // Sets the manual behavior for the given URL. |
| 80 | void SetManualBehaviorForURLs(const std::vector<GURL>& url, |
| 81 | ManualBehavior behavior); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 82 | |
[email protected] | bfd8cf98 | 2013-03-04 15:24:00 | [diff] [blame] | 83 | // 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] | 0d9a1da8 | 2013-03-14 21:52:07 | [diff] [blame^] | 87 | // 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] | bb25b40 | 2013-02-20 11:15:20 | [diff] [blame] | 92 | void SetElevated(bool is_elevated); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 93 | |
[email protected] | 0d9a1da8 | 2013-03-14 21:52:07 | [diff] [blame^] | 94 | // 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] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 101 | // Initializes this object. This method does nothing if the profile is not |
[email protected] | ce01914 | 2013-02-12 18:08:10 | [diff] [blame] | 102 | // managed. |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 103 | void Init(); |
| 104 | |
[email protected] | ce01914 | 2013-02-12 18:08:10 | [diff] [blame] | 105 | // extensions::ManagementPolicy::Provider implementation: |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 106 | 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] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 134 | void SetManualHosts(scoped_ptr<std::map<std::string, bool> > host_map); |
| 135 | void SetManualURLs(scoped_ptr<std::map<GURL, bool> > url_map); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 136 | |
| 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] | 0d9a1da8 | 2013-03-14 21:52:07 | [diff] [blame^] | 153 | bool ExtensionManagementPolicyImpl(const std::string& extension_id, |
| 154 | string16* error) const; |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 155 | |
| 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] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 164 | // Updates the manual overrides for hosts in the URL filters when the |
| 165 | // corresponding preference is changed. |
| 166 | void UpdateManualHosts(); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 167 | |
[email protected] | 5e02229 | 2013-02-06 16:42:17 | [diff] [blame] | 168 | // Updates the manual overrides for URLs in the URL filters when the |
| 169 | // corresponding preference is changed. |
| 170 | void UpdateManualURLs(); |
[email protected] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 171 | |
| 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] | 0d9a1da8 | 2013-03-14 21:52:07 | [diff] [blame^] | 183 | // 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] | 0850e84 | 2013-01-19 03:44:31 | [diff] [blame] | 187 | URLFilterContext url_filter_context_; |
| 188 | }; |
| 189 | |
| 190 | #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_ |