| 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/bookmark_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" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/prefs/public/pref_service_base.h" | 14 #include "base/prefs/public/pref_service_base.h" |
| 15 #include "base/sha1.h" | 15 #include "base/sha1.h" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 void BookmarkAPI::Shutdown() { | 296 void BookmarkAPI::Shutdown() { |
| 297 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 297 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
| 298 } | 298 } |
| 299 | 299 |
| 300 void BookmarkAPI::OnListenerAdded(const EventListenerInfo& details) { | 300 void BookmarkAPI::OnListenerAdded(const EventListenerInfo& details) { |
| 301 bookmark_event_router_.reset(new BookmarkEventRouter( | 301 bookmark_event_router_.reset(new BookmarkEventRouter( |
| 302 BookmarkModelFactory::GetForProfile(profile_))); | 302 BookmarkModelFactory::GetForProfile(profile_))); |
| 303 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 303 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
| 304 } | 304 } |
| 305 | 305 |
| 306 bool GetBookmarksFunction::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_type == |
| 314 bookmarks::Get::Params::ID_OR_ID_LIST_ARRAY) { | 314 bookmarks::Get::Params::ID_OR_ID_LIST_ARRAY) { |
| 315 std::vector<std::string>* ids = params->id_or_id_list_array.get(); | 315 std::vector<std::string>* ids = params->id_or_id_list_array.get(); |
| 316 size_t count = ids->size(); | 316 size_t count = ids->size(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 336 error_ = keys::kNoNodeError; | 336 error_ = keys::kNoNodeError; |
| 337 return false; | 337 return false; |
| 338 } | 338 } |
| 339 bookmark_api_helpers::AddNode(node, &nodes, false); | 339 bookmark_api_helpers::AddNode(node, &nodes, false); |
| 340 } | 340 } |
| 341 | 341 |
| 342 results_ = bookmarks::Get::Results::Create(nodes); | 342 results_ = bookmarks::Get::Results::Create(nodes); |
| 343 return true; | 343 return true; |
| 344 } | 344 } |
| 345 | 345 |
| 346 bool GetBookmarkChildrenFunction::RunImpl() { | 346 bool BookmarksGetChildrenFunction::RunImpl() { |
| 347 scoped_ptr<bookmarks::GetChildren::Params> params( | 347 scoped_ptr<bookmarks::GetChildren::Params> params( |
| 348 bookmarks::GetChildren::Params::Create(*args_)); | 348 bookmarks::GetChildren::Params::Create(*args_)); |
| 349 EXTENSION_FUNCTION_VALIDATE(params.get()); | 349 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 350 | 350 |
| 351 int64 id; | 351 int64 id; |
| 352 if (!GetBookmarkIdAsInt64(params->id, &id)) | 352 if (!GetBookmarkIdAsInt64(params->id, &id)) |
| 353 return false; | 353 return false; |
| 354 | 354 |
| 355 std::vector<linked_ptr<BookmarkTreeNode> > nodes; | 355 std::vector<linked_ptr<BookmarkTreeNode> > nodes; |
| 356 const BookmarkNode* node = | 356 const BookmarkNode* node = |
| 357 BookmarkModelFactory::GetForProfile(profile())->GetNodeByID(id); | 357 BookmarkModelFactory::GetForProfile(profile())->GetNodeByID(id); |
| 358 if (!node) { | 358 if (!node) { |
| 359 error_ = keys::kNoNodeError; | 359 error_ = keys::kNoNodeError; |
| 360 return false; | 360 return false; |
| 361 } | 361 } |
| 362 int child_count = node->child_count(); | 362 int child_count = node->child_count(); |
| 363 for (int i = 0; i < child_count; ++i) { | 363 for (int i = 0; i < child_count; ++i) { |
| 364 const BookmarkNode* child = node->GetChild(i); | 364 const BookmarkNode* child = node->GetChild(i); |
| 365 bookmark_api_helpers::AddNode(child, &nodes, false); | 365 bookmark_api_helpers::AddNode(child, &nodes, false); |
| 366 } | 366 } |
| 367 | 367 |
| 368 results_ = bookmarks::GetChildren::Results::Create(nodes); | 368 results_ = bookmarks::GetChildren::Results::Create(nodes); |
| 369 return true; | 369 return true; |
| 370 } | 370 } |
| 371 | 371 |
| 372 bool GetBookmarkRecentFunction::RunImpl() { | 372 bool BookmarksGetFunction::RunImpl() { |
| 373 scoped_ptr<bookmarks::GetRecent::Params> params( | 373 scoped_ptr<bookmarks::GetRecent::Params> params( |
| 374 bookmarks::GetRecent::Params::Create(*args_)); | 374 bookmarks::GetRecent::Params::Create(*args_)); |
| 375 EXTENSION_FUNCTION_VALIDATE(params.get()); | 375 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 376 if (params->number_of_items < 1) | 376 if (params->number_of_items < 1) |
| 377 return false; | 377 return false; |
| 378 | 378 |
| 379 std::vector<const BookmarkNode*> nodes; | 379 std::vector<const BookmarkNode*> nodes; |
| 380 bookmark_utils::GetMostRecentlyAddedEntries( | 380 bookmark_utils::GetMostRecentlyAddedEntries( |
| 381 BookmarkModelFactory::GetForProfile(profile()), | 381 BookmarkModelFactory::GetForProfile(profile()), |
| 382 params->number_of_items, | 382 params->number_of_items, |
| 383 &nodes); | 383 &nodes); |
| 384 | 384 |
| 385 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes; | 385 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes; |
| 386 std::vector<const BookmarkNode*>::iterator i = nodes.begin(); | 386 std::vector<const BookmarkNode*>::iterator i = nodes.begin(); |
| 387 for (; i != nodes.end(); ++i) { | 387 for (; i != nodes.end(); ++i) { |
| 388 const BookmarkNode* node = *i; | 388 const BookmarkNode* node = *i; |
| 389 bookmark_api_helpers::AddNode(node, &tree_nodes, false); | 389 bookmark_api_helpers::AddNode(node, &tree_nodes, false); |
| 390 } | 390 } |
| 391 | 391 |
| 392 results_ = bookmarks::GetRecent::Results::Create(tree_nodes); | 392 results_ = bookmarks::GetRecent::Results::Create(tree_nodes); |
| 393 return true; | 393 return true; |
| 394 } | 394 } |
| 395 | 395 |
| 396 bool GetBookmarkTreeFunction::RunImpl() { | 396 bool BookmarksGetSubTreeFunction::RunImpl() { |
| 397 std::vector<linked_ptr<BookmarkTreeNode> > nodes; | 397 std::vector<linked_ptr<BookmarkTreeNode> > nodes; |
| 398 const BookmarkNode* node = | 398 const BookmarkNode* node = |
| 399 BookmarkModelFactory::GetForProfile(profile())->root_node(); | 399 BookmarkModelFactory::GetForProfile(profile())->root_node(); |
| 400 bookmark_api_helpers::AddNode(node, &nodes, true); | 400 bookmark_api_helpers::AddNode(node, &nodes, true); |
| 401 results_ = bookmarks::GetTree::Results::Create(nodes); | 401 results_ = bookmarks::GetTree::Results::Create(nodes); |
| 402 return true; | 402 return true; |
| 403 } | 403 } |
| 404 | 404 |
| 405 bool GetBookmarkSubTreeFunction::RunImpl() { | 405 bool BookmarksGetRecentFunction::RunImpl() { |
| 406 scoped_ptr<bookmarks::GetSubTree::Params> params( | 406 scoped_ptr<bookmarks::GetSubTree::Params> params( |
| 407 bookmarks::GetSubTree::Params::Create(*args_)); | 407 bookmarks::GetSubTree::Params::Create(*args_)); |
| 408 EXTENSION_FUNCTION_VALIDATE(params.get()); | 408 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 409 | 409 |
| 410 int64 id; | 410 int64 id; |
| 411 if (!GetBookmarkIdAsInt64(params->id, &id)) | 411 if (!GetBookmarkIdAsInt64(params->id, &id)) |
| 412 return false; | 412 return false; |
| 413 | 413 |
| 414 const BookmarkNode* node = | 414 const BookmarkNode* node = |
| 415 BookmarkModelFactory::GetForProfile(profile())->GetNodeByID(id); | 415 BookmarkModelFactory::GetForProfile(profile())->GetNodeByID(id); |
| 416 if (!node) { | 416 if (!node) { |
| 417 error_ = keys::kNoNodeError; | 417 error_ = keys::kNoNodeError; |
| 418 return false; | 418 return false; |
| 419 } | 419 } |
| 420 | 420 |
| 421 std::vector<linked_ptr<BookmarkTreeNode> > nodes; | 421 std::vector<linked_ptr<BookmarkTreeNode> > nodes; |
| 422 bookmark_api_helpers::AddNode(node, &nodes, true); | 422 bookmark_api_helpers::AddNode(node, &nodes, true); |
| 423 results_ = bookmarks::GetSubTree::Results::Create(nodes); | 423 results_ = bookmarks::GetSubTree::Results::Create(nodes); |
| 424 return true; | 424 return true; |
| 425 } | 425 } |
| 426 | 426 |
| 427 bool SearchBookmarksFunction::RunImpl() { | 427 bool BookmarksSearchFunction::RunImpl() { |
| 428 scoped_ptr<bookmarks::Search::Params> params( | 428 scoped_ptr<bookmarks::Search::Params> params( |
| 429 bookmarks::Search::Params::Create(*args_)); | 429 bookmarks::Search::Params::Create(*args_)); |
| 430 EXTENSION_FUNCTION_VALIDATE(params.get()); | 430 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 431 | 431 |
| 432 PrefServiceBase* prefs = PrefServiceBase::FromBrowserContext(profile_); | 432 PrefServiceBase* prefs = PrefServiceBase::FromBrowserContext(profile_); |
| 433 std::string lang = prefs->GetString(prefs::kAcceptLanguages); | 433 std::string lang = prefs->GetString(prefs::kAcceptLanguages); |
| 434 std::vector<const BookmarkNode*> nodes; | 434 std::vector<const BookmarkNode*> nodes; |
| 435 bookmark_utils::GetBookmarksContainingText( | 435 bookmark_utils::GetBookmarksContainingText( |
| 436 BookmarkModelFactory::GetForProfile(profile()), | 436 BookmarkModelFactory::GetForProfile(profile()), |
| 437 UTF8ToUTF16(params->query), | 437 UTF8ToUTF16(params->query), |
| 438 std::numeric_limits<int>::max(), | 438 std::numeric_limits<int>::max(), |
| 439 lang, | 439 lang, |
| 440 &nodes); | 440 &nodes); |
| 441 | 441 |
| 442 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes; | 442 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes; |
| 443 for (std::vector<const BookmarkNode*>::iterator node_iter = nodes.begin(); | 443 for (std::vector<const BookmarkNode*>::iterator node_iter = nodes.begin(); |
| 444 node_iter != nodes.end(); ++node_iter) { | 444 node_iter != nodes.end(); ++node_iter) { |
| 445 bookmark_api_helpers::AddNode(*node_iter, &tree_nodes, false); | 445 bookmark_api_helpers::AddNode(*node_iter, &tree_nodes, false); |
| 446 } | 446 } |
| 447 | 447 |
| 448 results_ = bookmarks::Search::Results::Create(tree_nodes); | 448 results_ = bookmarks::Search::Results::Create(tree_nodes); |
| 449 return true; | 449 return true; |
| 450 } | 450 } |
| 451 | 451 |
| 452 // static | 452 // static |
| 453 bool RemoveBookmarkFunction::ExtractIds(const ListValue* args, | 453 bool BookmarksRemoveFunction::ExtractIds(const ListValue* args, |
| 454 std::list<int64>* ids, | 454 std::list<int64>* ids, |
| 455 bool* invalid_id) { | 455 bool* invalid_id) { |
| 456 std::string id_string; | 456 std::string id_string; |
| 457 if (!args->GetString(0, &id_string)) | 457 if (!args->GetString(0, &id_string)) |
| 458 return false; | 458 return false; |
| 459 int64 id; | 459 int64 id; |
| 460 if (base::StringToInt64(id_string, &id)) | 460 if (base::StringToInt64(id_string, &id)) |
| 461 ids->push_back(id); | 461 ids->push_back(id); |
| 462 else | 462 else |
| 463 *invalid_id = true; | 463 *invalid_id = true; |
| 464 return true; | 464 return true; |
| 465 } | 465 } |
| 466 | 466 |
| 467 bool RemoveBookmarkFunction::RunImpl() { | 467 bool BookmarksRemoveFunction::RunImpl() { |
| 468 if (!EditBookmarksEnabled()) | 468 if (!EditBookmarksEnabled()) |
| 469 return false; | 469 return false; |
| 470 | 470 |
| 471 scoped_ptr<bookmarks::Remove::Params> params( | 471 scoped_ptr<bookmarks::Remove::Params> params( |
| 472 bookmarks::Remove::Params::Create(*args_)); | 472 bookmarks::Remove::Params::Create(*args_)); |
| 473 EXTENSION_FUNCTION_VALIDATE(params.get()); | 473 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 474 | 474 |
| 475 int64 id; | 475 int64 id; |
| 476 if (!base::StringToInt64(params->id, &id)) { | 476 if (!base::StringToInt64(params->id, &id)) { |
| 477 error_ = keys::kInvalidIdError; | 477 error_ = keys::kInvalidIdError; |
| 478 return false; | 478 return false; |
| 479 } | 479 } |
| 480 | 480 |
| 481 bool recursive = false; | 481 bool recursive = false; |
| 482 if (name() == RemoveTreeBookmarkFunction::function_name()) | 482 if (name() == BookmarksRemoveTreeFunction::function_name()) |
| 483 recursive = true; | 483 recursive = true; |
| 484 | 484 |
| 485 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 485 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 486 if (!bookmark_api_helpers::RemoveNode(model, id, recursive, &error_)) | 486 if (!bookmark_api_helpers::RemoveNode(model, id, recursive, &error_)) |
| 487 return false; | 487 return false; |
| 488 | 488 |
| 489 return true; | 489 return true; |
| 490 } | 490 } |
| 491 | 491 |
| 492 bool CreateBookmarkFunction::RunImpl() { | 492 bool BookmarksCreateFunction::RunImpl() { |
| 493 if (!EditBookmarksEnabled()) | 493 if (!EditBookmarksEnabled()) |
| 494 return false; | 494 return false; |
| 495 | 495 |
| 496 scoped_ptr<bookmarks::Create::Params> params( | 496 scoped_ptr<bookmarks::Create::Params> params( |
| 497 bookmarks::Create::Params::Create(*args_)); | 497 bookmarks::Create::Params::Create(*args_)); |
| 498 EXTENSION_FUNCTION_VALIDATE(params.get()); | 498 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 499 | 499 |
| 500 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 500 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 501 int64 parentId; | 501 int64 parentId; |
| 502 | 502 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 } | 554 } |
| 555 | 555 |
| 556 scoped_ptr<BookmarkTreeNode> ret( | 556 scoped_ptr<BookmarkTreeNode> ret( |
| 557 bookmark_api_helpers::GetBookmarkTreeNode(node, false, false)); | 557 bookmark_api_helpers::GetBookmarkTreeNode(node, false, false)); |
| 558 results_ = bookmarks::Create::Results::Create(*ret); | 558 results_ = bookmarks::Create::Results::Create(*ret); |
| 559 | 559 |
| 560 return true; | 560 return true; |
| 561 } | 561 } |
| 562 | 562 |
| 563 // static | 563 // static |
| 564 bool MoveBookmarkFunction::ExtractIds(const ListValue* args, | 564 bool BookmarksMoveFunction::ExtractIds(const ListValue* args, |
| 565 std::list<int64>* ids, | 565 std::list<int64>* ids, |
| 566 bool* invalid_id) { | 566 bool* invalid_id) { |
| 567 // For now, Move accepts ID parameters in the same way as an Update. | 567 // For now, Move accepts ID parameters in the same way as an Update. |
| 568 return UpdateBookmarkFunction::ExtractIds(args, ids, invalid_id); | 568 return BookmarksUpdateFunction::ExtractIds(args, ids, invalid_id); |
| 569 } | 569 } |
| 570 | 570 |
| 571 bool MoveBookmarkFunction::RunImpl() { | 571 bool BookmarksMoveFunction::RunImpl() { |
| 572 if (!EditBookmarksEnabled()) | 572 if (!EditBookmarksEnabled()) |
| 573 return false; | 573 return false; |
| 574 | 574 |
| 575 scoped_ptr<bookmarks::Move::Params> params( | 575 scoped_ptr<bookmarks::Move::Params> params( |
| 576 bookmarks::Move::Params::Create(*args_)); | 576 bookmarks::Move::Params::Create(*args_)); |
| 577 EXTENSION_FUNCTION_VALIDATE(params.get()); | 577 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 578 | 578 |
| 579 int64 id; | 579 int64 id; |
| 580 if (!base::StringToInt64(params->id, &id)) { | 580 if (!base::StringToInt64(params->id, &id)) { |
| 581 error_ = keys::kInvalidIdError; | 581 error_ = keys::kInvalidIdError; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 model->Move(node, parent, index); | 628 model->Move(node, parent, index); |
| 629 | 629 |
| 630 scoped_ptr<BookmarkTreeNode> tree_node( | 630 scoped_ptr<BookmarkTreeNode> tree_node( |
| 631 bookmark_api_helpers::GetBookmarkTreeNode(node, false, false)); | 631 bookmark_api_helpers::GetBookmarkTreeNode(node, false, false)); |
| 632 results_ = bookmarks::Move::Results::Create(*tree_node); | 632 results_ = bookmarks::Move::Results::Create(*tree_node); |
| 633 | 633 |
| 634 return true; | 634 return true; |
| 635 } | 635 } |
| 636 | 636 |
| 637 // static | 637 // static |
| 638 bool UpdateBookmarkFunction::ExtractIds(const ListValue* args, | 638 bool BookmarksUpdateFunction::ExtractIds(const ListValue* args, |
| 639 std::list<int64>* ids, | 639 std::list<int64>* ids, |
| 640 bool* invalid_id) { | 640 bool* invalid_id) { |
| 641 // For now, Update accepts ID parameters in the same way as an Remove. | 641 // For now, Update accepts ID parameters in the same way as an Remove. |
| 642 return RemoveBookmarkFunction::ExtractIds(args, ids, invalid_id); | 642 return BookmarksRemoveFunction::ExtractIds(args, ids, invalid_id); |
| 643 } | 643 } |
| 644 | 644 |
| 645 bool UpdateBookmarkFunction::RunImpl() { | 645 bool BookmarksUpdateFunction::RunImpl() { |
| 646 if (!EditBookmarksEnabled()) | 646 if (!EditBookmarksEnabled()) |
| 647 return false; | 647 return false; |
| 648 | 648 |
| 649 scoped_ptr<bookmarks::Update::Params> params( | 649 scoped_ptr<bookmarks::Update::Params> params( |
| 650 bookmarks::Update::Params::Create(*args_)); | 650 bookmarks::Update::Params::Create(*args_)); |
| 651 EXTENSION_FUNCTION_VALIDATE(params.get()); | 651 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 652 | 652 |
| 653 int64 id; | 653 int64 id; |
| 654 if (!base::StringToInt64(params->id, &id)) { | 654 if (!base::StringToInt64(params->id, &id)) { |
| 655 error_ = keys::kInvalidIdError; | 655 error_ = keys::kInvalidIdError; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 } | 712 } |
| 713 private: | 713 private: |
| 714 std::map<BucketIdType, Bucket*> buckets_; | 714 std::map<BucketIdType, Bucket*> buckets_; |
| 715 }; | 715 }; |
| 716 | 716 |
| 717 // Mapper for 'bookmarks.create'. Maps "same input to bookmarks.create" to a | 717 // Mapper for 'bookmarks.create'. Maps "same input to bookmarks.create" to a |
| 718 // unique bucket. | 718 // unique bucket. |
| 719 class CreateBookmarkBucketMapper : public BookmarkBucketMapper<std::string> { | 719 class CreateBookmarkBucketMapper : public BookmarkBucketMapper<std::string> { |
| 720 public: | 720 public: |
| 721 explicit CreateBookmarkBucketMapper(Profile* profile) : profile_(profile) {} | 721 explicit CreateBookmarkBucketMapper(Profile* profile) : profile_(profile) {} |
| 722 // TODO(tim): This should share code with CreateBookmarkFunction::RunImpl, | 722 // TODO(tim): This should share code with BookmarksCreateFunction::RunImpl, |
| 723 // but I can't figure out a good way to do that with all the macros. | 723 // but I can't figure out a good way to do that with all the macros. |
| 724 virtual void GetBucketsForArgs(const ListValue* args, BucketList* buckets) { | 724 virtual void GetBucketsForArgs(const ListValue* args, BucketList* buckets) { |
| 725 const DictionaryValue* json; | 725 const DictionaryValue* json; |
| 726 if (!args->GetDictionary(0, &json)) | 726 if (!args->GetDictionary(0, &json)) |
| 727 return; | 727 return; |
| 728 | 728 |
| 729 std::string parent_id; | 729 std::string parent_id; |
| 730 if (json->HasKey(keys::kParentIdKey)) { | 730 if (json->HasKey(keys::kParentIdKey)) { |
| 731 if (!json->GetString(keys::kParentIdKey, &parent_id)) | 731 if (!json->GetString(keys::kParentIdKey, &parent_id)) |
| 732 return; | 732 return; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 756 }; | 756 }; |
| 757 | 757 |
| 758 // Mapper for 'bookmarks.remove'. | 758 // Mapper for 'bookmarks.remove'. |
| 759 class RemoveBookmarksBucketMapper : public BookmarkBucketMapper<std::string> { | 759 class RemoveBookmarksBucketMapper : public BookmarkBucketMapper<std::string> { |
| 760 public: | 760 public: |
| 761 explicit RemoveBookmarksBucketMapper(Profile* profile) : profile_(profile) {} | 761 explicit RemoveBookmarksBucketMapper(Profile* profile) : profile_(profile) {} |
| 762 virtual void GetBucketsForArgs(const ListValue* args, BucketList* buckets) { | 762 virtual void GetBucketsForArgs(const ListValue* args, BucketList* buckets) { |
| 763 typedef std::list<int64> IdList; | 763 typedef std::list<int64> IdList; |
| 764 IdList ids; | 764 IdList ids; |
| 765 bool invalid_id = false; | 765 bool invalid_id = false; |
| 766 if (!RemoveBookmarkFunction::ExtractIds(args, &ids, &invalid_id) || | 766 if (!BookmarksRemoveFunction::ExtractIds(args, &ids, &invalid_id) || |
| 767 invalid_id) { | 767 invalid_id) { |
| 768 return; | 768 return; |
| 769 } | 769 } |
| 770 | 770 |
| 771 for (IdList::iterator it = ids.begin(); it != ids.end(); ++it) { | 771 for (IdList::iterator it = ids.begin(); it != ids.end(); ++it) { |
| 772 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_); | 772 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_); |
| 773 const BookmarkNode* node = model->GetNodeByID(*it); | 773 const BookmarkNode* node = model->GetNodeByID(*it); |
| 774 if (!node || node->is_root()) | 774 if (!node || node->is_root()) |
| 775 return; | 775 return; |
| 776 | 776 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 heuristics->push_back(new TimedLimit( | 849 heuristics->push_back(new TimedLimit( |
| 850 kTimedLimitConfig, | 850 kTimedLimitConfig, |
| 851 long_mapper, | 851 long_mapper, |
| 852 "MAX_WRITE_OPERATIONS_PER_HOUR")); | 852 "MAX_WRITE_OPERATIONS_PER_HOUR")); |
| 853 } | 853 } |
| 854 | 854 |
| 855 DISALLOW_IMPLICIT_CONSTRUCTORS(BookmarksQuotaLimitFactory); | 855 DISALLOW_IMPLICIT_CONSTRUCTORS(BookmarksQuotaLimitFactory); |
| 856 }; | 856 }; |
| 857 | 857 |
| 858 // And finally, building the individual heuristics for each function. | 858 // And finally, building the individual heuristics for each function. |
| 859 void RemoveBookmarkFunction::GetQuotaLimitHeuristics( | 859 void BookmarksRemoveFunction::GetQuotaLimitHeuristics( |
| 860 QuotaLimitHeuristics* heuristics) const { | 860 QuotaLimitHeuristics* heuristics) const { |
| 861 BookmarksQuotaLimitFactory::BuildForRemove(heuristics, profile()); | 861 BookmarksQuotaLimitFactory::BuildForRemove(heuristics, profile()); |
| 862 } | 862 } |
| 863 | 863 |
| 864 void MoveBookmarkFunction::GetQuotaLimitHeuristics( | 864 void BookmarksMoveFunction::GetQuotaLimitHeuristics( |
| 865 QuotaLimitHeuristics* heuristics) const { | 865 QuotaLimitHeuristics* heuristics) const { |
| 866 BookmarksQuotaLimitFactory::Build<MoveBookmarkFunction>(heuristics); | 866 BookmarksQuotaLimitFactory::Build<BookmarksMoveFunction>(heuristics); |
| 867 } | 867 } |
| 868 | 868 |
| 869 void UpdateBookmarkFunction::GetQuotaLimitHeuristics( | 869 void BookmarksUpdateFunction::GetQuotaLimitHeuristics( |
| 870 QuotaLimitHeuristics* heuristics) const { | 870 QuotaLimitHeuristics* heuristics) const { |
| 871 BookmarksQuotaLimitFactory::Build<UpdateBookmarkFunction>(heuristics); | 871 BookmarksQuotaLimitFactory::Build<BookmarksUpdateFunction>(heuristics); |
| 872 }; | 872 }; |
| 873 | 873 |
| 874 void CreateBookmarkFunction::GetQuotaLimitHeuristics( | 874 void BookmarksCreateFunction::GetQuotaLimitHeuristics( |
| 875 QuotaLimitHeuristics* heuristics) const { | 875 QuotaLimitHeuristics* heuristics) const { |
| 876 BookmarksQuotaLimitFactory::BuildForCreate(heuristics, profile()); | 876 BookmarksQuotaLimitFactory::BuildForCreate(heuristics, profile()); |
| 877 } | 877 } |
| 878 | 878 |
| 879 BookmarksIOFunction::BookmarksIOFunction() {} | 879 BookmarksIOFunction::BookmarksIOFunction() {} |
| 880 | 880 |
| 881 BookmarksIOFunction::~BookmarksIOFunction() { | 881 BookmarksIOFunction::~BookmarksIOFunction() { |
| 882 // There may be pending file dialogs, we need to tell them that we've gone | 882 // There may be pending file dialogs, we need to tell them that we've gone |
| 883 // away so they don't try and call back to us. | 883 // away so they don't try and call back to us. |
| 884 if (select_file_dialog_.get()) | 884 if (select_file_dialog_.get()) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 void BookmarksIOFunction::FileSelectionCanceled(void* params) { | 942 void BookmarksIOFunction::FileSelectionCanceled(void* params) { |
| 943 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 943 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
| 944 } | 944 } |
| 945 | 945 |
| 946 void BookmarksIOFunction::MultiFilesSelected( | 946 void BookmarksIOFunction::MultiFilesSelected( |
| 947 const std::vector<FilePath>& files, void* params) { | 947 const std::vector<FilePath>& files, void* params) { |
| 948 Release(); // Balanced in BookmarsIOFunction::SelectFile() | 948 Release(); // Balanced in BookmarsIOFunction::SelectFile() |
| 949 NOTREACHED() << "Should not be able to select multiple files"; | 949 NOTREACHED() << "Should not be able to select multiple files"; |
| 950 } | 950 } |
| 951 | 951 |
| 952 bool ImportBookmarksFunction::RunImpl() { | 952 bool BookmarksImportFunction::RunImpl() { |
| 953 if (!EditBookmarksEnabled()) | 953 if (!EditBookmarksEnabled()) |
| 954 return false; | 954 return false; |
| 955 SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE); | 955 SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE); |
| 956 return true; | 956 return true; |
| 957 } | 957 } |
| 958 | 958 |
| 959 void ImportBookmarksFunction::FileSelected(const FilePath& path, | 959 void BookmarksImportFunction::FileSelected(const FilePath& path, |
| 960 int index, | 960 int index, |
| 961 void* params) { | 961 void* params) { |
| 962 #if !defined(OS_ANDROID) | 962 #if !defined(OS_ANDROID) |
| 963 // Android does not have support for the standard importers. | 963 // Android does not have support for the standard importers. |
| 964 // TODO(jgreenwald): remove ifdef once extensions are no longer built on | 964 // TODO(jgreenwald): remove ifdef once extensions are no longer built on |
| 965 // Android. | 965 // Android. |
| 966 scoped_refptr<ImporterHost> importer_host(new ImporterHost); | 966 scoped_refptr<ImporterHost> importer_host(new ImporterHost); |
| 967 importer::SourceProfile source_profile; | 967 importer::SourceProfile source_profile; |
| 968 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; | 968 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; |
| 969 source_profile.source_path = path; | 969 source_profile.source_path = path; |
| 970 importer_host->StartImportSettings(source_profile, | 970 importer_host->StartImportSettings(source_profile, |
| 971 profile(), | 971 profile(), |
| 972 importer::FAVORITES, | 972 importer::FAVORITES, |
| 973 new ProfileWriter(profile()), | 973 new ProfileWriter(profile()), |
| 974 true); | 974 true); |
| 975 #endif | 975 #endif |
| 976 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 976 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
| 977 } | 977 } |
| 978 | 978 |
| 979 bool ExportBookmarksFunction::RunImpl() { | 979 bool BookmarksExportFunction::RunImpl() { |
| 980 SelectFile(ui::SelectFileDialog::SELECT_SAVEAS_FILE); | 980 SelectFile(ui::SelectFileDialog::SELECT_SAVEAS_FILE); |
| 981 return true; | 981 return true; |
| 982 } | 982 } |
| 983 | 983 |
| 984 void ExportBookmarksFunction::FileSelected(const FilePath& path, | 984 void BookmarksExportFunction::FileSelected(const FilePath& path, |
| 985 int index, | 985 int index, |
| 986 void* params) { | 986 void* params) { |
| 987 #if !defined(OS_ANDROID) | 987 #if !defined(OS_ANDROID) |
| 988 // Android does not have support for the standard exporter. | 988 // Android does not have support for the standard exporter. |
| 989 // TODO(jgreenwald): remove ifdef once extensions are no longer built on | 989 // TODO(jgreenwald): remove ifdef once extensions are no longer built on |
| 990 // Android. | 990 // Android. |
| 991 bookmark_html_writer::WriteBookmarks(profile(), path, NULL); | 991 bookmark_html_writer::WriteBookmarks(profile(), path, NULL); |
| 992 #endif | 992 #endif |
| 993 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 993 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
| 994 } | 994 } |
| 995 | 995 |
| 996 } // namespace extensions | 996 } // namespace extensions |
| OLD | NEW |