Chromium Code Reviews| Index: chrome/browser/managed_mode/managed_user_service.h |
| diff --git a/chrome/browser/managed_mode/managed_user_service.h b/chrome/browser/managed_mode/managed_user_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ad71d57428e3b039e7360d7ff7097c7f34531c68 |
| --- /dev/null |
| +++ b/chrome/browser/managed_mode/managed_user_service.h |
| @@ -0,0 +1,147 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
Pam (message me for reviews)
2013/01/14 14:12:42
2013
...even though most of this comes straight fr
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_ |
| +#define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_ |
| + |
| +#include <vector> |
| + |
| +#include "base/prefs/public/pref_change_registrar.h" |
| +#include "base/string16.h" |
| +#include "chrome/browser/extensions/management_policy.h" |
| +#include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
| +#include "chrome/browser/profiles/profile_keyed_service.h" |
| +#include "content/public/browser/notification_observer.h" |
| +#include "content/public/browser/notification_registrar.h" |
| + |
| +class ManagedModeURLFilter; |
| +class ManagedModeSiteList; |
| +class PrefServiceSyncable; |
| +class Profile; |
| + |
| +class ManagedUserService : public ProfileKeyedService, |
|
Pam (message me for reviews)
2013/01/14 14:12:42
Please add a brief comment describing what this th
Bernhard Bauer
2013/01/15 14:24:44
Done.
|
| + public extensions::ManagementPolicy::Provider, |
| + public content::NotificationObserver { |
| + public: |
| + typedef std::vector<string16> CategoryList; |
| + |
| + explicit ManagedUserService(Profile* profile); |
| + virtual ~ManagedUserService(); |
| + |
| + bool ProfileIsManaged() const; |
| + |
| + static void RegisterUserPrefs(PrefServiceSyncable* prefs); |
| + |
| + // Returns the URL filter for the IO thread, for filtering network requests |
| + // (in ChromeNetworkDelegate). |
| + scoped_refptr<const ManagedModeURLFilter> GetURLFilterForIOThread(); |
| + |
| + // Returns the URL filter for the UI thread, for filtering navigations and |
| + // classifying sites in the history view. |
| + const ManagedModeURLFilter* GetURLFilterForUIThread(); |
| + |
| + // Returns the URL's category. |
|
Pam (message me for reviews)
2013/01/14 14:12:42
...obtained from one of the installed content-pack
Bernhard Bauer
2013/01/15 14:24:44
Done.
|
| + int GetCategory(const GURL& url); |
| + |
| + // Called in the critical path of drawing the history UI, so needs to be fast. |
|
Pam (message me for reviews)
2013/01/14 14:12:42
Returns the list of all known human-readable categ
Bernhard Bauer
2013/01/15 14:24:44
Done.
|
| + void GetCategoryNames(CategoryList* list); |
| + |
| + // The functions that handle manual whitelists use |url_pattern| or lists |
| + // of "url patterns". An "url pattern" is a pattern in the format used by the |
| + // policy::URLBlacklist filter. A description of the format used can be found |
| + // here: http://dev.chromium.org/administrators/url-blacklist-filter-format. |
| + // They all receive the |is_whitelist| parameter which dictates whether they |
| + // act on the whitelist (for |is_whitelist| == true) or on the blacklist (for |
| + // |is_whitelist| == false). |
| + |
| + // Checks if the |url_pattern| is in the manual whitelist. |
| + bool IsInManualList(const bool is_whitelist, |
| + const std::string& url_pattern); |
| + |
| + // Appends |list| to the manual white/black list (according to |is_whitelist|) |
| + // both in URL filter and in preferences. |
| + void AddToManualList(const bool is_whitelist, |
| + const base::ListValue& list); |
| + |
| + // Removes |list| from the manual white/black list (according to |
| + // |is_whitelist|) both in URL filter and in preferences. |
| + void RemoveFromManualList(const bool is_whitelist, |
| + const base::ListValue& list); |
| + |
| + // Updates the whitelist and the blacklist from the prefs. |
| + void UpdateManualLists(); |
| + |
| + // ExtensionManagementPolicy::Provider implementation: |
| + virtual std::string GetDebugPolicyProviderName() const OVERRIDE; |
| + virtual bool UserMayLoad(const extensions::Extension* extension, |
| + string16* error) const OVERRIDE; |
| + virtual bool UserMayModifySettings(const extensions::Extension* extension, |
| + string16* error) const OVERRIDE; |
| + |
| + // content::NotificationObserver implementation: |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE; |
| + |
| + private: |
| + // A bridge from ManagedMode (which lives on the UI thread) to a |
| + // ManagedModeURLFilter living on the IO thread. |
|
Pam (message me for reviews)
2013/01/14 14:12:42
More than that, really. A bridge from ManagedMode
|
| + class URLFilterContext { |
| + public: |
| + URLFilterContext(); |
| + ~URLFilterContext(); |
| + |
| + ManagedModeURLFilter* ui_url_filter() const; |
| + ManagedModeURLFilter* io_url_filter() const; |
| + |
| + void SetDefaultFilteringBehavior( |
| + ManagedModeURLFilter::FilteringBehavior behavior); |
| + void LoadWhitelists(ScopedVector<ManagedModeSiteList> site_lists); |
| + void SetManualLists(scoped_ptr<base::ListValue> whitelist, |
| + scoped_ptr<base::ListValue> blacklist); |
| + void AddURLPatternToManualList(const bool isWhitelist, |
| + const std::string& url); |
| + |
| + private: |
| + scoped_refptr<ManagedModeURLFilter> ui_url_filter_; |
|
Pam (message me for reviews)
2013/01/14 14:12:42
It would be worth explaining a little bit here why
Bernhard Bauer
2013/01/15 14:24:44
Done.
|
| + scoped_refptr<ManagedModeURLFilter> io_url_filter_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(URLFilterContext); |
| + }; |
| + |
| + // Internal implementation for ExtensionManagementPolicy::Delegate methods. |
| + // If |error| is not NULL, it will be filled with an error message if the |
| + // requested extension action (install, modify status, etc.) is not permitted. |
| + bool ExtensionManagementPolicyImpl(string16* error) const; |
| + |
| + // Returns a list of all installed and enabled site lists in the current |
| + // managed profile. |
| + // This method should only be called if managed mode is active. |
|
Pam (message me for reviews)
2013/01/14 14:12:42
I'd say that managed mode is always active in a ma
Bernhard Bauer
2013/01/15 14:24:44
The restriction is not really needed anymore (it w
|
| + ScopedVector<ManagedModeSiteList> GetActiveSiteLists(); |
| + |
| + void OnDefaultFilteringBehaviorChanged(); |
| + |
| + void UpdateSiteLists(); |
| + |
| + // Adds the |url_pattern| to the manual lists in the URL filter. This is used |
| + // by AddToManualListImpl(). |
| + void AddURLPatternToManualList(const bool is_whitelist, |
| + const std::string& url_pattern); |
| + |
| + // Returns a copy of the manual whitelist which is stored in each profile. |
| + scoped_ptr<base::ListValue> GetWhitelist(); |
| + |
| + // Returns a copy of the manual whitelist which is stored in each profile. |
|
Pam (message me for reviews)
2013/01/14 14:12:42
whitelist -> blacklist
Bernhard Bauer
2013/01/15 14:24:44
Done.
|
| + scoped_ptr<base::ListValue> GetBlacklist(); |
| + |
| + // Owns us. |
|
Pam (message me for reviews)
2013/01/14 14:12:42
Not anymore.
Bernhard Bauer
2013/01/15 14:24:44
It does, via the ProfileKeyedService mechanism. I
|
| + Profile* profile_; |
| + |
| + content::NotificationRegistrar registrar_; |
| + PrefChangeRegistrar pref_change_registrar_; |
| + |
| + URLFilterContext url_filter_context_; |
| +}; |
| + |
| +#endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SERVICE_H_ |