summaryrefslogtreecommitdiffstats
path: root/chrome/browser/content_settings/content_settings_mock_provider.cc
blob: 02d3db0aa67def073bd59531fe627fef1ad1dfd7 (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
// Copyright (c) 2011 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 "chrome/browser/content_settings/content_settings_mock_provider.h"

namespace content_settings {

MockProvider::MockProvider()
    : read_only_(false) {}

MockProvider::MockProvider(ContentSettingsPattern requesting_url_pattern,
                           ContentSettingsPattern embedding_url_pattern,
                           ContentSettingsType content_type,
                           ResourceIdentifier resource_identifier,
                           ContentSetting setting,
                           bool read_only,
                           bool is_managed)
    : read_only_(read_only) {
  value_map_.SetValue(requesting_url_pattern,
                      embedding_url_pattern,
                      content_type,
                      resource_identifier,
                      Value::CreateIntegerValue(setting));
}

MockProvider::~MockProvider() {}

RuleIterator* MockProvider::GetRuleIterator(
    ContentSettingsType content_type,
    const ResourceIdentifier& resource_identifier,
    bool incognito) const {
  return value_map_.GetRuleIterator(content_type, resource_identifier, NULL);
}

bool MockProvider::SetWebsiteSetting(
    const ContentSettingsPattern& requesting_url_pattern,
    const ContentSettingsPattern& embedding_url_pattern,
    ContentSettingsType content_type,
    const ResourceIdentifier& resource_identifier,
    base::Value* value) {
  if (read_only_)
    return false;
  value_map_.clear();
  value_map_.SetValue(requesting_url_pattern,
                      embedding_url_pattern,
                      content_type,
                      resource_identifier,
                      value);
  return true;
}

void MockProvider::ShutdownOnUIThread() {
  RemoveAllObservers();
}

}  // namespace content_settings