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

Side by Side Diff: chrome/browser/extensions/extension_web_ui.cc

Issue 2740143002: Change base::Value::ListStorage to std::vector<base::Value> (Closed)
Patch Set: Comment Updates Created 3 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/extension_web_ui.h" 5 #include "chrome/browser/extensions/extension_web_ui.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // Iterates over |list| and: 59 // Iterates over |list| and:
60 // - Converts any entries of the form <entry> to 60 // - Converts any entries of the form <entry> to
61 // { 'entry': <entry>, 'active': true }. 61 // { 'entry': <entry>, 'active': true }.
62 // - Removes any duplicate entries. 62 // - Removes any duplicate entries.
63 // We do the conversion because we previously stored these values as strings 63 // We do the conversion because we previously stored these values as strings
64 // rather than objects. 64 // rather than objects.
65 // TODO(devlin): Remove the conversion once everyone's updated. 65 // TODO(devlin): Remove the conversion once everyone's updated.
66 void InitializeOverridesList(base::ListValue* list) { 66 void InitializeOverridesList(base::ListValue* list) {
67 base::ListValue migrated; 67 base::ListValue migrated;
68 std::set<std::string> seen_entries; 68 std::set<std::string> seen_entries;
69 for (const auto& val : *list) { 69 for (auto& val : *list) {
70 std::unique_ptr<base::DictionaryValue> new_dict( 70 std::unique_ptr<base::DictionaryValue> new_dict(
71 new base::DictionaryValue()); 71 new base::DictionaryValue());
72 std::string entry_name; 72 std::string entry_name;
73 base::DictionaryValue* existing_dict = nullptr; 73 base::DictionaryValue* existing_dict = nullptr;
74 if (val->GetAsDictionary(&existing_dict)) { 74 if (val.GetAsDictionary(&existing_dict)) {
75 bool success = existing_dict->GetString(kEntry, &entry_name); 75 bool success = existing_dict->GetString(kEntry, &entry_name);
76 if (!success) // See comment about CHECK(success) in ForEachOverrideList. 76 if (!success) // See comment about CHECK(success) in ForEachOverrideList.
77 continue; 77 continue;
78 new_dict->Swap(existing_dict); 78 new_dict->Swap(existing_dict);
79 } else if (val->GetAsString(&entry_name)) { 79 } else if (val.GetAsString(&entry_name)) {
80 new_dict->SetString(kEntry, entry_name); 80 new_dict->SetString(kEntry, entry_name);
81 new_dict->SetBoolean(kActive, true); 81 new_dict->SetBoolean(kActive, true);
82 } else { 82 } else {
83 NOTREACHED(); 83 NOTREACHED();
84 continue; 84 continue;
85 } 85 }
86 86
87 if (seen_entries.count(entry_name) == 0) { 87 if (seen_entries.count(entry_name) == 0) {
88 seen_entries.insert(entry_name); 88 seen_entries.insert(entry_name);
89 migrated.Append(std::move(new_dict)); 89 migrated.Append(std::move(new_dict));
90 } 90 }
91 } 91 }
92 92
93 list->Swap(&migrated); 93 list->Swap(&migrated);
94 } 94 }
95 95
96 // Adds |override| to |list|, or, if there's already an entry for the override, 96 // Adds |override| to |list|, or, if there's already an entry for the override,
97 // marks it as active. 97 // marks it as active.
98 void AddOverridesToList(base::ListValue* list, 98 void AddOverridesToList(base::ListValue* list,
99 const std::string& override) { 99 const std::string& override) {
100 for (const auto& val : *list) { 100 for (auto& val : *list) {
101 base::DictionaryValue* dict = nullptr; 101 base::DictionaryValue* dict = nullptr;
102 std::string entry; 102 std::string entry;
103 if (!val->GetAsDictionary(&dict) || !dict->GetString(kEntry, &entry)) { 103 if (!val.GetAsDictionary(&dict) || !dict->GetString(kEntry, &entry)) {
104 NOTREACHED(); 104 NOTREACHED();
105 continue; 105 continue;
106 } 106 }
107 if (entry == override) { 107 if (entry == override) {
108 dict->SetBoolean(kActive, true); 108 dict->SetBoolean(kActive, true);
109 return; // All done! 109 return; // All done!
110 } 110 }
111 } 111 }
112 112
113 auto dict = base::MakeUnique<base::DictionaryValue>(); 113 auto dict = base::MakeUnique<base::DictionaryValue>();
114 dict->SetString(kEntry, override); 114 dict->SetString(kEntry, override);
115 dict->SetBoolean(kActive, true); 115 dict->SetBoolean(kActive, true);
116 // Add the entry to the front of the list. 116 // Add the entry to the front of the list.
117 list->Insert(0, std::move(dict)); 117 list->Insert(0, std::move(dict));
118 } 118 }
119 119
120 // Validates that each entry in |list| contains a valid url and points to an 120 // Validates that each entry in |list| contains a valid url and points to an
121 // extension contained in |all_extensions| (and, if not, removes it). 121 // extension contained in |all_extensions| (and, if not, removes it).
122 void ValidateOverridesList(const extensions::ExtensionSet* all_extensions, 122 void ValidateOverridesList(const extensions::ExtensionSet* all_extensions,
123 base::ListValue* list) { 123 base::ListValue* list) {
124 base::ListValue migrated; 124 base::ListValue migrated;
125 for (const auto& val : *list) { 125 for (auto& val : *list) {
126 base::DictionaryValue* dict = nullptr; 126 base::DictionaryValue* dict = nullptr;
127 std::string entry; 127 std::string entry;
128 if (!val->GetAsDictionary(&dict) || !dict->GetString(kEntry, &entry)) { 128 if (!val.GetAsDictionary(&dict) || !dict->GetString(kEntry, &entry)) {
129 NOTREACHED(); 129 NOTREACHED();
130 continue; 130 continue;
131 } 131 }
132 std::unique_ptr<base::DictionaryValue> new_dict( 132 std::unique_ptr<base::DictionaryValue> new_dict(
133 new base::DictionaryValue()); 133 new base::DictionaryValue());
134 new_dict->Swap(dict); 134 new_dict->Swap(dict);
135 GURL override_url(entry); 135 GURL override_url(entry);
136 if (!override_url.is_valid()) 136 if (!override_url.is_valid())
137 continue; 137 continue;
138 138
(...skipping 29 matching lines...) Expand all
168 enum UpdateBehavior { 168 enum UpdateBehavior {
169 UPDATE_DEACTIVATE, // Mark 'active' as false. 169 UPDATE_DEACTIVATE, // Mark 'active' as false.
170 UPDATE_REMOVE, // Remove the entry from the list. 170 UPDATE_REMOVE, // Remove the entry from the list.
171 }; 171 };
172 172
173 // Updates the entry (if any) for |override_url| in |overrides_list| according 173 // Updates the entry (if any) for |override_url| in |overrides_list| according
174 // to |behavior|. Returns true if anything changed. 174 // to |behavior|. Returns true if anything changed.
175 bool UpdateOverridesList(base::ListValue* overrides_list, 175 bool UpdateOverridesList(base::ListValue* overrides_list,
176 const std::string& override_url, 176 const std::string& override_url,
177 UpdateBehavior behavior) { 177 UpdateBehavior behavior) {
178 base::ListValue::iterator iter = 178 base::ListValue::iterator iter = std::find_if(
179 std::find_if(overrides_list->begin(), overrides_list->end(), 179 overrides_list->begin(), overrides_list->end(),
180 [&override_url](const std::unique_ptr<base::Value>& value) { 180 [&override_url](const base::Value& value) {
181 std::string entry; 181 std::string entry;
182 const base::DictionaryValue* dict = nullptr; 182 const base::DictionaryValue* dict = nullptr;
183 return value->GetAsDictionary(&dict) && 183 return value.GetAsDictionary(&dict) &&
184 dict->GetString(kEntry, &entry) && 184 dict->GetString(kEntry, &entry) && entry == override_url;
185 entry == override_url; 185 });
186 });
187 if (iter != overrides_list->end()) { 186 if (iter != overrides_list->end()) {
188 switch (behavior) { 187 switch (behavior) {
189 case UPDATE_DEACTIVATE: { 188 case UPDATE_DEACTIVATE: {
190 base::DictionaryValue* dict = nullptr; 189 base::DictionaryValue* dict = nullptr;
191 bool success = (*iter)->GetAsDictionary(&dict); 190 bool success = iter->GetAsDictionary(&dict);
192 // See comment about CHECK(success) in ForEachOverrideList. 191 // See comment about CHECK(success) in ForEachOverrideList.
193 if (success) { 192 if (success) {
194 dict->SetBoolean(kActive, false); 193 dict->SetBoolean(kActive, false);
195 break; 194 break;
196 } 195 }
197 // Else fall through and erase the broken pref. 196 // Else fall through and erase the broken pref.
198 } 197 }
199 case UPDATE_REMOVE: 198 case UPDATE_REMOVE:
200 overrides_list->Erase(iter, nullptr); 199 overrides_list->Erase(iter, nullptr);
201 break; 200 break;
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 // chrome://bookmarks/#1 for display in the omnibox. 418 // chrome://bookmarks/#1 for display in the omnibox.
420 for (base::DictionaryValue::Iterator dict_iter(*overrides); 419 for (base::DictionaryValue::Iterator dict_iter(*overrides);
421 !dict_iter.IsAtEnd(); dict_iter.Advance()) { 420 !dict_iter.IsAtEnd(); dict_iter.Advance()) {
422 const base::ListValue* url_list = nullptr; 421 const base::ListValue* url_list = nullptr;
423 if (!dict_iter.value().GetAsList(&url_list)) 422 if (!dict_iter.value().GetAsList(&url_list))
424 continue; 423 continue;
425 424
426 for (base::ListValue::const_iterator list_iter = url_list->begin(); 425 for (base::ListValue::const_iterator list_iter = url_list->begin();
427 list_iter != url_list->end(); ++list_iter) { 426 list_iter != url_list->end(); ++list_iter) {
428 const base::DictionaryValue* dict = nullptr; 427 const base::DictionaryValue* dict = nullptr;
429 if (!(*list_iter)->GetAsDictionary(&dict)) 428 if (!list_iter->GetAsDictionary(&dict))
430 continue; 429 continue;
431 std::string override; 430 std::string override;
432 if (!dict->GetString(kEntry, &override)) 431 if (!dict->GetString(kEntry, &override))
433 continue; 432 continue;
434 if (base::StartsWith(url->spec(), override, 433 if (base::StartsWith(url->spec(), override,
435 base::CompareCase::SENSITIVE)) { 434 base::CompareCase::SENSITIVE)) {
436 GURL original_url(content::kChromeUIScheme + std::string("://") + 435 GURL original_url(content::kChromeUIScheme + std::string("://") +
437 dict_iter.key() + 436 dict_iter.key() +
438 url->spec().substr(override.length())); 437 url->spec().substr(override.length()));
439 *url = original_url; 438 *url = original_url;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE, 524 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE,
526 gfx::Size(pixel_size, pixel_size), 525 gfx::Size(pixel_size, pixel_size),
527 resource_scale_factor)); 526 resource_scale_factor));
528 } 527 }
529 528
530 // LoadImagesAsync actually can run callback synchronously. We want to force 529 // LoadImagesAsync actually can run callback synchronously. We want to force
531 // async. 530 // async.
532 extensions::ImageLoader::Get(profile)->LoadImagesAsync( 531 extensions::ImageLoader::Get(profile)->LoadImagesAsync(
533 extension, info_list, base::Bind(&RunFaviconCallbackAsync, callback)); 532 extension, info_list, base::Bind(&RunFaviconCallbackAsync, callback));
534 } 533 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698