summaryrefslogtreecommitdiffstats
path: root/components/content_settings/core/browser/website_settings_info.cc
blob: 20faa27ca069bca24fee0ae147a8ec9d4a1bde04 (plain)
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
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/content_settings/core/browser/website_settings_info.h"

#include "base/logging.h"
#include "base/prefs/pref_registry.h"
#include "base/strings/string_util.h"
#include "base/values.h"
#include "components/pref_registry/pref_registry_syncable.h"

namespace {

const char kPrefPrefix[] = "profile.content_settings.exceptions.";
const char kDefaultPrefPrefix[] = "profile.default_content_setting_values.";

std::string GetPrefName(const std::string& name, const char* prefix) {
  std::string pref_name = name;
  base::ReplaceChars(pref_name, "-", "_", &pref_name);
  return std::string(prefix).append(pref_name);
}

}  // namespace

namespace content_settings {

WebsiteSettingsInfo::WebsiteSettingsInfo(
    ContentSettingsType type,
    const std::string& name,
    scoped_ptr<base::Value> initial_default_value,
    SyncStatus sync_status,
    LossyStatus lossy_status)
    : type_(type),
      name_(name),
      pref_name_(GetPrefName(name, kPrefPrefix)),
      default_value_pref_name_(GetPrefName(name, kDefaultPrefPrefix)),
      initial_default_value_(initial_default_value.Pass()),
      sync_status_(sync_status),
      lossy_status_(lossy_status) {
  // For legacy reasons the default value is currently restricted to be an int.
  // TODO(raymes): We should migrate the underlying pref to be a dictionary
  // rather than an int.
  DCHECK(!initial_default_value_ ||
         initial_default_value_->IsType(base::Value::TYPE_INTEGER));
}

WebsiteSettingsInfo::~WebsiteSettingsInfo() {}

uint32 WebsiteSettingsInfo::GetPrefRegistrationFlags() const {
  uint32 flags = PrefRegistry::NO_REGISTRATION_FLAGS;

  if (sync_status_ == SYNCABLE)
    flags |= user_prefs::PrefRegistrySyncable::SYNCABLE_PREF;

  if (lossy_status_ == LOSSY)
    flags |= PrefRegistry::LOSSY_PREF;

  return flags;
}

}  // namespace content_settings