Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Side by Side Diff: chrome/browser/extensions/extension_bookmarks_module.cc

Issue 160064: Push bookmarks.remove/removeAll polymorphism into c++. fix bookmarks id schema issues (Closed)
Patch Set: presubmit Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/extension_bookmarks_module.h" 5 #include "chrome/browser/extensions/extension_bookmarks_module.h"
6 6
7 #include "base/json_writer.h" 7 #include "base/json_writer.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/bookmarks/bookmark_codec.h" 9 #include "chrome/browser/bookmarks/bookmark_codec.h"
10 #include "chrome/browser/bookmarks/bookmark_model.h" 10 #include "chrome/browser/bookmarks/bookmark_model.h"
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 for (; i != nodes.end(); ++i) { 351 for (; i != nodes.end(); ++i) {
352 const BookmarkNode* node = *i; 352 const BookmarkNode* node = *i;
353 ExtensionBookmarks::AddNode(node, json, false); 353 ExtensionBookmarks::AddNode(node, json, false);
354 } 354 }
355 355
356 result_.reset(json); 356 result_.reset(json);
357 return true; 357 return true;
358 } 358 }
359 359
360 bool RemoveBookmarkFunction::RunImpl() { 360 bool RemoveBookmarkFunction::RunImpl() {
361 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
362 const ListValue* args = static_cast<const ListValue*>(args_);
363 bool recursive = false; 361 bool recursive = false;
364 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(1, &recursive)); 362 if (name() ==
363 extension_bookmarks_module_constants::kRemoveBookmarkTreeFunction)
364 recursive = true;
365 365
366 BookmarkModel* model = profile()->GetBookmarkModel(); 366 BookmarkModel* model = profile()->GetBookmarkModel();
367 int64 id; 367 int64 id;
368 std::string id_string; 368 std::string id_string;
369 if (args->GetString(0, &id_string) && StringToInt64(id_string, &id)) { 369 if (args_->IsType(Value::TYPE_STRING) &&
370 args_->GetAsString(&id_string) &&
371 StringToInt64(id_string, &id)) {
370 return ExtensionBookmarks::RemoveNode(model, id, recursive, &error_); 372 return ExtensionBookmarks::RemoveNode(model, id, recursive, &error_);
371 } else { 373 } else {
372 ListValue* ids; 374 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
373 EXTENSION_FUNCTION_VALIDATE(args->GetList(0, &ids)); 375 ListValue* ids = static_cast<ListValue*>(args_);
374 size_t count = ids->GetSize(); 376 size_t count = ids->GetSize();
375 EXTENSION_FUNCTION_VALIDATE(count > 0); 377 EXTENSION_FUNCTION_VALIDATE(count > 0);
376 for (size_t i = 0; i < count; ++i) { 378 for (size_t i = 0; i < count; ++i) {
377 EXTENSION_FUNCTION_VALIDATE(ids->GetString(i, &id_string)); 379 EXTENSION_FUNCTION_VALIDATE(ids->GetString(i, &id_string));
378 if (!GetBookmarkIdAsInt64(id_string, &id)) 380 if (!GetBookmarkIdAsInt64(id_string, &id))
379 return false; 381 return false;
380 if (!ExtensionBookmarks::RemoveNode(model, id, recursive, &error_)) 382 if (!ExtensionBookmarks::RemoveNode(model, id, recursive, &error_))
381 return false; 383 return false;
382 } 384 }
383 return true; 385 return true;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 node == model->GetBookmarkBarNode()) { 472 node == model->GetBookmarkBarNode()) {
471 error_ = keys::kModifySpecialError; 473 error_ = keys::kModifySpecialError;
472 return false; 474 return false;
473 } 475 }
474 476
475 const BookmarkNode* parent; 477 const BookmarkNode* parent;
476 if (!destination->HasKey(keys::kParentIdKey)) { 478 if (!destination->HasKey(keys::kParentIdKey)) {
477 // Optional, defaults to current parent. 479 // Optional, defaults to current parent.
478 parent = node->GetParent(); 480 parent = node->GetParent();
479 } else { 481 } else {
480 int parentId; 482 std::string parentId_string;
481 EXTENSION_FUNCTION_VALIDATE(destination->GetInteger(keys::kParentIdKey, 483 EXTENSION_FUNCTION_VALIDATE(destination->GetString(keys::kParentIdKey,
482 &parentId)); 484 &parentId_string));
485 int64 parentId;
486 if (!GetBookmarkIdAsInt64(parentId_string, &parentId))
487 return false;
488
483 parent = model->GetNodeByID(parentId); 489 parent = model->GetNodeByID(parentId);
484 } 490 }
485 if (!parent) { 491 if (!parent) {
486 error_ = keys::kNoParentError; 492 error_ = keys::kNoParentError;
487 // TODO(erikkay) return an error message. 493 // TODO(erikkay) return an error message.
488 return false; 494 return false;
489 } 495 }
490 if (parent == model->root_node()) { 496 if (parent == model->root_node()) {
491 error_ = keys::kModifySpecialError; 497 error_ = keys::kModifySpecialError;
492 return false; 498 return false;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 } 534 }
529 if (node == model->root_node() || 535 if (node == model->root_node() ||
530 node == model->other_node() || 536 node == model->other_node() ||
531 node == model->GetBookmarkBarNode()) { 537 node == model->GetBookmarkBarNode()) {
532 error_ = keys::kModifySpecialError; 538 error_ = keys::kModifySpecialError;
533 return false; 539 return false;
534 } 540 }
535 model->SetTitle(node, title); 541 model->SetTitle(node, title);
536 return true; 542 return true;
537 } 543 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_extension_function.cc ('k') | chrome/browser/extensions/extension_function.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698