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

Side by Side Diff: chrome/browser/permissions/chooser_context_base.cc

Issue 2000803003: Use std::unique_ptr for base::DictionaryValue and base::ListValue's internal store. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More fixes Created 4 years, 7 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/permissions/chooser_context_base.h" 5 #include "chrome/browser/permissions/chooser_context_base.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 GetWebsiteSetting(requesting_origin, embedding_origin); 48 GetWebsiteSetting(requesting_origin, embedding_origin);
49 std::unique_ptr<base::Value> objects; 49 std::unique_ptr<base::Value> objects;
50 if (!setting->Remove(kObjectListKey, &objects)) 50 if (!setting->Remove(kObjectListKey, &objects))
51 return results; 51 return results;
52 52
53 std::unique_ptr<base::ListValue> object_list = 53 std::unique_ptr<base::ListValue> object_list =
54 base::ListValue::From(std::move(objects)); 54 base::ListValue::From(std::move(objects));
55 if (!object_list) 55 if (!object_list)
56 return results; 56 return results;
57 57
58 for (base::ListValue::iterator it = object_list->begin(); 58 for (auto& object : *object_list) {
59 it != object_list->end(); ++it) {
60 // Steal ownership of |object| from |object_list|. 59 // Steal ownership of |object| from |object_list|.
61 std::unique_ptr<base::Value> object(*it);
62 *it = nullptr;
63
64 std::unique_ptr<base::DictionaryValue> object_dict = 60 std::unique_ptr<base::DictionaryValue> object_dict =
65 base::DictionaryValue::From(std::move(object)); 61 base::DictionaryValue::From(std::move(object));
66 if (object_dict && IsValidObject(*object_dict)) 62 if (object_dict && IsValidObject(*object_dict))
67 results.push_back(std::move(object_dict)); 63 results.push_back(std::move(object_dict));
68 } 64 }
69 return results; 65 return results;
70 } 66 }
71 67
72 std::vector<std::unique_ptr<ChooserContextBase::Object>> 68 std::vector<std::unique_ptr<ChooserContextBase::Object>>
73 ChooserContextBase::GetAllGrantedObjects() { 69 ChooserContextBase::GetAllGrantedObjects() {
74 ContentSettingsForOneType content_settings; 70 ContentSettingsForOneType content_settings;
75 host_content_settings_map_->GetSettingsForOneType( 71 host_content_settings_map_->GetSettingsForOneType(
76 data_content_settings_type_, std::string(), &content_settings); 72 data_content_settings_type_, std::string(), &content_settings);
77 73
78 std::vector<std::unique_ptr<Object>> results; 74 std::vector<std::unique_ptr<Object>> results;
79 for (const ContentSettingPatternSource& content_setting : content_settings) { 75 for (const ContentSettingPatternSource& content_setting : content_settings) {
80 GURL requesting_origin(content_setting.primary_pattern.ToString()); 76 GURL requesting_origin(content_setting.primary_pattern.ToString());
81 GURL embedding_origin(content_setting.secondary_pattern.ToString()); 77 GURL embedding_origin(content_setting.secondary_pattern.ToString());
82 if (!requesting_origin.is_valid() || !embedding_origin.is_valid()) 78 if (!requesting_origin.is_valid() || !embedding_origin.is_valid())
83 continue; 79 continue;
84 80
85 std::unique_ptr<base::DictionaryValue> setting = 81 std::unique_ptr<base::DictionaryValue> setting =
86 GetWebsiteSetting(requesting_origin, embedding_origin); 82 GetWebsiteSetting(requesting_origin, embedding_origin);
87 base::ListValue* object_list; 83 base::ListValue* object_list;
88 if (!setting->GetList(kObjectListKey, &object_list)) 84 if (!setting->GetList(kObjectListKey, &object_list))
89 continue; 85 continue;
90 86
91 for (base::Value* object : *object_list) { 87 for (const auto& object : *object_list) {
92 base::DictionaryValue* object_dict; 88 base::DictionaryValue* object_dict;
93 if (!object->GetAsDictionary(&object_dict) || 89 if (!object->GetAsDictionary(&object_dict) ||
94 !IsValidObject(*object_dict)) { 90 !IsValidObject(*object_dict)) {
95 continue; 91 continue;
96 } 92 }
97 93
98 results.push_back(base::WrapUnique( 94 results.push_back(base::WrapUnique(
99 new Object(requesting_origin, embedding_origin, object_dict, 95 new Object(requesting_origin, embedding_origin, object_dict,
100 content_setting.source, content_setting.incognito))); 96 content_setting.source, content_setting.incognito)));
101 } 97 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 return value; 148 return value;
153 } 149 }
154 150
155 void ChooserContextBase::SetWebsiteSetting(const GURL& requesting_origin, 151 void ChooserContextBase::SetWebsiteSetting(const GURL& requesting_origin,
156 const GURL& embedding_origin, 152 const GURL& embedding_origin,
157 std::unique_ptr<base::Value> value) { 153 std::unique_ptr<base::Value> value) {
158 host_content_settings_map_->SetWebsiteSettingDefaultScope( 154 host_content_settings_map_->SetWebsiteSettingDefaultScope(
159 requesting_origin, embedding_origin, data_content_settings_type_, 155 requesting_origin, embedding_origin, data_content_settings_type_,
160 std::string(), value.release()); 156 std::string(), value.release());
161 } 157 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/plugin_metrics_provider.cc ('k') | chrome/browser/plugins/plugin_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698