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

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

Powered by Google App Engine
This is Rietveld 408576698