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

Side by Side Diff: components/content_settings/core/common/content_settings.cc

Issue 2938163002: Store base::Value in ContentSettingPatternSource instead of an enum (Closed)
Patch Set: moar rebase, raymes comments Created 3 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "components/content_settings/core/common/content_settings.h" 5 #include "components/content_settings/core/common/content_settings.h"
6 6
7 #include "base/containers/hash_tables.h" 7 #include "base/containers/hash_tables.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "components/content_settings/core/common/content_settings_utils.h"
12 13
13 ContentSetting IntToContentSetting(int content_setting) { 14 ContentSetting IntToContentSetting(int content_setting) {
14 return ((content_setting < 0) || 15 return ((content_setting < 0) ||
15 (content_setting >= CONTENT_SETTING_NUM_SETTINGS)) ? 16 (content_setting >= CONTENT_SETTING_NUM_SETTINGS)) ?
16 CONTENT_SETTING_DEFAULT : static_cast<ContentSetting>(content_setting); 17 CONTENT_SETTING_DEFAULT : static_cast<ContentSetting>(content_setting);
17 } 18 }
18 19
19 struct HistogramValue { 20 struct HistogramValue {
20 ContentSettingsType type; 21 ContentSettingsType type;
21 int value; 22 int value;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 72 }
72 73
73 DCHECK(base::ContainsKey(kMap, content_setting)); 74 DCHECK(base::ContainsKey(kMap, content_setting));
74 *num_values = arraysize(kHistogramValue); 75 *num_values = arraysize(kHistogramValue);
75 return kMap[content_setting]; 76 return kMap[content_setting];
76 } 77 }
77 78
78 ContentSettingPatternSource::ContentSettingPatternSource( 79 ContentSettingPatternSource::ContentSettingPatternSource(
79 const ContentSettingsPattern& primary_pattern, 80 const ContentSettingsPattern& primary_pattern,
80 const ContentSettingsPattern& secondary_pattern, 81 const ContentSettingsPattern& secondary_pattern,
81 ContentSetting setting, 82 std::unique_ptr<base::Value> setting_value,
82 const std::string& source, 83 const std::string& source,
83 bool incognito) 84 bool incognito)
84 : primary_pattern(primary_pattern), 85 : primary_pattern(primary_pattern),
85 secondary_pattern(secondary_pattern), 86 secondary_pattern(secondary_pattern),
86 setting(setting), 87 setting_value(std::move(setting_value)),
87 source(source), 88 source(source),
88 incognito(incognito) {} 89 incognito(incognito) {}
89 90
90 ContentSettingPatternSource::ContentSettingPatternSource() 91 ContentSettingPatternSource::ContentSettingPatternSource() : incognito(false) {}
91 : setting(CONTENT_SETTING_DEFAULT), incognito(false) { 92
93 ContentSettingPatternSource::ContentSettingPatternSource(
94 const ContentSettingPatternSource& other) {
95 primary_pattern = other.primary_pattern;
96 secondary_pattern = other.secondary_pattern;
97 if (other.setting_value)
98 setting_value = base::MakeUnique<base::Value>(*(other.setting_value));
99 source = other.source;
100 incognito = other.incognito;
raymes 2017/06/28 01:15:43 nit: I think we can reuse code here by just callin
tbansal1 2017/06/28 14:16:40 Done.
92 } 101 }
93 102
94 ContentSettingPatternSource::ContentSettingPatternSource( 103 ContentSettingPatternSource& ContentSettingPatternSource::operator=(
95 const ContentSettingPatternSource& other) = default; 104 const ContentSettingPatternSource& other) {
105 primary_pattern = other.primary_pattern;
106 secondary_pattern = other.secondary_pattern;
107 if (other.setting_value)
108 setting_value = base::MakeUnique<base::Value>(*(other.setting_value));
109 source = other.source;
110 incognito = other.incognito;
111 return *this;
112 }
113
114 ContentSettingPatternSource::~ContentSettingPatternSource() {}
115
116 ContentSetting ContentSettingPatternSource::GetContentSetting() const {
117 return content_settings::ValueToContentSetting(setting_value.get());
118 }
96 119
97 RendererContentSettingRules::RendererContentSettingRules() {} 120 RendererContentSettingRules::RendererContentSettingRules() {}
98 121
99 RendererContentSettingRules::~RendererContentSettingRules() {} 122 RendererContentSettingRules::~RendererContentSettingRules() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698