OLD | NEW |
(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 |
OLD | NEW |