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

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

Issue 377036: Fix memory leak in AsyncExtensionFunction. (Closed)
Patch Set: feedback Created 11 years, 1 month 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/json_writer.h" 7 #include "base/json/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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 base::JSONWriter::Write(&args, false, &json_args); 270 base::JSONWriter::Write(&args, false, &json_args);
271 DispatchEvent(model->profile(), 271 DispatchEvent(model->profile(),
272 keys::kOnBookmarkChildrenReordered, 272 keys::kOnBookmarkChildrenReordered,
273 json_args); 273 json_args);
274 } 274 }
275 275
276 bool GetBookmarksFunction::RunImpl() { 276 bool GetBookmarksFunction::RunImpl() {
277 BookmarkModel* model = profile()->GetBookmarkModel(); 277 BookmarkModel* model = profile()->GetBookmarkModel();
278 scoped_ptr<ListValue> json(new ListValue()); 278 scoped_ptr<ListValue> json(new ListValue());
279 if (args_->IsType(Value::TYPE_LIST)) { 279 if (args_->IsType(Value::TYPE_LIST)) {
280 ListValue* ids = static_cast<ListValue*>(args_); 280 const ListValue* ids = args_as_list();
281 size_t count = ids->GetSize(); 281 size_t count = ids->GetSize();
282 EXTENSION_FUNCTION_VALIDATE(count > 0); 282 EXTENSION_FUNCTION_VALIDATE(count > 0);
283 for (size_t i = 0; i < count; ++i) { 283 for (size_t i = 0; i < count; ++i) {
284 int64 id; 284 int64 id;
285 std::string id_string; 285 std::string id_string;
286 EXTENSION_FUNCTION_VALIDATE(ids->GetString(i, &id_string)); 286 EXTENSION_FUNCTION_VALIDATE(ids->GetString(i, &id_string));
287 if (!GetBookmarkIdAsInt64(id_string, &id)) 287 if (!GetBookmarkIdAsInt64(id_string, &id))
288 return false; 288 return false;
289 const BookmarkNode* node = model->GetNodeByID(id); 289 const BookmarkNode* node = model->GetNodeByID(id);
290 if (!node) { 290 if (!node) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 372
373 BookmarkModel* model = profile()->GetBookmarkModel(); 373 BookmarkModel* model = profile()->GetBookmarkModel();
374 int64 id; 374 int64 id;
375 std::string id_string; 375 std::string id_string;
376 if (args_->IsType(Value::TYPE_STRING) && 376 if (args_->IsType(Value::TYPE_STRING) &&
377 args_->GetAsString(&id_string) && 377 args_->GetAsString(&id_string) &&
378 StringToInt64(id_string, &id)) { 378 StringToInt64(id_string, &id)) {
379 return ExtensionBookmarks::RemoveNode(model, id, recursive, &error_); 379 return ExtensionBookmarks::RemoveNode(model, id, recursive, &error_);
380 } else { 380 } else {
381 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); 381 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
382 ListValue* ids = static_cast<ListValue*>(args_); 382 const ListValue* ids = args_as_list();
383 size_t count = ids->GetSize(); 383 size_t count = ids->GetSize();
384 EXTENSION_FUNCTION_VALIDATE(count > 0); 384 EXTENSION_FUNCTION_VALIDATE(count > 0);
385 for (size_t i = 0; i < count; ++i) { 385 for (size_t i = 0; i < count; ++i) {
386 EXTENSION_FUNCTION_VALIDATE(ids->GetString(i, &id_string)); 386 EXTENSION_FUNCTION_VALIDATE(ids->GetString(i, &id_string));
387 if (!GetBookmarkIdAsInt64(id_string, &id)) 387 if (!GetBookmarkIdAsInt64(id_string, &id))
388 return false; 388 return false;
389 if (!ExtensionBookmarks::RemoveNode(model, id, recursive, &error_)) 389 if (!ExtensionBookmarks::RemoveNode(model, id, recursive, &error_))
390 return false; 390 return false;
391 } 391 }
392 return true; 392 return true;
393 } 393 }
394 } 394 }
395 395
396 bool CreateBookmarkFunction::RunImpl() { 396 bool CreateBookmarkFunction::RunImpl() {
397 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); 397 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
398 DictionaryValue* json = static_cast<DictionaryValue*>(args_); 398 const DictionaryValue* json = args_as_dictionary();
399 399
400 BookmarkModel* model = profile()->GetBookmarkModel(); 400 BookmarkModel* model = profile()->GetBookmarkModel();
401 int64 parentId; 401 int64 parentId;
402 if (!json->HasKey(keys::kParentIdKey)) { 402 if (!json->HasKey(keys::kParentIdKey)) {
403 // Optional, default to "other bookmarks". 403 // Optional, default to "other bookmarks".
404 parentId = model->other_node()->id(); 404 parentId = model->other_node()->id();
405 } else { 405 } else {
406 std::string parentId_string; 406 std::string parentId_string;
407 EXTENSION_FUNCTION_VALIDATE(json->GetString(keys::kParentIdKey, 407 EXTENSION_FUNCTION_VALIDATE(json->GetString(keys::kParentIdKey,
408 &parentId_string)); 408 &parentId_string));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 } 452 }
453 453
454 DictionaryValue* ret = ExtensionBookmarks::GetNodeDictionary(node, false); 454 DictionaryValue* ret = ExtensionBookmarks::GetNodeDictionary(node, false);
455 result_.reset(ret); 455 result_.reset(ret);
456 456
457 return true; 457 return true;
458 } 458 }
459 459
460 bool MoveBookmarkFunction::RunImpl() { 460 bool MoveBookmarkFunction::RunImpl() {
461 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); 461 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
462 const ListValue* args = static_cast<const ListValue*>(args_); 462 const ListValue* args = args_as_list();
463 int64 id; 463 int64 id;
464 std::string id_string; 464 std::string id_string;
465 EXTENSION_FUNCTION_VALIDATE(args->GetString(0, &id_string)); 465 EXTENSION_FUNCTION_VALIDATE(args->GetString(0, &id_string));
466 if (!GetBookmarkIdAsInt64(id_string, &id)) 466 if (!GetBookmarkIdAsInt64(id_string, &id))
467 return false; 467 return false;
468 DictionaryValue* destination; 468 DictionaryValue* destination;
469 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &destination)); 469 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &destination));
470 470
471 BookmarkModel* model = profile()->GetBookmarkModel(); 471 BookmarkModel* model = profile()->GetBookmarkModel();
472 const BookmarkNode* node = model->GetNodeByID(id); 472 const BookmarkNode* node = model->GetNodeByID(id);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 model->Move(node, parent, index); 520 model->Move(node, parent, index);
521 521
522 DictionaryValue* ret = ExtensionBookmarks::GetNodeDictionary(node, false); 522 DictionaryValue* ret = ExtensionBookmarks::GetNodeDictionary(node, false);
523 result_.reset(ret); 523 result_.reset(ret);
524 524
525 return true; 525 return true;
526 } 526 }
527 527
528 bool UpdateBookmarkFunction::RunImpl() { 528 bool UpdateBookmarkFunction::RunImpl() {
529 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); 529 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
530 const ListValue* args = static_cast<const ListValue*>(args_); 530 const ListValue* args = args_as_list();
531 int64 id; 531 int64 id;
532 std::string id_string; 532 std::string id_string;
533 EXTENSION_FUNCTION_VALIDATE(args->GetString(0, &id_string)); 533 EXTENSION_FUNCTION_VALIDATE(args->GetString(0, &id_string));
534 if (!GetBookmarkIdAsInt64(id_string, &id)) 534 if (!GetBookmarkIdAsInt64(id_string, &id))
535 return false; 535 return false;
536 DictionaryValue* updates; 536 DictionaryValue* updates;
537 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &updates)); 537 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &updates));
538 std::wstring title; 538 std::wstring title;
539 updates->GetString(keys::kTitleKey, &title); // Optional (empty is clear). 539 updates->GetString(keys::kTitleKey, &title); // Optional (empty is clear).
540 540
541 BookmarkModel* model = profile()->GetBookmarkModel(); 541 BookmarkModel* model = profile()->GetBookmarkModel();
542 const BookmarkNode* node = model->GetNodeByID(id); 542 const BookmarkNode* node = model->GetNodeByID(id);
543 if (!node) { 543 if (!node) {
544 error_ = keys::kNoNodeError; 544 error_ = keys::kNoNodeError;
545 return false; 545 return false;
546 } 546 }
547 if (node == model->root_node() || 547 if (node == model->root_node() ||
548 node == model->other_node() || 548 node == model->other_node() ||
549 node == model->GetBookmarkBarNode()) { 549 node == model->GetBookmarkBarNode()) {
550 error_ = keys::kModifySpecialError; 550 error_ = keys::kModifySpecialError;
551 return false; 551 return false;
552 } 552 }
553 model->SetTitle(node, title); 553 model->SetTitle(node, title);
554 554
555 DictionaryValue* ret = ExtensionBookmarks::GetNodeDictionary(node, false); 555 DictionaryValue* ret = ExtensionBookmarks::GetNodeDictionary(node, false);
556 result_.reset(ret); 556 result_.reset(ret);
557 557
558 return true; 558 return true;
559 } 559 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/execute_code_in_tab_function.cc ('k') | chrome/browser/extensions/extension_browser_actions_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698