| Index: components/content_settings/core/common/content_settings_utils.cc
|
| diff --git a/components/content_settings/core/common/content_settings_utils.cc b/components/content_settings/core/common/content_settings_utils.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3f86905a69b0c11e206c0edffe5d0ad471d182e5
|
| --- /dev/null
|
| +++ b/components/content_settings/core/common/content_settings_utils.cc
|
| @@ -0,0 +1,47 @@
|
| +// Copyright 2017 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 "components/content_settings/core/common/content_settings_utils.h"
|
| +
|
| +#include "base/memory/ptr_util.h"
|
| +#include "base/values.h"
|
| +
|
| +namespace content_settings {
|
| +
|
| +namespace {
|
| +
|
| +// Converts a |Value| to a |ContentSetting|. Returns true if |value| encodes
|
| +// a valid content setting, false otherwise. Note that |CONTENT_SETTING_DEFAULT|
|
| +// is encoded as a NULL value, so it is not allowed as an integer value.
|
| +bool ParseContentSettingValue(const base::Value* value,
|
| + ContentSetting* setting) {
|
| + if (!value) {
|
| + *setting = CONTENT_SETTING_DEFAULT;
|
| + return true;
|
| + }
|
| + int int_value = -1;
|
| + if (!value->GetAsInteger(&int_value))
|
| + return false;
|
| + *setting = IntToContentSetting(int_value);
|
| + return *setting != CONTENT_SETTING_DEFAULT;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +ContentSetting ValueToContentSetting(const base::Value* value) {
|
| + ContentSetting setting = CONTENT_SETTING_DEFAULT;
|
| + bool valid = ParseContentSettingValue(value, &setting);
|
| + DCHECK(valid);
|
| + return setting;
|
| +}
|
| +
|
| +std::unique_ptr<base::Value> ContentSettingToValue(ContentSetting setting) {
|
| + if (setting <= CONTENT_SETTING_DEFAULT ||
|
| + setting >= CONTENT_SETTING_NUM_SETTINGS) {
|
| + return nullptr;
|
| + }
|
| + return base::MakeUnique<base::Value>(setting);
|
| +}
|
| +
|
| +} // namespace content_settings
|
|
|