OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bookmarks/bookmark_model.h" | 5 #include "chrome/browser/bookmarks/bookmark_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "chrome/browser/bookmarks/bookmark_expanded_state_tracker.h" | 15 #include "chrome/browser/bookmarks/bookmark_expanded_state_tracker.h" |
16 #include "chrome/browser/bookmarks/bookmark_index.h" | 16 #include "chrome/browser/bookmarks/bookmark_index.h" |
17 #include "chrome/browser/bookmarks/bookmark_model_observer.h" | 17 #include "chrome/browser/bookmarks/bookmark_model_observer.h" |
18 #include "chrome/browser/bookmarks/bookmark_storage.h" | 18 #include "chrome/browser/bookmarks/bookmark_storage.h" |
19 #include "chrome/browser/bookmarks/bookmark_utils.h" | 19 #include "chrome/browser/bookmarks/bookmark_utils.h" |
20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/history/history_notifications.h" | 21 #include "chrome/browser/history/history_notifications.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
27 #include "content/common/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
28 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
30 #include "ui/base/l10n/l10n_util_collator.h" | 30 #include "ui/base/l10n/l10n_util_collator.h" |
31 #include "ui/gfx/codec/png_codec.h" | 31 #include "ui/gfx/codec/png_codec.h" |
32 | 32 |
33 using base::Time; | 33 using base::Time; |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 // Helper to get a mutable bookmark node. | 37 // Helper to get a mutable bookmark node. |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 | 608 |
609 loaded_ = true; | 609 loaded_ = true; |
610 | 610 |
611 loaded_signal_.Signal(); | 611 loaded_signal_.Signal(); |
612 | 612 |
613 // Notify our direct observers. | 613 // Notify our direct observers. |
614 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, | 614 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, |
615 Loaded(this, details->ids_reassigned())); | 615 Loaded(this, details->ids_reassigned())); |
616 | 616 |
617 // And generic notification. | 617 // And generic notification. |
618 NotificationService::current()->Notify( | 618 content::NotificationService::current()->Notify( |
619 chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, | 619 chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, |
620 content::Source<Profile>(profile_), | 620 content::Source<Profile>(profile_), |
621 NotificationService::NoDetails()); | 621 content::NotificationService::NoDetails()); |
622 } | 622 } |
623 | 623 |
624 void BookmarkModel::RemoveAndDeleteNode(BookmarkNode* delete_me) { | 624 void BookmarkModel::RemoveAndDeleteNode(BookmarkNode* delete_me) { |
625 scoped_ptr<BookmarkNode> node(delete_me); | 625 scoped_ptr<BookmarkNode> node(delete_me); |
626 | 626 |
627 BookmarkNode* parent = AsMutable(node->parent()); | 627 BookmarkNode* parent = AsMutable(node->parent()); |
628 DCHECK(parent); | 628 DCHECK(parent); |
629 int index = parent->GetIndexOf(node.get()); | 629 int index = parent->GetIndexOf(node.get()); |
630 parent->Remove(node.get()); | 630 parent->Remove(node.get()); |
631 history::URLsStarredDetails details(false); | 631 history::URLsStarredDetails details(false); |
(...skipping 28 matching lines...) Expand all Loading... |
660 return; | 660 return; |
661 } | 661 } |
662 | 662 |
663 if (profile_) { | 663 if (profile_) { |
664 HistoryService* history = | 664 HistoryService* history = |
665 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 665 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
666 if (history) | 666 if (history) |
667 history->URLsNoLongerBookmarked(details.changed_urls); | 667 history->URLsNoLongerBookmarked(details.changed_urls); |
668 } | 668 } |
669 | 669 |
670 NotificationService::current()->Notify( | 670 content::NotificationService::current()->Notify( |
671 chrome::NOTIFICATION_URLS_STARRED, | 671 chrome::NOTIFICATION_URLS_STARRED, |
672 content::Source<Profile>(profile_), | 672 content::Source<Profile>(profile_), |
673 content::Details<history::URLsStarredDetails>(&details)); | 673 content::Details<history::URLsStarredDetails>(&details)); |
674 } | 674 } |
675 | 675 |
676 BookmarkNode* BookmarkModel::AddNode(BookmarkNode* parent, | 676 BookmarkNode* BookmarkModel::AddNode(BookmarkNode* parent, |
677 int index, | 677 int index, |
678 BookmarkNode* node, | 678 BookmarkNode* node, |
679 bool was_bookmarked) { | 679 bool was_bookmarked) { |
680 parent->Add(node, index); | 680 parent->Add(node, index); |
681 | 681 |
682 if (store_.get()) | 682 if (store_.get()) |
683 store_->ScheduleSave(); | 683 store_->ScheduleSave(); |
684 | 684 |
685 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, | 685 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, |
686 BookmarkNodeAdded(this, parent, index)); | 686 BookmarkNodeAdded(this, parent, index)); |
687 | 687 |
688 index_->Add(node); | 688 index_->Add(node); |
689 | 689 |
690 if (node->is_url() && !was_bookmarked) { | 690 if (node->is_url() && !was_bookmarked) { |
691 history::URLsStarredDetails details(true); | 691 history::URLsStarredDetails details(true); |
692 details.changed_urls.insert(node->url()); | 692 details.changed_urls.insert(node->url()); |
693 NotificationService::current()->Notify( | 693 content::NotificationService::current()->Notify( |
694 chrome::NOTIFICATION_URLS_STARRED, | 694 chrome::NOTIFICATION_URLS_STARRED, |
695 content::Source<Profile>(profile_), | 695 content::Source<Profile>(profile_), |
696 content::Details<history::URLsStarredDetails>(&details)); | 696 content::Details<history::URLsStarredDetails>(&details)); |
697 } | 697 } |
698 return node; | 698 return node; |
699 } | 699 } |
700 | 700 |
701 const BookmarkNode* BookmarkModel::GetNodeByID(const BookmarkNode* node, | 701 const BookmarkNode* BookmarkModel::GetNodeByID(const BookmarkNode* node, |
702 int64 id) { | 702 int64 id) { |
703 if (node->id() == id) | 703 if (node->id() == id) |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 file_changed_ = true; | 833 file_changed_ = true; |
834 } | 834 } |
835 | 835 |
836 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { | 836 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { |
837 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); | 837 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); |
838 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); | 838 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); |
839 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); | 839 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); |
840 return new BookmarkLoadDetails(bb_node, other_node, synced_node, | 840 return new BookmarkLoadDetails(bb_node, other_node, synced_node, |
841 new BookmarkIndex(profile_), next_node_id_); | 841 new BookmarkIndex(profile_), next_node_id_); |
842 } | 842 } |
OLD | NEW |