| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/api/bookmarks/bookmarks_api.h" | 5 #include "chrome/browser/extensions/api/bookmarks/bookmarks_api.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/i18n/file_util_icu.h" | 9 #include "base/i18n/file_util_icu.h" |
| 10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 303 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
| 304 } | 304 } |
| 305 | 305 |
| 306 bool BookmarksGetTreeFunction::RunImpl() { | 306 bool BookmarksGetTreeFunction::RunImpl() { |
| 307 scoped_ptr<bookmarks::Get::Params> params( | 307 scoped_ptr<bookmarks::Get::Params> params( |
| 308 bookmarks::Get::Params::Create(*args_)); | 308 bookmarks::Get::Params::Create(*args_)); |
| 309 EXTENSION_FUNCTION_VALIDATE(params.get()); | 309 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 310 | 310 |
| 311 std::vector<linked_ptr<BookmarkTreeNode> > nodes; | 311 std::vector<linked_ptr<BookmarkTreeNode> > nodes; |
| 312 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 312 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 313 if (params->id_or_id_list_type == | 313 if (params->id_or_id_list.as_array) { |
| 314 bookmarks::Get::Params::ID_OR_ID_LIST_ARRAY) { | 314 std::vector<std::string>* ids = params->id_or_id_list.as_array.get(); |
| 315 std::vector<std::string>* ids = params->id_or_id_list_array.get(); | |
| 316 size_t count = ids->size(); | 315 size_t count = ids->size(); |
| 317 EXTENSION_FUNCTION_VALIDATE(count > 0); | 316 EXTENSION_FUNCTION_VALIDATE(count > 0); |
| 318 for (size_t i = 0; i < count; ++i) { | 317 for (size_t i = 0; i < count; ++i) { |
| 319 int64 id; | 318 int64 id; |
| 320 if (!GetBookmarkIdAsInt64(ids->at(i), &id)) | 319 if (!GetBookmarkIdAsInt64(ids->at(i), &id)) |
| 321 return false; | 320 return false; |
| 322 const BookmarkNode* node = model->GetNodeByID(id); | 321 const BookmarkNode* node = model->GetNodeByID(id); |
| 323 if (!node) { | 322 if (!node) { |
| 324 error_ = keys::kNoNodeError; | 323 error_ = keys::kNoNodeError; |
| 325 return false; | 324 return false; |
| 326 } else { | 325 } else { |
| 327 bookmark_api_helpers::AddNode(node, &nodes, false); | 326 bookmark_api_helpers::AddNode(node, &nodes, false); |
| 328 } | 327 } |
| 329 } | 328 } |
| 330 } else { | 329 } else { |
| 331 int64 id; | 330 int64 id; |
| 332 if (!GetBookmarkIdAsInt64(*params->id_or_id_list_string, &id)) | 331 if (!GetBookmarkIdAsInt64(*params->id_or_id_list.as_string, &id)) |
| 333 return false; | 332 return false; |
| 334 const BookmarkNode* node = model->GetNodeByID(id); | 333 const BookmarkNode* node = model->GetNodeByID(id); |
| 335 if (!node) { | 334 if (!node) { |
| 336 error_ = keys::kNoNodeError; | 335 error_ = keys::kNoNodeError; |
| 337 return false; | 336 return false; |
| 338 } | 337 } |
| 339 bookmark_api_helpers::AddNode(node, &nodes, false); | 338 bookmark_api_helpers::AddNode(node, &nodes, false); |
| 340 } | 339 } |
| 341 | 340 |
| 342 results_ = bookmarks::Get::Results::Create(nodes); | 341 results_ = bookmarks::Get::Results::Create(nodes); |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 #if !defined(OS_ANDROID) | 986 #if !defined(OS_ANDROID) |
| 988 // Android does not have support for the standard exporter. | 987 // Android does not have support for the standard exporter. |
| 989 // TODO(jgreenwald): remove ifdef once extensions are no longer built on | 988 // TODO(jgreenwald): remove ifdef once extensions are no longer built on |
| 990 // Android. | 989 // Android. |
| 991 bookmark_html_writer::WriteBookmarks(profile(), path, NULL); | 990 bookmark_html_writer::WriteBookmarks(profile(), path, NULL); |
| 992 #endif | 991 #endif |
| 993 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 992 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
| 994 } | 993 } |
| 995 | 994 |
| 996 } // namespace extensions | 995 } // namespace extensions |
| OLD | NEW |