1 // Copyright 2020 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_SAFE_BROWSING_GENERATED_SAFE_BROWSING_PREF_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_GENERATED_SAFE_BROWSING_PREF_H_
7 
8 #include "base/scoped_observer.h"
9 #include "chrome/browser/extensions/api/settings_private/generated_pref.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "components/prefs/pref_change_registrar.h"
12 
13 namespace safe_browsing {
14 
15 extern const char kGeneratedSafeBrowsingPref[];
16 
17 // Must be kept in sync with the SafeBrowsing enum located in
18 // chrome/browser/resources/settings/privacy_page/security_page.js.
19 enum class SafeBrowsingSetting {
20   ENHANCED,
21   STANDARD,
22   DISABLED,
23 };
24 
25 // A generated preference which represents the effective Safe Browsing setting
26 // state (including non-user management) based on the underlying Safe Browsing
27 // enhanced, enabled and reporting preferences. This preference allows the
28 // direct use of WebUI controls without exposing any logic responsible for
29 // coalescing the underlying Safe Browsing prefs to front-end code.
30 class GeneratedSafeBrowsingPref
31     : public extensions::settings_private::GeneratedPref {
32  public:
33   explicit GeneratedSafeBrowsingPref(Profile* profile);
34 
35   // Generated Preference Interface.
36   extensions::settings_private::SetPrefResult SetPref(
37       const base::Value* value) override;
38   std::unique_ptr<extensions::api::settings_private::PrefObject> GetPrefObject()
39       const override;
40 
41   // Fired when underlying Safe Browsing preferences are changed.
42   void OnSafeBrowsingPreferencesChanged();
43 
44  private:
45   // Applies the effective management state of Safe Browsing for |profile| to
46   // |pref_object|.
47   static void ApplySafeBrowsingManagementState(
48       const Profile* profile,
49       extensions::api::settings_private::PrefObject* pref_object);
50 
51   // Weak reference to the profile this preference is generated for.
52   Profile* const profile_;
53 
54   PrefChangeRegistrar user_prefs_registrar_;
55 };
56 
57 }  // namespace safe_browsing
58 
59 #endif  // CHROME_BROWSER_SAFE_BROWSING_GENERATED_SAFE_BROWSING_PREF_H_
60