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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_MANAGEMENT_POLICY_H_
6 #define CHROME_BROWSER_EXTENSIONS_MANAGEMENT_POLICY_H_
11 #include "base/basictypes.h"
12 #include "chrome/common/extensions/extension.h"
14 namespace extensions
{
16 // This class registers providers that want to prohibit certain actions from
17 // being applied to extensions. It must be called, via the ExtensionService,
18 // before allowing a user or a user-level mechanism to perform the respective
19 // action. (That is, installing or otherwise modifying an extension in order
20 // to conform to enterprise administrator policy must be exempted from these
23 // This "policy" and its providers should not be confused with administrator
24 // policy, although admin policy is one of the sources ("Providers") of
25 // restrictions registered with and exposed by the ManagementPolicy.
26 class ManagementPolicy
{
28 // Each mechanism that wishes to limit users' ability to control extensions,
29 // whether one individual extension or the whole system, should implement
30 // the methods of this Provider interface that it needs. In each case, if the
31 // provider does not need to control a certain action, that method does not
32 // need to be implemented.
34 // It is not guaranteed that a particular Provider's methods will be called
35 // each time a user tries to perform one of the controlled actions (the list
36 // of providers is short-circuited as soon as a decision is possible), so
37 // implementations of these methods must have no side effects.
39 // For all of the Provider methods below, if |error| is not NULL and the
40 // method imposes a restriction on the desired action, |error| may be set
41 // to an applicable error message, but this is not required.
45 virtual ~Provider() {}
47 // A human-readable name for this provider, for use in debug messages.
48 // Implementers should return an empty string in non-debug builds, to save
50 virtual std::string
GetDebugPolicyProviderName() const = 0;
52 // Providers should return false if a user may not install the |extension|,
53 // or load or run it if it has already been installed.
54 virtual bool UserMayLoad(const Extension
* extension
,
55 string16
* error
) const;
57 // Providers should return false if a user may not enable, disable, or
58 // uninstall the |extension|, or change its usage options (incognito
59 // permission, file access, etc.).
60 virtual bool UserMayModifySettings(const Extension
* extension
,
61 string16
* error
) const;
63 // Providers should return true if the |extension| must always remain
64 // enabled. This is distinct from UserMayModifySettings() in that the latter
65 // also prohibits enabling the extension if it is currently disabled.
66 // Providers implementing this method should also implement the others
67 // above, if they wish to completely lock in an extension.
68 virtual bool MustRemainEnabled(const Extension
* extension
,
69 string16
* error
) const;
72 DISALLOW_COPY_AND_ASSIGN(Provider
);
78 // Registers or unregisters a provider, causing it to be added to or removed
79 // from the list of providers queried. Ownership of the provider remains with
80 // the caller. Providers do not need to be unregistered on shutdown.
81 void RegisterProvider(Provider
* provider
);
82 void UnregisterProvider(Provider
* provider
);
84 // Returns true if the user is permitted to install, load, and run the given
85 // extension. If not, |error| may be set to an appropriate message.
86 bool UserMayLoad(const Extension
* extension
, string16
* error
) const;
88 // Returns true if the user is permitted to enable, disable, or uninstall the
89 // given extension, or change the extension's usage options (incognito mode,
90 // file access, etc.). If not, |error| may be set to an appropriate message.
91 bool UserMayModifySettings(const Extension
* extension
,
92 string16
* error
) const;
94 // Returns true if the extension must remain enabled at all times (e.g. a
95 // compoment extension). In that case, |error| may be set to an appropriate
97 bool MustRemainEnabled(const Extension
* extension
,
98 string16
* error
) const;
100 // For use in testing.
101 void UnregisterAllProviders();
102 int GetNumProviders() const;
105 typedef std::set
<Provider
*> ProviderList
;
106 ProviderList providers_
;
108 DISALLOW_COPY_AND_ASSIGN(ManagementPolicy
);
113 #endif // CHROME_BROWSER_EXTENSIONS_MANAGEMENT_POLICY_H_