| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bookmarks/bookmark_extension_helpers.h" | 5 #include "chrome/browser/bookmarks/bookmark_extension_helpers.h" |
| 6 | 6 |
| 7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_extension_api_constants.h" | 9 #include "chrome/browser/bookmarks/bookmark_extension_api_constants.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 11 | 11 |
| 12 namespace keys = bookmark_extension_api_constants; | 12 namespace keys = bookmark_extension_api_constants; |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 void AddNode(const BookmarkNode* node, | 16 void AddNode(const BookmarkNode* node, |
| 17 base::ListValue* list, | 17 base::ListValue* list, |
| 18 bool recurse, | 18 bool recurse, |
| 19 bool only_folders) { | 19 bool only_folders) { |
| 20 if (node->IsVisible()) { | 20 base::DictionaryValue* dict = bookmark_extension_helpers::GetNodeDictionary( |
| 21 base::DictionaryValue* dict = bookmark_extension_helpers::GetNodeDictionary( | 21 node, recurse, only_folders); |
| 22 node, recurse, only_folders); | 22 list->Append(dict); |
| 23 list->Append(dict); | |
| 24 } | |
| 25 } | 23 } |
| 26 | 24 |
| 27 } // namespace | 25 } // namespace |
| 28 | 26 |
| 29 namespace bookmark_extension_helpers { | 27 namespace bookmark_extension_helpers { |
| 30 | 28 |
| 31 base::DictionaryValue* GetNodeDictionary(const BookmarkNode* node, | 29 base::DictionaryValue* GetNodeDictionary(const BookmarkNode* node, |
| 32 bool recurse, | 30 bool recurse, |
| 33 bool only_folders) { | 31 bool only_folders) { |
| 34 base::DictionaryValue* dict = new base::DictionaryValue; | 32 base::DictionaryValue* dict = new base::DictionaryValue; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 54 if (!node->date_added().is_null()) { | 52 if (!node->date_added().is_null()) { |
| 55 // Javascript Date wants milliseconds since the epoch, ToDoubleT is seconds. | 53 // Javascript Date wants milliseconds since the epoch, ToDoubleT is seconds. |
| 56 dict->SetDouble(keys::kDateAddedKey, | 54 dict->SetDouble(keys::kDateAddedKey, |
| 57 floor(node->date_added().ToDoubleT() * 1000)); | 55 floor(node->date_added().ToDoubleT() * 1000)); |
| 58 } | 56 } |
| 59 | 57 |
| 60 if (recurse && node->is_folder()) { | 58 if (recurse && node->is_folder()) { |
| 61 base::ListValue* children = new base::ListValue; | 59 base::ListValue* children = new base::ListValue; |
| 62 for (int i = 0; i < node->child_count(); ++i) { | 60 for (int i = 0; i < node->child_count(); ++i) { |
| 63 const BookmarkNode* child = node->GetChild(i); | 61 const BookmarkNode* child = node->GetChild(i); |
| 64 if (child->IsVisible() && (!only_folders || child->is_folder())) { | 62 if (!only_folders || child->is_folder()) { |
| 65 DictionaryValue* dict = GetNodeDictionary(child, true, only_folders); | 63 DictionaryValue* dict = GetNodeDictionary(child, true, only_folders); |
| 66 children->Append(dict); | 64 children->Append(dict); |
| 67 } | 65 } |
| 68 } | 66 } |
| 69 dict->Set(keys::kChildrenKey, children); | 67 dict->Set(keys::kChildrenKey, children); |
| 70 } | 68 } |
| 71 return dict; | 69 return dict; |
| 72 } | 70 } |
| 73 | 71 |
| 74 void AddNode(const BookmarkNode* node, base::ListValue* list, bool recurse) { | 72 void AddNode(const BookmarkNode* node, base::ListValue* list, bool recurse) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 98 *error = keys::kFolderNotEmptyError; | 96 *error = keys::kFolderNotEmptyError; |
| 99 return false; | 97 return false; |
| 100 } | 98 } |
| 101 | 99 |
| 102 const BookmarkNode* parent = node->parent(); | 100 const BookmarkNode* parent = node->parent(); |
| 103 model->Remove(parent, parent->GetIndexOf(node)); | 101 model->Remove(parent, parent->GetIndexOf(node)); |
| 104 return true; | 102 return true; |
| 105 } | 103 } |
| 106 | 104 |
| 107 } // namespace bookmark_extension_helpers | 105 } // namespace bookmark_extension_helpers |
| OLD | NEW |