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

Side by Side Diff: chrome/browser/policy/managed_bookmarks_policy_handler.cc

Issue 2809023003: Reland of Change base::Value::ListStorage to std::vector<base::Value> (Closed)
Patch Set: Created 3 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/policy/managed_bookmarks_policy_handler.h" 5 #include "chrome/browser/policy/managed_bookmarks_policy_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "components/bookmarks/common/bookmark_pref_names.h" 10 #include "components/bookmarks/common/bookmark_pref_names.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 GetFolderName(*list)); 44 GetFolderName(*list));
45 FilterBookmarks(list); 45 FilterBookmarks(list);
46 prefs->SetValue(bookmarks::prefs::kManagedBookmarks, std::move(value)); 46 prefs->SetValue(bookmarks::prefs::kManagedBookmarks, std::move(value));
47 } 47 }
48 48
49 std::string 49 std::string
50 ManagedBookmarksPolicyHandler::GetFolderName(const base::ListValue& list) { 50 ManagedBookmarksPolicyHandler::GetFolderName(const base::ListValue& list) {
51 // Iterate over the list, and try to find the FolderName. 51 // Iterate over the list, and try to find the FolderName.
52 for (const auto& el : list) { 52 for (const auto& el : list) {
53 const base::DictionaryValue* dict = NULL; 53 const base::DictionaryValue* dict = NULL;
54 if (!el || !el->GetAsDictionary(&dict)) continue; 54 if (!el.GetAsDictionary(&dict))
55 continue;
55 56
56 std::string name; 57 std::string name;
57 if (dict->GetString(ManagedBookmarksTracker::kFolderName, &name)) { 58 if (dict->GetString(ManagedBookmarksTracker::kFolderName, &name)) {
58 return name; 59 return name;
59 } 60 }
60 } 61 }
61 62
62 // FolderName not present. 63 // FolderName not present.
63 return std::string(); 64 return std::string();
64 } 65 }
65 66
66 void ManagedBookmarksPolicyHandler::FilterBookmarks(base::ListValue* list) { 67 void ManagedBookmarksPolicyHandler::FilterBookmarks(base::ListValue* list) {
67 // Remove any non-conforming values found. 68 // Remove any non-conforming values found.
68 base::ListValue::iterator it = list->begin(); 69 base::ListValue::iterator it = list->begin();
69 while (it != list->end()) { 70 while (it != list->end()) {
70 base::DictionaryValue* dict = NULL; 71 base::DictionaryValue* dict = NULL;
71 if (!*it || !(*it)->GetAsDictionary(&dict)) { 72 if (!it->GetAsDictionary(&dict)) {
72 it = list->Erase(it, NULL); 73 it = list->Erase(it, NULL);
73 continue; 74 continue;
74 } 75 }
75 76
76 std::string name; 77 std::string name;
77 std::string url; 78 std::string url;
78 base::ListValue* children = NULL; 79 base::ListValue* children = NULL;
79 // Every bookmark must have a name, and then either a URL of a list of 80 // Every bookmark must have a name, and then either a URL of a list of
80 // child bookmarks. 81 // child bookmarks.
81 if (!dict->GetString(ManagedBookmarksTracker::kName, &name) || 82 if (!dict->GetString(ManagedBookmarksTracker::kName, &name) ||
(...skipping 16 matching lines...) Expand all
98 continue; 99 continue;
99 } 100 }
100 dict->SetString(ManagedBookmarksTracker::kUrl, gurl.spec()); 101 dict->SetString(ManagedBookmarksTracker::kUrl, gurl.spec());
101 } 102 }
102 103
103 ++it; 104 ++it;
104 } 105 }
105 } 106 }
106 107
107 } // namespace policy 108 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/plugins/plugin_prefs.cc ('k') | chrome/browser/policy/policy_prefs_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698