| OLD | NEW |
| 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 Loading... |
| 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.GetAsDictionary(&dict)) | 54 if (!el || !el->GetAsDictionary(&dict)) continue; |
| 55 continue; | |
| 56 | 55 |
| 57 std::string name; | 56 std::string name; |
| 58 if (dict->GetString(ManagedBookmarksTracker::kFolderName, &name)) { | 57 if (dict->GetString(ManagedBookmarksTracker::kFolderName, &name)) { |
| 59 return name; | 58 return name; |
| 60 } | 59 } |
| 61 } | 60 } |
| 62 | 61 |
| 63 // FolderName not present. | 62 // FolderName not present. |
| 64 return std::string(); | 63 return std::string(); |
| 65 } | 64 } |
| 66 | 65 |
| 67 void ManagedBookmarksPolicyHandler::FilterBookmarks(base::ListValue* list) { | 66 void ManagedBookmarksPolicyHandler::FilterBookmarks(base::ListValue* list) { |
| 68 // Remove any non-conforming values found. | 67 // Remove any non-conforming values found. |
| 69 base::ListValue::iterator it = list->begin(); | 68 base::ListValue::iterator it = list->begin(); |
| 70 while (it != list->end()) { | 69 while (it != list->end()) { |
| 71 base::DictionaryValue* dict = NULL; | 70 base::DictionaryValue* dict = NULL; |
| 72 if (!it->GetAsDictionary(&dict)) { | 71 if (!*it || !(*it)->GetAsDictionary(&dict)) { |
| 73 it = list->Erase(it, NULL); | 72 it = list->Erase(it, NULL); |
| 74 continue; | 73 continue; |
| 75 } | 74 } |
| 76 | 75 |
| 77 std::string name; | 76 std::string name; |
| 78 std::string url; | 77 std::string url; |
| 79 base::ListValue* children = NULL; | 78 base::ListValue* children = NULL; |
| 80 // Every bookmark must have a name, and then either a URL of a list of | 79 // Every bookmark must have a name, and then either a URL of a list of |
| 81 // child bookmarks. | 80 // child bookmarks. |
| 82 if (!dict->GetString(ManagedBookmarksTracker::kName, &name) || | 81 if (!dict->GetString(ManagedBookmarksTracker::kName, &name) || |
| (...skipping 16 matching lines...) Expand all Loading... |
| 99 continue; | 98 continue; |
| 100 } | 99 } |
| 101 dict->SetString(ManagedBookmarksTracker::kUrl, gurl.spec()); | 100 dict->SetString(ManagedBookmarksTracker::kUrl, gurl.spec()); |
| 102 } | 101 } |
| 103 | 102 |
| 104 ++it; | 103 ++it; |
| 105 } | 104 } |
| 106 } | 105 } |
| 107 | 106 |
| 108 } // namespace policy | 107 } // namespace policy |
| OLD | NEW |