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

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

Issue 2938163002: Store base::Value in ContentSettingPatternSource instead of an enum (Closed)
Patch Set: ps 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/content_settings/core/common/content_settings_utils.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "base/values.h"
9 #include "components/content_settings/core/common/content_settings_types.h"
10
11 namespace content_settings {
12
13 ContentSetting ValueToContentSetting(const base::Value* value) {
14 ContentSetting setting = CONTENT_SETTING_DEFAULT;
15 bool valid = ParseContentSettingValue(value, &setting);
16 DCHECK(valid);
17 return setting;
18 }
19
20 bool ParseContentSettingValue(const base::Value* value,
21 ContentSetting* setting) {
22 if (!value) {
23 *setting = CONTENT_SETTING_DEFAULT;
24 return true;
25 }
26 int int_value = -1;
27 if (!value->GetAsInteger(&int_value))
28 return false;
29 *setting = IntToContentSetting(int_value);
30 return *setting != CONTENT_SETTING_DEFAULT;
31 }
32
33 std::unique_ptr<base::Value> ContentSettingToValue(ContentSetting setting) {
34 if (setting <= CONTENT_SETTING_DEFAULT ||
35 setting >= CONTENT_SETTING_NUM_SETTINGS) {
36 return nullptr;
37 }
38 return base::MakeUnique<base::Value>(setting);
39 }
40
41 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698