| 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 "base/prefs/pref_value_map.h" | 7 #include "base/prefs/pref_value_map.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/common/net/url_fixer_upper.h" | 9 #include "chrome/common/net/url_fixer_upper.h" |
| 10 #include "components/bookmarks/browser/managed_bookmarks_tracker.h" |
| 10 #include "components/bookmarks/common/bookmark_pref_names.h" | 11 #include "components/bookmarks/common/bookmark_pref_names.h" |
| 11 #include "components/policy/core/browser/policy_error_map.h" | 12 #include "components/policy/core/browser/policy_error_map.h" |
| 12 #include "components/policy/core/common/policy_map.h" | 13 #include "components/policy/core/common/policy_map.h" |
| 13 #include "grit/components_strings.h" | 14 #include "grit/components_strings.h" |
| 14 #include "policy/policy_constants.h" | 15 #include "policy/policy_constants.h" |
| 15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 16 | 17 |
| 17 namespace policy { | 18 namespace policy { |
| 18 | 19 |
| 19 const char ManagedBookmarksPolicyHandler::kName[] = "name"; | |
| 20 const char ManagedBookmarksPolicyHandler::kUrl[] = "url"; | |
| 21 const char ManagedBookmarksPolicyHandler::kChildren[] = "children"; | |
| 22 | |
| 23 ManagedBookmarksPolicyHandler::ManagedBookmarksPolicyHandler( | 20 ManagedBookmarksPolicyHandler::ManagedBookmarksPolicyHandler( |
| 24 Schema chrome_schema) | 21 Schema chrome_schema) |
| 25 : SchemaValidatingPolicyHandler( | 22 : SchemaValidatingPolicyHandler( |
| 26 key::kManagedBookmarks, | 23 key::kManagedBookmarks, |
| 27 chrome_schema.GetKnownProperty(key::kManagedBookmarks), | 24 chrome_schema.GetKnownProperty(key::kManagedBookmarks), |
| 28 SCHEMA_ALLOW_INVALID) {} | 25 SCHEMA_ALLOW_INVALID) {} |
| 29 | 26 |
| 30 ManagedBookmarksPolicyHandler::~ManagedBookmarksPolicyHandler() {} | 27 ManagedBookmarksPolicyHandler::~ManagedBookmarksPolicyHandler() {} |
| 31 | 28 |
| 32 void ManagedBookmarksPolicyHandler::ApplyPolicySettings( | 29 void ManagedBookmarksPolicyHandler::ApplyPolicySettings( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 52 if (!*it || !(*it)->GetAsDictionary(&dict)) { | 49 if (!*it || !(*it)->GetAsDictionary(&dict)) { |
| 53 it = list->Erase(it, NULL); | 50 it = list->Erase(it, NULL); |
| 54 continue; | 51 continue; |
| 55 } | 52 } |
| 56 | 53 |
| 57 std::string name; | 54 std::string name; |
| 58 std::string url; | 55 std::string url; |
| 59 base::ListValue* children = NULL; | 56 base::ListValue* children = NULL; |
| 60 // Every bookmark must have a name, and then either a URL of a list of | 57 // Every bookmark must have a name, and then either a URL of a list of |
| 61 // child bookmarks. | 58 // child bookmarks. |
| 62 if (!dict->GetString(kName, &name) || | 59 if (!dict->GetString(ManagedBookmarksTracker::kName, &name) || |
| 63 (!dict->GetList(kChildren, &children) && | 60 (!dict->GetList(ManagedBookmarksTracker::kChildren, &children) && |
| 64 !dict->GetString(kUrl, &url))) { | 61 !dict->GetString(ManagedBookmarksTracker::kUrl, &url))) { |
| 65 it = list->Erase(it, NULL); | 62 it = list->Erase(it, NULL); |
| 66 continue; | 63 continue; |
| 67 } | 64 } |
| 68 | 65 |
| 69 if (children) { | 66 if (children) { |
| 70 // Ignore the URL if this bookmark has child nodes. | 67 // Ignore the URL if this bookmark has child nodes. |
| 71 dict->Remove(kUrl, NULL); | 68 dict->Remove(ManagedBookmarksTracker::kUrl, NULL); |
| 72 FilterBookmarks(children); | 69 FilterBookmarks(children); |
| 73 } else { | 70 } else { |
| 74 // Make sure the URL is valid before passing a bookmark to the pref. | 71 // Make sure the URL is valid before passing a bookmark to the pref. |
| 75 dict->Remove(kChildren, NULL); | 72 dict->Remove(ManagedBookmarksTracker::kChildren, NULL); |
| 76 GURL gurl = URLFixerUpper::FixupURL(url, ""); | 73 GURL gurl = URLFixerUpper::FixupURL(url, ""); |
| 77 if (!gurl.is_valid()) { | 74 if (!gurl.is_valid()) { |
| 78 it = list->Erase(it, NULL); | 75 it = list->Erase(it, NULL); |
| 79 continue; | 76 continue; |
| 80 } | 77 } |
| 81 dict->SetString(kUrl, gurl.spec()); | 78 dict->SetString(ManagedBookmarksTracker::kUrl, gurl.spec()); |
| 82 } | 79 } |
| 83 | 80 |
| 84 ++it; | 81 ++it; |
| 85 } | 82 } |
| 86 } | 83 } |
| 87 | 84 |
| 88 } // namespace policy | 85 } // namespace policy |
| OLD | NEW |