1 // Copyright 2018 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_POLICY_DEVELOPER_TOOLS_POLICY_HANDLER_H_
6 #define CHROME_BROWSER_POLICY_DEVELOPER_TOOLS_POLICY_HANDLER_H_
7 
8 #include "base/macros.h"
9 #include "components/policy/core/browser/configuration_policy_handler.h"
10 
11 class PrefService;
12 
13 namespace user_prefs {
14 class PrefRegistrySyncable;
15 }
16 
17 namespace policy {
18 
19 // Handles the DeveloperToolsDisabled and DeveloperToolsAvailability policies.
20 // Controls the managed values of the prefs |kDevToolsAvailability| and
21 // |kExtensionsUIDeveloperMode|.
22 class DeveloperToolsPolicyHandler : public ConfigurationPolicyHandler {
23  public:
24   DeveloperToolsPolicyHandler();
25   ~DeveloperToolsPolicyHandler() override;
26 
27   // Developer tools availability as set by policy. The values must match the
28   // 'DeveloperToolsAvailability' policy definition.
29   enum class Availability {
30     // Default: Developer tools are allowed, except for
31     // force-installed extensions.
32     kDisallowedForForceInstalledExtensions = 0,
33     // Developer tools allowed in all contexts.
34     kAllowed = 1,
35     // Developer tools disallowed in all contexts.
36     kDisallowed = 2,
37     // Maximal valid value for range checking.
38     kMaxValue = kDisallowed
39   };
40 
41   // ConfigurationPolicyHandler methods:
42   bool CheckPolicySettings(const policy::PolicyMap& policies,
43                            policy::PolicyErrorMap* errors) override;
44   void ApplyPolicySettings(const PolicyMap& policies,
45                            PrefValueMap* prefs) override;
46 
47   // Registers the pref for policy-set developer tools availability in
48   // |registry|.
49   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
50 
51   // Returns the current policy-set developer tools availability according to
52   // the values in |pref_service|. If no policy mandating developer tools
53   // availability is set, the default will be
54   // |Availability::kDisallowedForForceInstalledExtensions|.
55   static Availability GetDevToolsAvailability(const PrefService* pref_service);
56 
57   // Returns true if developer tools availability is set by an active policy in
58   // |pref_service|.
59   static bool IsDevToolsAvailabilitySetByPolicy(
60       const PrefService* pref_service);
61 
62   // Returns the most restrictive availability within [|availability_1|,
63   // |availability_2|].
64   static Availability GetMostRestrictiveAvailability(
65       Availability availability_1,
66       Availability availability_2);
67 
68  private:
69   DISALLOW_COPY_AND_ASSIGN(DeveloperToolsPolicyHandler);
70 };
71 
72 }  // namespace policy
73 
74 #endif  // CHROME_BROWSER_POLICY_DEVELOPER_TOOLS_POLICY_HANDLER_H_
75