1 // Copyright 2015 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_EXTENSIONS_API_SETTINGS_PRIVATE_SETTINGS_PRIVATE_DELEGATE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_SETTINGS_PRIVATE_DELEGATE_H_
7 
8 #include <map>
9 #include <memory>
10 #include <string>
11 
12 #include "base/callback.h"
13 #include "base/macros.h"
14 #include "chrome/browser/extensions/api/settings_private/prefs_util.h"
15 #include "chrome/common/extensions/api/settings_private.h"
16 #include "components/keyed_service/core/keyed_service.h"
17 #include "extensions/browser/extension_function.h"
18 
19 class Profile;
20 
21 namespace base {
22 class Value;
23 }
24 
25 namespace extensions {
26 
27 using TypedPrefMap = std::map<std::string, api::settings_private::PrefType>;
28 
29 // Manages all the pref service interactions.
30 // Use SettingsPrivateDelegateFactory to create a SettingsPrivateDelegate
31 // object.
32 class SettingsPrivateDelegate : public KeyedService {
33  public:
34   explicit SettingsPrivateDelegate(Profile* profile);
35   ~SettingsPrivateDelegate() override;
36 
37   // Sets the pref with the given name and value in the proper PrefService.
38   virtual settings_private::SetPrefResult SetPref(const std::string& name,
39                                                   const base::Value* value);
40 
41   // Gets the value of the pref with the given |name|.
42   virtual std::unique_ptr<base::Value> GetPref(const std::string& name);
43 
44   // Gets the values of all allowlisted prefs.
45   virtual std::unique_ptr<base::Value> GetAllPrefs();
46 
47   // Gets the value.
48   virtual std::unique_ptr<base::Value> GetDefaultZoom();
49 
50   // Sets the pref.
51   virtual settings_private::SetPrefResult SetDefaultZoom(double zoom);
52 
profile_for_test()53   Profile* profile_for_test() { return profile_; }
54 
55  protected:
56   Profile* profile_;  // weak; not owned by us
57   std::unique_ptr<PrefsUtil> prefs_util_;
58 
59  private:
60   DISALLOW_COPY_AND_ASSIGN(SettingsPrivateDelegate);
61 };
62 
63 }  // namespace extensions
64 
65 #endif  // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_PRIVATE_SETTINGS_PRIVATE_DELEGATE_H_
66