OLD | NEW |
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/supervised_user/supervised_user_bookmarks_handler.h" | 5 #include "chrome/browser/supervised_user/supervised_user_bookmarks_handler.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "components/url_fixer/url_fixer.h" | 10 #include "components/url_formatter/url_fixer.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 // Keys of relevant managed user settings. | 14 // Keys of relevant managed user settings. |
15 const char kKeyLink[] = "SupervisedBookmarkLink"; | 15 const char kKeyLink[] = "SupervisedBookmarkLink"; |
16 const char kKeyFolder[] = "SupervisedBookmarkFolder"; | 16 const char kKeyFolder[] = "SupervisedBookmarkFolder"; |
17 | 17 |
18 // Keys for elements of the bookmarks json tree. | 18 // Keys for elements of the bookmarks json tree. |
19 const char kId[] = "id"; | 19 const char kId[] = "id"; |
20 const char kName[] = "name"; | 20 const char kName[] = "name"; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 for (const Folder& folder : folders_failed) { | 180 for (const Folder& folder : folders_failed) { |
181 LOG(WARNING) << folder.id << ", " << folder.name << ", " | 181 LOG(WARNING) << folder.id << ", " << folder.name << ", " |
182 << folder.parent_id; | 182 << folder.parent_id; |
183 } | 183 } |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 void SupervisedUserBookmarksHandler::AddLinksToTree() { | 187 void SupervisedUserBookmarksHandler::AddLinksToTree() { |
188 for (const auto& link : links_) { | 188 for (const auto& link : links_) { |
189 scoped_ptr<base::DictionaryValue> node(new base::DictionaryValue); | 189 scoped_ptr<base::DictionaryValue> node(new base::DictionaryValue); |
190 GURL url = url_fixer::FixupURL(link.url, std::string()); | 190 GURL url = url_formatter::FixupURL(link.url, std::string()); |
191 if (!url.is_valid()) { | 191 if (!url.is_valid()) { |
192 LOG(WARNING) << "Got invalid URL: " << link.url; | 192 LOG(WARNING) << "Got invalid URL: " << link.url; |
193 continue; | 193 continue; |
194 } | 194 } |
195 node->SetStringWithoutPathExpansion(kUrl, url.spec()); | 195 node->SetStringWithoutPathExpansion(kUrl, url.spec()); |
196 node->SetStringWithoutPathExpansion(kName, link.name); | 196 node->SetStringWithoutPathExpansion(kName, link.name); |
197 if (!AddNodeToTree(link.parent_id, node.Pass())) { | 197 if (!AddNodeToTree(link.parent_id, node.Pass())) { |
198 LOG(WARNING) << "SupervisedUserBookmarksHandler::AddLinksToTree" | 198 LOG(WARNING) << "SupervisedUserBookmarksHandler::AddLinksToTree" |
199 << " failed to add link (url,name,parent): " | 199 << " failed to add link (url,name,parent): " |
200 << link.url << ", " << link.name << ", " << link.parent_id; | 200 << link.url << ", " << link.name << ", " << link.parent_id; |
201 } | 201 } |
202 } | 202 } |
203 } | 203 } |
204 | 204 |
205 bool SupervisedUserBookmarksHandler::AddNodeToTree( | 205 bool SupervisedUserBookmarksHandler::AddNodeToTree( |
206 int parent_id, | 206 int parent_id, |
207 scoped_ptr<base::DictionaryValue> node) { | 207 scoped_ptr<base::DictionaryValue> node) { |
208 base::ListValue* parent = FindFolder(root_.get(), parent_id); | 208 base::ListValue* parent = FindFolder(root_.get(), parent_id); |
209 if (!parent) | 209 if (!parent) |
210 return false; | 210 return false; |
211 parent->Append(node.release()); | 211 parent->Append(node.release()); |
212 return true; | 212 return true; |
213 } | 213 } |
OLD | NEW |