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

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: rebased Created 3 years, 5 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
10 namespace content_settings {
11
12 namespace {
13
14 // Converts a |Value| to a |ContentSetting|. Returns true if |value| encodes
15 // a valid content setting, false otherwise. Note that |CONTENT_SETTING_DEFAULT|
16 // is encoded as a NULL value, so it is not allowed as an integer value.
17 bool ParseContentSettingValue(const base::Value* value,
18 ContentSetting* setting) {
19 if (!value) {
20 *setting = CONTENT_SETTING_DEFAULT;
21 return true;
22 }
23 int int_value = -1;
24 if (!value->GetAsInteger(&int_value))
25 return false;
26 *setting = IntToContentSetting(int_value);
27 return *setting != CONTENT_SETTING_DEFAULT;
28 }
29
30 } // namespace
31
32 ContentSetting ValueToContentSetting(const base::Value* value) {
33 ContentSetting setting = CONTENT_SETTING_DEFAULT;
34 bool valid = ParseContentSettingValue(value, &setting);
35 DCHECK(valid);
36 return setting;
37 }
38
39 std::unique_ptr<base::Value> ContentSettingToValue(ContentSetting setting) {
40 if (setting <= CONTENT_SETTING_DEFAULT ||
41 setting >= CONTENT_SETTING_NUM_SETTINGS) {
42 return nullptr;
43 }
44 return base::MakeUnique<base::Value>(setting);
45 }
46
47 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698