Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Side by Side Diff: components/content_settings/core/browser/website_settings_registry.h

Issue 1991623005: Only Register() platform specific content settings types on different platforms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: split the changes and register images, plugins, mouselock in this CL Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_WEBSITE_SETTINGS_REGISTRY_H_ 5 #ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_WEBSITE_SETTINGS_REGISTRY_H_
6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_WEBSITE_SETTINGS_REGISTRY_H_ 6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_WEBSITE_SETTINGS_REGISTRY_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "components/content_settings/core/browser/content_settings_utils.h" 15 #include "components/content_settings/core/browser/content_settings_utils.h"
16 #include "components/content_settings/core/browser/website_settings_info.h" 16 #include "components/content_settings/core/browser/website_settings_info.h"
17 #include "components/content_settings/core/common/content_settings.h" 17 #include "components/content_settings/core/common/content_settings.h"
18 #include "components/content_settings/core/common/content_settings_types.h" 18 #include "components/content_settings/core/common/content_settings_types.h"
19 19
20 namespace content_settings { 20 namespace content_settings {
21 21
22 // This class stores WebsiteSettingsInfo objects for each website setting in the 22 // This class stores WebsiteSettingsInfo objects for each website setting in the
23 // system and provides access to them. Global instances can be fetched and 23 // system and provides access to them. Global instances can be fetched and
24 // methods called from from any thread because all of its public methods are 24 // methods called from from any thread because all of its public methods are
25 // const. 25 // const.
26 class WebsiteSettingsRegistry { 26 class WebsiteSettingsRegistry {
27 public: 27 public:
28 typedef uint32_t Platforms;
29 // TODO(lshang): Remove this enum when content settings can be registered from
30 // within the component in which they are used. When this is possible then
31 // ifdefs can be contained within each component.
32 enum Platform : Platforms {
33 PLATFORM_WINDOWS = 1 << 0,
34 PLATFORM_LINUX = 1 << 1,
35 PLATFORM_CHROMEOS = 1 << 2,
36 PLATFORM_MAC = 1 << 3,
37 PLATFORM_ANDROID = 1 << 4,
38 PLATFORM_IOS = 1 << 5,
39
40 // Settings only applied to win, mac, linux and chromeos.
41 DESKTOP =
42 PLATFORM_WINDOWS | PLATFORM_LINUX | PLATFORM_CHROMEOS | PLATFORM_MAC,
43
44 // Settings applied to all platforms, including win, mac, linux, chromeos,
45 // android, ios.
46 ALL_PLATFORMS = DESKTOP | PLATFORM_ANDROID | PLATFORM_IOS,
47 };
48
28 using Map = 49 using Map =
29 std::map<ContentSettingsType, std::unique_ptr<WebsiteSettingsInfo>>; 50 std::map<ContentSettingsType, std::unique_ptr<WebsiteSettingsInfo>>;
30 using const_iterator = MapValueIterator<typename Map::const_iterator, 51 using const_iterator = MapValueIterator<typename Map::const_iterator,
31 const WebsiteSettingsInfo*>; 52 const WebsiteSettingsInfo*>;
32 53
33 static WebsiteSettingsRegistry* GetInstance(); 54 static WebsiteSettingsRegistry* GetInstance();
34 55
35 // Reset the instance for use inside tests. 56 // Reset the instance for use inside tests.
36 void ResetForTest(); 57 void ResetForTest();
37 58
38 const WebsiteSettingsInfo* Get(ContentSettingsType type) const; 59 const WebsiteSettingsInfo* Get(ContentSettingsType type) const;
39 const WebsiteSettingsInfo* GetByName(const std::string& name) const; 60 const WebsiteSettingsInfo* GetByName(const std::string& name) const;
40 61
41 // Register a new website setting. This maps an origin to an arbitrary 62 // Register a new website setting. This maps an origin to an arbitrary
42 // base::Value. Returns a pointer to the registered WebsiteSettingsInfo which 63 // base::Value. Returns a pointer to the registered WebsiteSettingsInfo which
43 // is owned by the registry. 64 // is owned by the registry.
65 // A nullptr will be returned if registration fails (for example if
66 // |platforms| doesn't match the current platform).
44 const WebsiteSettingsInfo* Register( 67 const WebsiteSettingsInfo* Register(
45 ContentSettingsType type, 68 ContentSettingsType type,
46 const std::string& name, 69 const std::string& name,
47 std::unique_ptr<base::Value> initial_default_value, 70 std::unique_ptr<base::Value> initial_default_value,
48 WebsiteSettingsInfo::SyncStatus sync_status, 71 WebsiteSettingsInfo::SyncStatus sync_status,
49 WebsiteSettingsInfo::LossyStatus lossy_status, 72 WebsiteSettingsInfo::LossyStatus lossy_status,
50 WebsiteSettingsInfo::ScopingType scoping_type, 73 WebsiteSettingsInfo::ScopingType scoping_type,
74 Platforms platforms,
51 WebsiteSettingsInfo::IncognitoBehavior incognito_behavior); 75 WebsiteSettingsInfo::IncognitoBehavior incognito_behavior);
52 76
53 const_iterator begin() const; 77 const_iterator begin() const;
54 const_iterator end() const; 78 const_iterator end() const;
55 79
56 private: 80 private:
57 friend class ContentSettingsRegistryTest; 81 friend class ContentSettingsRegistryTest;
58 friend class WebsiteSettingsRegistryTest; 82 friend class WebsiteSettingsRegistryTest;
59 friend struct base::DefaultLazyInstanceTraits<WebsiteSettingsRegistry>; 83 friend struct base::DefaultLazyInstanceTraits<WebsiteSettingsRegistry>;
60 84
61 WebsiteSettingsRegistry(); 85 WebsiteSettingsRegistry();
62 ~WebsiteSettingsRegistry(); 86 ~WebsiteSettingsRegistry();
63 87
64 void Init(); 88 void Init();
65 89
66 Map website_settings_info_; 90 Map website_settings_info_;
67 91
68 DISALLOW_COPY_AND_ASSIGN(WebsiteSettingsRegistry); 92 DISALLOW_COPY_AND_ASSIGN(WebsiteSettingsRegistry);
69 }; 93 };
70 94
71 } // namespace content_settings 95 } // namespace content_settings
72 96
73 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_WEBSITE_SETTINGS_REGISTRY_H_ 97 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_WEBSITE_SETTINGS_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698