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/files/file_path.h" | 8 #include "base/files/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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 file_util::ReplaceIllegalCharactersInPath(&filename, '_'); | 92 file_util::ReplaceIllegalCharactersInPath(&filename, '_'); |
93 | 93 |
94 base::FilePath default_path; | 94 base::FilePath default_path; |
95 PathService::Get(chrome::DIR_USER_DOCUMENTS, &default_path); | 95 PathService::Get(chrome::DIR_USER_DOCUMENTS, &default_path); |
96 return default_path.Append(filename); | 96 return default_path.Append(filename); |
97 } | 97 } |
98 | 98 |
99 } // namespace | 99 } // namespace |
100 | 100 |
101 void BookmarksFunction::Run() { | 101 bool BookmarksFunction::RunImpl() { |
102 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); | 102 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); |
103 if (!model->loaded()) { | 103 if (!model->loaded()) { |
104 // Bookmarks are not ready yet. We'll wait. | 104 // Bookmarks are not ready yet. We'll wait. |
105 model->AddObserver(this); | 105 model->AddObserver(this); |
106 AddRef(); // Balanced in Loaded(). | 106 AddRef(); // Balanced in Loaded(). |
107 return; | 107 return true; |
108 } | 108 } |
109 | 109 |
110 bool success = RunImpl(); | 110 bool success = RunOnReady(); |
111 if (success) { | 111 if (success) { |
112 content::NotificationService::current()->Notify( | 112 content::NotificationService::current()->Notify( |
113 chrome::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, | 113 chrome::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, |
114 content::Source<const Extension>(GetExtension()), | 114 content::Source<const Extension>(GetExtension()), |
115 content::Details<const BookmarksFunction>(this)); | 115 content::Details<const BookmarksFunction>(this)); |
116 } | 116 } |
117 SendResponse(success); | 117 SendResponse(success); |
| 118 return true; |
118 } | 119 } |
119 | 120 |
120 bool BookmarksFunction::GetBookmarkIdAsInt64(const std::string& id_string, | 121 bool BookmarksFunction::GetBookmarkIdAsInt64(const std::string& id_string, |
121 int64* id) { | 122 int64* id) { |
122 if (base::StringToInt64(id_string, id)) | 123 if (base::StringToInt64(id_string, id)) |
123 return true; | 124 return true; |
124 | 125 |
125 error_ = keys::kInvalidIdError; | 126 error_ = keys::kInvalidIdError; |
126 return false; | 127 return false; |
127 } | 128 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 error_ = keys::kEditBookmarksDisabled; | 211 error_ = keys::kEditBookmarksDisabled; |
211 return false; | 212 return false; |
212 } | 213 } |
213 | 214 |
214 void BookmarksFunction::BookmarkModelChanged() { | 215 void BookmarksFunction::BookmarkModelChanged() { |
215 } | 216 } |
216 | 217 |
217 void BookmarksFunction::BookmarkModelLoaded(BookmarkModel* model, | 218 void BookmarksFunction::BookmarkModelLoaded(BookmarkModel* model, |
218 bool ids_reassigned) { | 219 bool ids_reassigned) { |
219 model->RemoveObserver(this); | 220 model->RemoveObserver(this); |
220 Run(); | 221 RunOnReady(); |
221 Release(); // Balanced in Run(). | 222 Release(); // Balanced in RunOnReady(). |
222 } | 223 } |
223 | 224 |
224 BookmarkEventRouter::BookmarkEventRouter(BrowserContext* context, | 225 BookmarkEventRouter::BookmarkEventRouter(BrowserContext* context, |
225 BookmarkModel* model) | 226 BookmarkModel* model) |
226 : browser_context_(context), model_(model) { | 227 : browser_context_(context), model_(model) { |
227 model_->AddObserver(this); | 228 model_->AddObserver(this); |
228 } | 229 } |
229 | 230 |
230 BookmarkEventRouter::~BookmarkEventRouter() { | 231 BookmarkEventRouter::~BookmarkEventRouter() { |
231 if (model_) { | 232 if (model_) { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 } | 380 } |
380 | 381 |
381 void BookmarksAPI::OnListenerAdded(const EventListenerInfo& details) { | 382 void BookmarksAPI::OnListenerAdded(const EventListenerInfo& details) { |
382 bookmark_event_router_.reset(new BookmarkEventRouter( | 383 bookmark_event_router_.reset(new BookmarkEventRouter( |
383 browser_context_, | 384 browser_context_, |
384 BookmarkModelFactory::GetForProfile( | 385 BookmarkModelFactory::GetForProfile( |
385 Profile::FromBrowserContext(browser_context_)))); | 386 Profile::FromBrowserContext(browser_context_)))); |
386 EventRouter::Get(browser_context_)->UnregisterObserver(this); | 387 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
387 } | 388 } |
388 | 389 |
389 bool BookmarksGetFunction::RunImpl() { | 390 bool BookmarksGetFunction::RunOnReady() { |
390 scoped_ptr<bookmarks::Get::Params> params( | 391 scoped_ptr<bookmarks::Get::Params> params( |
391 bookmarks::Get::Params::Create(*args_)); | 392 bookmarks::Get::Params::Create(*args_)); |
392 EXTENSION_FUNCTION_VALIDATE(params.get()); | 393 EXTENSION_FUNCTION_VALIDATE(params.get()); |
393 | 394 |
394 std::vector<linked_ptr<BookmarkTreeNode> > nodes; | 395 std::vector<linked_ptr<BookmarkTreeNode> > nodes; |
395 if (params->id_or_id_list.as_strings) { | 396 if (params->id_or_id_list.as_strings) { |
396 std::vector<std::string>& ids = *params->id_or_id_list.as_strings; | 397 std::vector<std::string>& ids = *params->id_or_id_list.as_strings; |
397 size_t count = ids.size(); | 398 size_t count = ids.size(); |
398 EXTENSION_FUNCTION_VALIDATE(count > 0); | 399 EXTENSION_FUNCTION_VALIDATE(count > 0); |
399 for (size_t i = 0; i < count; ++i) { | 400 for (size_t i = 0; i < count; ++i) { |
400 const BookmarkNode* node = GetBookmarkNodeFromId(ids[i]); | 401 const BookmarkNode* node = GetBookmarkNodeFromId(ids[i]); |
401 if (!node) | 402 if (!node) |
402 return false; | 403 return false; |
403 bookmark_api_helpers::AddNode(node, &nodes, false); | 404 bookmark_api_helpers::AddNode(node, &nodes, false); |
404 } | 405 } |
405 } else { | 406 } else { |
406 const BookmarkNode* node = | 407 const BookmarkNode* node = |
407 GetBookmarkNodeFromId(*params->id_or_id_list.as_string); | 408 GetBookmarkNodeFromId(*params->id_or_id_list.as_string); |
408 if (!node) | 409 if (!node) |
409 return false; | 410 return false; |
410 bookmark_api_helpers::AddNode(node, &nodes, false); | 411 bookmark_api_helpers::AddNode(node, &nodes, false); |
411 } | 412 } |
412 | 413 |
413 results_ = bookmarks::Get::Results::Create(nodes); | 414 results_ = bookmarks::Get::Results::Create(nodes); |
414 return true; | 415 return true; |
415 } | 416 } |
416 | 417 |
417 bool BookmarksGetChildrenFunction::RunImpl() { | 418 bool BookmarksGetChildrenFunction::RunOnReady() { |
418 scoped_ptr<bookmarks::GetChildren::Params> params( | 419 scoped_ptr<bookmarks::GetChildren::Params> params( |
419 bookmarks::GetChildren::Params::Create(*args_)); | 420 bookmarks::GetChildren::Params::Create(*args_)); |
420 EXTENSION_FUNCTION_VALIDATE(params.get()); | 421 EXTENSION_FUNCTION_VALIDATE(params.get()); |
421 | 422 |
422 const BookmarkNode* node = GetBookmarkNodeFromId(params->id); | 423 const BookmarkNode* node = GetBookmarkNodeFromId(params->id); |
423 if (!node) | 424 if (!node) |
424 return false; | 425 return false; |
425 | 426 |
426 std::vector<linked_ptr<BookmarkTreeNode> > nodes; | 427 std::vector<linked_ptr<BookmarkTreeNode> > nodes; |
427 int child_count = node->child_count(); | 428 int child_count = node->child_count(); |
428 for (int i = 0; i < child_count; ++i) { | 429 for (int i = 0; i < child_count; ++i) { |
429 const BookmarkNode* child = node->GetChild(i); | 430 const BookmarkNode* child = node->GetChild(i); |
430 bookmark_api_helpers::AddNode(child, &nodes, false); | 431 bookmark_api_helpers::AddNode(child, &nodes, false); |
431 } | 432 } |
432 | 433 |
433 results_ = bookmarks::GetChildren::Results::Create(nodes); | 434 results_ = bookmarks::GetChildren::Results::Create(nodes); |
434 return true; | 435 return true; |
435 } | 436 } |
436 | 437 |
437 bool BookmarksGetRecentFunction::RunImpl() { | 438 bool BookmarksGetRecentFunction::RunOnReady() { |
438 scoped_ptr<bookmarks::GetRecent::Params> params( | 439 scoped_ptr<bookmarks::GetRecent::Params> params( |
439 bookmarks::GetRecent::Params::Create(*args_)); | 440 bookmarks::GetRecent::Params::Create(*args_)); |
440 EXTENSION_FUNCTION_VALIDATE(params.get()); | 441 EXTENSION_FUNCTION_VALIDATE(params.get()); |
441 if (params->number_of_items < 1) | 442 if (params->number_of_items < 1) |
442 return false; | 443 return false; |
443 | 444 |
444 std::vector<const BookmarkNode*> nodes; | 445 std::vector<const BookmarkNode*> nodes; |
445 bookmark_utils::GetMostRecentlyAddedEntries( | 446 bookmark_utils::GetMostRecentlyAddedEntries( |
446 BookmarkModelFactory::GetForProfile(GetProfile()), | 447 BookmarkModelFactory::GetForProfile(GetProfile()), |
447 params->number_of_items, | 448 params->number_of_items, |
448 &nodes); | 449 &nodes); |
449 | 450 |
450 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes; | 451 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes; |
451 std::vector<const BookmarkNode*>::iterator i = nodes.begin(); | 452 std::vector<const BookmarkNode*>::iterator i = nodes.begin(); |
452 for (; i != nodes.end(); ++i) { | 453 for (; i != nodes.end(); ++i) { |
453 const BookmarkNode* node = *i; | 454 const BookmarkNode* node = *i; |
454 bookmark_api_helpers::AddNode(node, &tree_nodes, false); | 455 bookmark_api_helpers::AddNode(node, &tree_nodes, false); |
455 } | 456 } |
456 | 457 |
457 results_ = bookmarks::GetRecent::Results::Create(tree_nodes); | 458 results_ = bookmarks::GetRecent::Results::Create(tree_nodes); |
458 return true; | 459 return true; |
459 } | 460 } |
460 | 461 |
461 bool BookmarksGetTreeFunction::RunImpl() { | 462 bool BookmarksGetTreeFunction::RunOnReady() { |
462 std::vector<linked_ptr<BookmarkTreeNode> > nodes; | 463 std::vector<linked_ptr<BookmarkTreeNode> > nodes; |
463 const BookmarkNode* node = | 464 const BookmarkNode* node = |
464 BookmarkModelFactory::GetForProfile(GetProfile())->root_node(); | 465 BookmarkModelFactory::GetForProfile(GetProfile())->root_node(); |
465 bookmark_api_helpers::AddNode(node, &nodes, true); | 466 bookmark_api_helpers::AddNode(node, &nodes, true); |
466 results_ = bookmarks::GetTree::Results::Create(nodes); | 467 results_ = bookmarks::GetTree::Results::Create(nodes); |
467 return true; | 468 return true; |
468 } | 469 } |
469 | 470 |
470 bool BookmarksGetSubTreeFunction::RunImpl() { | 471 bool BookmarksGetSubTreeFunction::RunOnReady() { |
471 scoped_ptr<bookmarks::GetSubTree::Params> params( | 472 scoped_ptr<bookmarks::GetSubTree::Params> params( |
472 bookmarks::GetSubTree::Params::Create(*args_)); | 473 bookmarks::GetSubTree::Params::Create(*args_)); |
473 EXTENSION_FUNCTION_VALIDATE(params.get()); | 474 EXTENSION_FUNCTION_VALIDATE(params.get()); |
474 | 475 |
475 const BookmarkNode* node = GetBookmarkNodeFromId(params->id); | 476 const BookmarkNode* node = GetBookmarkNodeFromId(params->id); |
476 if (!node) | 477 if (!node) |
477 return false; | 478 return false; |
478 | 479 |
479 std::vector<linked_ptr<BookmarkTreeNode> > nodes; | 480 std::vector<linked_ptr<BookmarkTreeNode> > nodes; |
480 bookmark_api_helpers::AddNode(node, &nodes, true); | 481 bookmark_api_helpers::AddNode(node, &nodes, true); |
481 results_ = bookmarks::GetSubTree::Results::Create(nodes); | 482 results_ = bookmarks::GetSubTree::Results::Create(nodes); |
482 return true; | 483 return true; |
483 } | 484 } |
484 | 485 |
485 bool BookmarksSearchFunction::RunImpl() { | 486 bool BookmarksSearchFunction::RunOnReady() { |
486 scoped_ptr<bookmarks::Search::Params> params( | 487 scoped_ptr<bookmarks::Search::Params> params( |
487 bookmarks::Search::Params::Create(*args_)); | 488 bookmarks::Search::Params::Create(*args_)); |
488 EXTENSION_FUNCTION_VALIDATE(params.get()); | 489 EXTENSION_FUNCTION_VALIDATE(params.get()); |
489 | 490 |
490 PrefService* prefs = user_prefs::UserPrefs::Get(GetProfile()); | 491 PrefService* prefs = user_prefs::UserPrefs::Get(GetProfile()); |
491 std::string lang = prefs->GetString(prefs::kAcceptLanguages); | 492 std::string lang = prefs->GetString(prefs::kAcceptLanguages); |
492 std::vector<const BookmarkNode*> nodes; | 493 std::vector<const BookmarkNode*> nodes; |
493 if (params->query.as_string) { | 494 if (params->query.as_string) { |
494 bookmark_utils::QueryFields query; | 495 bookmark_utils::QueryFields query; |
495 query.word_phrase_query.reset( | 496 query.word_phrase_query.reset( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 if (!args->GetString(0, &id_string)) | 540 if (!args->GetString(0, &id_string)) |
540 return false; | 541 return false; |
541 int64 id; | 542 int64 id; |
542 if (base::StringToInt64(id_string, &id)) | 543 if (base::StringToInt64(id_string, &id)) |
543 ids->push_back(id); | 544 ids->push_back(id); |
544 else | 545 else |
545 *invalid_id = true; | 546 *invalid_id = true; |
546 return true; | 547 return true; |
547 } | 548 } |
548 | 549 |
549 bool BookmarksRemoveFunction::RunImpl() { | 550 bool BookmarksRemoveFunction::RunOnReady() { |
550 if (!EditBookmarksEnabled()) | 551 if (!EditBookmarksEnabled()) |
551 return false; | 552 return false; |
552 | 553 |
553 scoped_ptr<bookmarks::Remove::Params> params( | 554 scoped_ptr<bookmarks::Remove::Params> params( |
554 bookmarks::Remove::Params::Create(*args_)); | 555 bookmarks::Remove::Params::Create(*args_)); |
555 EXTENSION_FUNCTION_VALIDATE(params.get()); | 556 EXTENSION_FUNCTION_VALIDATE(params.get()); |
556 | 557 |
557 int64 id; | 558 int64 id; |
558 if (!GetBookmarkIdAsInt64(params->id, &id)) | 559 if (!GetBookmarkIdAsInt64(params->id, &id)) |
559 return false; | 560 return false; |
560 | 561 |
561 bool recursive = false; | 562 bool recursive = false; |
562 if (name() == BookmarksRemoveTreeFunction::function_name()) | 563 if (name() == BookmarksRemoveTreeFunction::function_name()) |
563 recursive = true; | 564 recursive = true; |
564 | 565 |
565 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); | 566 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); |
566 if (!bookmark_api_helpers::RemoveNode(model, id, recursive, &error_)) | 567 if (!bookmark_api_helpers::RemoveNode(model, id, recursive, &error_)) |
567 return false; | 568 return false; |
568 | 569 |
569 return true; | 570 return true; |
570 } | 571 } |
571 | 572 |
572 bool BookmarksCreateFunction::RunImpl() { | 573 bool BookmarksCreateFunction::RunOnReady() { |
573 if (!EditBookmarksEnabled()) | 574 if (!EditBookmarksEnabled()) |
574 return false; | 575 return false; |
575 | 576 |
576 scoped_ptr<bookmarks::Create::Params> params( | 577 scoped_ptr<bookmarks::Create::Params> params( |
577 bookmarks::Create::Params::Create(*args_)); | 578 bookmarks::Create::Params::Create(*args_)); |
578 EXTENSION_FUNCTION_VALIDATE(params.get()); | 579 EXTENSION_FUNCTION_VALIDATE(params.get()); |
579 | 580 |
580 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); | 581 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); |
581 const BookmarkNode* node = CreateBookmarkNode(model, params->bookmark, NULL); | 582 const BookmarkNode* node = CreateBookmarkNode(model, params->bookmark, NULL); |
582 if (!node) | 583 if (!node) |
583 return false; | 584 return false; |
584 | 585 |
585 scoped_ptr<BookmarkTreeNode> ret( | 586 scoped_ptr<BookmarkTreeNode> ret( |
586 bookmark_api_helpers::GetBookmarkTreeNode(node, false, false)); | 587 bookmark_api_helpers::GetBookmarkTreeNode(node, false, false)); |
587 results_ = bookmarks::Create::Results::Create(*ret); | 588 results_ = bookmarks::Create::Results::Create(*ret); |
588 | 589 |
589 return true; | 590 return true; |
590 } | 591 } |
591 | 592 |
592 // static | 593 // static |
593 bool BookmarksMoveFunction::ExtractIds(const base::ListValue* args, | 594 bool BookmarksMoveFunction::ExtractIds(const base::ListValue* args, |
594 std::list<int64>* ids, | 595 std::list<int64>* ids, |
595 bool* invalid_id) { | 596 bool* invalid_id) { |
596 // For now, Move accepts ID parameters in the same way as an Update. | 597 // For now, Move accepts ID parameters in the same way as an Update. |
597 return BookmarksUpdateFunction::ExtractIds(args, ids, invalid_id); | 598 return BookmarksUpdateFunction::ExtractIds(args, ids, invalid_id); |
598 } | 599 } |
599 | 600 |
600 bool BookmarksMoveFunction::RunImpl() { | 601 bool BookmarksMoveFunction::RunOnReady() { |
601 if (!EditBookmarksEnabled()) | 602 if (!EditBookmarksEnabled()) |
602 return false; | 603 return false; |
603 | 604 |
604 scoped_ptr<bookmarks::Move::Params> params( | 605 scoped_ptr<bookmarks::Move::Params> params( |
605 bookmarks::Move::Params::Create(*args_)); | 606 bookmarks::Move::Params::Create(*args_)); |
606 EXTENSION_FUNCTION_VALIDATE(params.get()); | 607 EXTENSION_FUNCTION_VALIDATE(params.get()); |
607 | 608 |
608 const BookmarkNode* node = GetBookmarkNodeFromId(params->id); | 609 const BookmarkNode* node = GetBookmarkNodeFromId(params->id); |
609 if (!node) | 610 if (!node) |
610 return false; | 611 return false; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 } | 658 } |
658 | 659 |
659 // static | 660 // static |
660 bool BookmarksUpdateFunction::ExtractIds(const base::ListValue* args, | 661 bool BookmarksUpdateFunction::ExtractIds(const base::ListValue* args, |
661 std::list<int64>* ids, | 662 std::list<int64>* ids, |
662 bool* invalid_id) { | 663 bool* invalid_id) { |
663 // For now, Update accepts ID parameters in the same way as an Remove. | 664 // For now, Update accepts ID parameters in the same way as an Remove. |
664 return BookmarksRemoveFunction::ExtractIds(args, ids, invalid_id); | 665 return BookmarksRemoveFunction::ExtractIds(args, ids, invalid_id); |
665 } | 666 } |
666 | 667 |
667 bool BookmarksUpdateFunction::RunImpl() { | 668 bool BookmarksUpdateFunction::RunOnReady() { |
668 if (!EditBookmarksEnabled()) | 669 if (!EditBookmarksEnabled()) |
669 return false; | 670 return false; |
670 | 671 |
671 scoped_ptr<bookmarks::Update::Params> params( | 672 scoped_ptr<bookmarks::Update::Params> params( |
672 bookmarks::Update::Params::Create(*args_)); | 673 bookmarks::Update::Params::Create(*args_)); |
673 EXTENSION_FUNCTION_VALIDATE(params.get()); | 674 EXTENSION_FUNCTION_VALIDATE(params.get()); |
674 | 675 |
675 // Optional but we need to distinguish non present from an empty title. | 676 // Optional but we need to distinguish non present from an empty title. |
676 base::string16 title; | 677 base::string16 title; |
677 bool has_title = false; | 678 bool has_title = false; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 private: | 728 private: |
728 std::map<BucketIdType, Bucket*> buckets_; | 729 std::map<BucketIdType, Bucket*> buckets_; |
729 }; | 730 }; |
730 | 731 |
731 // Mapper for 'bookmarks.create'. Maps "same input to bookmarks.create" to a | 732 // Mapper for 'bookmarks.create'. Maps "same input to bookmarks.create" to a |
732 // unique bucket. | 733 // unique bucket. |
733 class CreateBookmarkBucketMapper : public BookmarkBucketMapper<std::string> { | 734 class CreateBookmarkBucketMapper : public BookmarkBucketMapper<std::string> { |
734 public: | 735 public: |
735 explicit CreateBookmarkBucketMapper(BrowserContext* context) | 736 explicit CreateBookmarkBucketMapper(BrowserContext* context) |
736 : browser_context_(context) {} | 737 : browser_context_(context) {} |
737 // TODO(tim): This should share code with BookmarksCreateFunction::RunImpl, | 738 // TODO(tim): This should share code with BookmarksCreateFunction::RunOnReady, |
738 // but I can't figure out a good way to do that with all the macros. | 739 // but I can't figure out a good way to do that with all the macros. |
739 virtual void GetBucketsForArgs(const base::ListValue* args, | 740 virtual void GetBucketsForArgs(const base::ListValue* args, |
740 BucketList* buckets) OVERRIDE { | 741 BucketList* buckets) OVERRIDE { |
741 const base::DictionaryValue* json; | 742 const base::DictionaryValue* json; |
742 if (!args->GetDictionary(0, &json)) | 743 if (!args->GetDictionary(0, &json)) |
743 return; | 744 return; |
744 | 745 |
745 std::string parent_id; | 746 std::string parent_id; |
746 if (json->HasKey(keys::kParentIdKey)) { | 747 if (json->HasKey(keys::kParentIdKey)) { |
747 if (!json->GetString(keys::kParentIdKey, &parent_id)) | 748 if (!json->GetString(keys::kParentIdKey, &parent_id)) |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 void BookmarksIOFunction::FileSelectionCanceled(void* params) { | 974 void BookmarksIOFunction::FileSelectionCanceled(void* params) { |
974 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 975 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
975 } | 976 } |
976 | 977 |
977 void BookmarksIOFunction::MultiFilesSelected( | 978 void BookmarksIOFunction::MultiFilesSelected( |
978 const std::vector<base::FilePath>& files, void* params) { | 979 const std::vector<base::FilePath>& files, void* params) { |
979 Release(); // Balanced in BookmarsIOFunction::SelectFile() | 980 Release(); // Balanced in BookmarsIOFunction::SelectFile() |
980 NOTREACHED() << "Should not be able to select multiple files"; | 981 NOTREACHED() << "Should not be able to select multiple files"; |
981 } | 982 } |
982 | 983 |
983 bool BookmarksImportFunction::RunImpl() { | 984 bool BookmarksImportFunction::RunOnReady() { |
984 if (!EditBookmarksEnabled()) | 985 if (!EditBookmarksEnabled()) |
985 return false; | 986 return false; |
986 SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE); | 987 SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE); |
987 return true; | 988 return true; |
988 } | 989 } |
989 | 990 |
990 void BookmarksImportFunction::FileSelected(const base::FilePath& path, | 991 void BookmarksImportFunction::FileSelected(const base::FilePath& path, |
991 int index, | 992 int index, |
992 void* params) { | 993 void* params) { |
993 #if !defined(OS_ANDROID) | 994 #if !defined(OS_ANDROID) |
994 // Android does not have support for the standard importers. | 995 // Android does not have support for the standard importers. |
995 // TODO(jgreenwald): remove ifdef once extensions are no longer built on | 996 // TODO(jgreenwald): remove ifdef once extensions are no longer built on |
996 // Android. | 997 // Android. |
997 // Deletes itself. | 998 // Deletes itself. |
998 ExternalProcessImporterHost* importer_host = new ExternalProcessImporterHost; | 999 ExternalProcessImporterHost* importer_host = new ExternalProcessImporterHost; |
999 importer::SourceProfile source_profile; | 1000 importer::SourceProfile source_profile; |
1000 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; | 1001 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; |
1001 source_profile.source_path = path; | 1002 source_profile.source_path = path; |
1002 importer_host->StartImportSettings(source_profile, | 1003 importer_host->StartImportSettings(source_profile, |
1003 GetProfile(), | 1004 GetProfile(), |
1004 importer::FAVORITES, | 1005 importer::FAVORITES, |
1005 new ProfileWriter(GetProfile())); | 1006 new ProfileWriter(GetProfile())); |
1006 | 1007 |
1007 importer::LogImporterUseToMetrics("BookmarksAPI", | 1008 importer::LogImporterUseToMetrics("BookmarksAPI", |
1008 importer::TYPE_BOOKMARKS_FILE); | 1009 importer::TYPE_BOOKMARKS_FILE); |
1009 #endif | 1010 #endif |
1010 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 1011 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
1011 } | 1012 } |
1012 | 1013 |
1013 bool BookmarksExportFunction::RunImpl() { | 1014 bool BookmarksExportFunction::RunOnReady() { |
1014 SelectFile(ui::SelectFileDialog::SELECT_SAVEAS_FILE); | 1015 SelectFile(ui::SelectFileDialog::SELECT_SAVEAS_FILE); |
1015 return true; | 1016 return true; |
1016 } | 1017 } |
1017 | 1018 |
1018 void BookmarksExportFunction::FileSelected(const base::FilePath& path, | 1019 void BookmarksExportFunction::FileSelected(const base::FilePath& path, |
1019 int index, | 1020 int index, |
1020 void* params) { | 1021 void* params) { |
1021 #if !defined(OS_ANDROID) | 1022 #if !defined(OS_ANDROID) |
1022 // Android does not have support for the standard exporter. | 1023 // Android does not have support for the standard exporter. |
1023 // TODO(jgreenwald): remove ifdef once extensions are no longer built on | 1024 // TODO(jgreenwald): remove ifdef once extensions are no longer built on |
1024 // Android. | 1025 // Android. |
1025 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); | 1026 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); |
1026 #endif | 1027 #endif |
1027 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 1028 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
1028 } | 1029 } |
1029 | 1030 |
1030 } // namespace extensions | 1031 } // namespace extensions |
OLD | NEW |