File: website_settings_registry.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (99 lines) | stat: -rw-r--r-- 3,701 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_WEBSITE_SETTINGS_REGISTRY_H_
#define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_WEBSITE_SETTINGS_REGISTRY_H_

#include <map>
#include <memory>
#include <string>

#include "base/lazy_instance.h"
#include "base/values.h"
#include "components/content_settings/core/browser/content_settings_utils.h"
#include "components/content_settings/core/browser/website_settings_info.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"

namespace content_settings {

// This class stores WebsiteSettingsInfo objects for each website setting in the
// system and provides access to them. Global instances can be fetched and
// methods called from from any thread because all of its public methods are
// const.
class WebsiteSettingsRegistry {
 public:
  typedef uint32_t Platforms;
  // TODO(lshang): Remove this enum when content settings can be registered from
  // within the component in which they are used. When this is possible then
  // ifdefs can be contained within each component.
  enum Platform : Platforms {
    PLATFORM_WINDOWS = 1 << 0,
    PLATFORM_LINUX = 1 << 1,
    PLATFORM_CHROMEOS = 1 << 2,
    PLATFORM_MAC = 1 << 3,
    PLATFORM_ANDROID = 1 << 4,
    PLATFORM_IOS = 1 << 5,
    PLATFORM_FUCHSIA = 1 << 6,

    // Settings only applied to win, mac, linux, chromeos, and fuchsia.
    DESKTOP = PLATFORM_WINDOWS | PLATFORM_LINUX | PLATFORM_CHROMEOS |
              PLATFORM_MAC | PLATFORM_FUCHSIA,

    // Settings applied to all platforms, including win, mac, linux, chromeos,
    // android, ios, and fuchsia.
    ALL_PLATFORMS =
        DESKTOP | PLATFORM_ANDROID | PLATFORM_IOS | PLATFORM_FUCHSIA,
  };

  using Map =
      std::map<ContentSettingsType, std::unique_ptr<WebsiteSettingsInfo>>;
  using const_iterator = MapValueIterator<typename Map::const_iterator,
                                          const WebsiteSettingsInfo*>;

  static WebsiteSettingsRegistry* GetInstance();

  WebsiteSettingsRegistry(const WebsiteSettingsRegistry&) = delete;
  WebsiteSettingsRegistry& operator=(const WebsiteSettingsRegistry&) = delete;

  // Reset the instance for use inside tests.
  void ResetForTest();

  const WebsiteSettingsInfo* Get(ContentSettingsType type) const;
  const WebsiteSettingsInfo* GetByName(const std::string& name) const;

  // Register a new website setting. This maps an origin to an arbitrary
  // base::Value. Returns a pointer to the registered WebsiteSettingsInfo which
  // is owned by the registry.
  // A nullptr will be returned if registration fails (for example if
  // |platforms| doesn't match the current platform).
  const WebsiteSettingsInfo* Register(
      ContentSettingsType type,
      const std::string& name,
      base::Value initial_default_value,
      WebsiteSettingsInfo::SyncStatus sync_status,
      WebsiteSettingsInfo::LossyStatus lossy_status,
      WebsiteSettingsInfo::ScopingType scoping_type,
      Platforms platforms,
      WebsiteSettingsInfo::IncognitoBehavior incognito_behavior);

  const_iterator begin() const;
  const_iterator end() const;

 private:
  friend class ContentSettingsRegistryTest;
  friend class WebsiteSettingsRegistryTest;
  friend struct base::LazyInstanceTraitsBase<WebsiteSettingsRegistry>;

  WebsiteSettingsRegistry();
  ~WebsiteSettingsRegistry();

  void Init();

  Map website_settings_info_;
};

}  // namespace content_settings

#endif  // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_WEBSITE_SETTINGS_REGISTRY_H_