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

Side by Side Diff: chrome/browser/bookmarks/bookmark_model.cc

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
OLDNEW
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/callback.h" 10 #include "base/callback.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/bookmarks/bookmark_index.h" 14 #include "chrome/browser/bookmarks/bookmark_index.h"
15 #include "chrome/browser/bookmarks/bookmark_storage.h" 15 #include "chrome/browser/bookmarks/bookmark_storage.h"
16 #include "chrome/browser/bookmarks/bookmark_utils.h" 16 #include "chrome/browser/bookmarks/bookmark_utils.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/history/history_notifications.h" 18 #include "chrome/browser/history/history_notifications.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
21 #include "content/common/notification_service.h" 22 #include "content/common/notification_service.h"
22 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
23 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/l10n/l10n_util_collator.h" 25 #include "ui/base/l10n/l10n_util_collator.h"
25 #include "ui/gfx/codec/png_codec.h" 26 #include "ui/gfx/codec/png_codec.h"
26 27
27 using base::Time; 28 using base::Time;
28 29
29 namespace { 30 namespace {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 void BookmarkModel::Load() { 137 void BookmarkModel::Load() {
137 if (store_.get()) { 138 if (store_.get()) {
138 // If the store is non-null, it means Load was already invoked. Load should 139 // If the store is non-null, it means Load was already invoked. Load should
139 // only be invoked once. 140 // only be invoked once.
140 NOTREACHED(); 141 NOTREACHED();
141 return; 142 return;
142 } 143 }
143 144
144 // Listen for changes to favicons so that we can update the favicon of the 145 // Listen for changes to favicons so that we can update the favicon of the
145 // node appropriately. 146 // node appropriately.
146 registrar_.Add(this, NotificationType::FAVICON_CHANGED, 147 registrar_.Add(this, chrome::NOTIFICATION_FAVICON_CHANGED,
147 Source<Profile>(profile_)); 148 Source<Profile>(profile_));
148 149
149 // Load the bookmarks. BookmarkStorage notifies us when done. 150 // Load the bookmarks. BookmarkStorage notifies us when done.
150 store_ = new BookmarkStorage(profile_, this); 151 store_ = new BookmarkStorage(profile_, this);
151 store_->LoadBookmarks(CreateLoadDetails()); 152 store_->LoadBookmarks(CreateLoadDetails());
152 } 153 }
153 154
154 const BookmarkNode* BookmarkModel::GetParentForNewNodes() { 155 const BookmarkNode* BookmarkModel::GetParentForNewNodes() {
155 std::vector<const BookmarkNode*> nodes = 156 std::vector<const BookmarkNode*> nodes =
156 bookmark_utils::GetMostRecentlyModifiedFolders(this, 1); 157 bookmark_utils::GetMostRecentlyModifiedFolders(this, 1);
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 575
575 loaded_ = true; 576 loaded_ = true;
576 577
577 loaded_signal_.Signal(); 578 loaded_signal_.Signal();
578 579
579 // Notify our direct observers. 580 // Notify our direct observers.
580 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, Loaded(this)); 581 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, Loaded(this));
581 582
582 // And generic notification. 583 // And generic notification.
583 NotificationService::current()->Notify( 584 NotificationService::current()->Notify(
584 NotificationType::BOOKMARK_MODEL_LOADED, 585 chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED,
585 Source<Profile>(profile_), 586 Source<Profile>(profile_),
586 NotificationService::NoDetails()); 587 NotificationService::NoDetails());
587 } 588 }
588 589
589 void BookmarkModel::RemoveAndDeleteNode(BookmarkNode* delete_me) { 590 void BookmarkModel::RemoveAndDeleteNode(BookmarkNode* delete_me) {
590 scoped_ptr<BookmarkNode> node(delete_me); 591 scoped_ptr<BookmarkNode> node(delete_me);
591 592
592 BookmarkNode* parent = AsMutable(node->parent()); 593 BookmarkNode* parent = AsMutable(node->parent());
593 DCHECK(parent); 594 DCHECK(parent);
594 int index = parent->GetIndexOf(node.get()); 595 int index = parent->GetIndexOf(node.get());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 } 627 }
627 628
628 if (profile_) { 629 if (profile_) {
629 HistoryService* history = 630 HistoryService* history =
630 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 631 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
631 if (history) 632 if (history)
632 history->URLsNoLongerBookmarked(details.changed_urls); 633 history->URLsNoLongerBookmarked(details.changed_urls);
633 } 634 }
634 635
635 NotificationService::current()->Notify( 636 NotificationService::current()->Notify(
636 NotificationType::URLS_STARRED, 637 chrome::NOTIFICATION_URLS_STARRED,
637 Source<Profile>(profile_), 638 Source<Profile>(profile_),
638 Details<history::URLsStarredDetails>(&details)); 639 Details<history::URLsStarredDetails>(&details));
639 } 640 }
640 641
641 void BookmarkModel::BeginImportMode() { 642 void BookmarkModel::BeginImportMode() {
642 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, 643 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_,
643 BookmarkImportBeginning(this)); 644 BookmarkImportBeginning(this));
644 } 645 }
645 646
646 void BookmarkModel::EndImportMode() { 647 void BookmarkModel::EndImportMode() {
(...skipping 12 matching lines...) Expand all
659 660
660 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, 661 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_,
661 BookmarkNodeAdded(this, parent, index)); 662 BookmarkNodeAdded(this, parent, index));
662 663
663 index_->Add(node); 664 index_->Add(node);
664 665
665 if (node->is_url() && !was_bookmarked) { 666 if (node->is_url() && !was_bookmarked) {
666 history::URLsStarredDetails details(true); 667 history::URLsStarredDetails details(true);
667 details.changed_urls.insert(node->GetURL()); 668 details.changed_urls.insert(node->GetURL());
668 NotificationService::current()->Notify( 669 NotificationService::current()->Notify(
669 NotificationType::URLS_STARRED, 670 chrome::NOTIFICATION_URLS_STARRED,
670 Source<Profile>(profile_), 671 Source<Profile>(profile_),
671 Details<history::URLsStarredDetails>(&details)); 672 Details<history::URLsStarredDetails>(&details));
672 } 673 }
673 return node; 674 return node;
674 } 675 }
675 676
676 void BookmarkModel::BlockTillLoaded() { 677 void BookmarkModel::BlockTillLoaded() {
677 loaded_signal_.Wait(); 678 loaded_signal_.Wait();
678 } 679 }
679 680
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 void BookmarkModel::CancelPendingFaviconLoadRequests(BookmarkNode* node) { 753 void BookmarkModel::CancelPendingFaviconLoadRequests(BookmarkNode* node) {
753 if (node->favicon_load_handle()) { 754 if (node->favicon_load_handle()) {
754 FaviconService* favicon_service = 755 FaviconService* favicon_service =
755 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); 756 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS);
756 if (favicon_service) 757 if (favicon_service)
757 favicon_service->CancelRequest(node->favicon_load_handle()); 758 favicon_service->CancelRequest(node->favicon_load_handle());
758 node->set_favicon_load_handle(0); 759 node->set_favicon_load_handle(0);
759 } 760 }
760 } 761 }
761 762
762 void BookmarkModel::Observe(NotificationType type, 763 void BookmarkModel::Observe(int type,
763 const NotificationSource& source, 764 const NotificationSource& source,
764 const NotificationDetails& details) { 765 const NotificationDetails& details) {
765 switch (type.value) { 766 switch (type) {
766 case NotificationType::FAVICON_CHANGED: { 767 case chrome::NOTIFICATION_FAVICON_CHANGED: {
767 // Prevent the observers from getting confused for multiple favicon loads. 768 // Prevent the observers from getting confused for multiple favicon loads.
768 Details<history::FaviconChangeDetails> favicon_details(details); 769 Details<history::FaviconChangeDetails> favicon_details(details);
769 for (std::set<GURL>::const_iterator i = favicon_details->urls.begin(); 770 for (std::set<GURL>::const_iterator i = favicon_details->urls.begin();
770 i != favicon_details->urls.end(); ++i) { 771 i != favicon_details->urls.end(); ++i) {
771 std::vector<const BookmarkNode*> nodes; 772 std::vector<const BookmarkNode*> nodes;
772 GetNodesByURL(*i, &nodes); 773 GetNodesByURL(*i, &nodes);
773 for (size_t i = 0; i < nodes.size(); ++i) { 774 for (size_t i = 0; i < nodes.size(); ++i) {
774 // Got an updated favicon, for a URL, do a new request. 775 // Got an updated favicon, for a URL, do a new request.
775 BookmarkNode* node = AsMutable(nodes[i]); 776 BookmarkNode* node = AsMutable(nodes[i]);
776 node->InvalidateFavicon(); 777 node->InvalidateFavicon();
(...skipping 28 matching lines...) Expand all
805 file_changed_ = true; 806 file_changed_ = true;
806 } 807 }
807 808
808 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { 809 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() {
809 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); 810 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR);
810 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); 811 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE);
811 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); 812 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED);
812 return new BookmarkLoadDetails(bb_node, other_node, synced_node, 813 return new BookmarkLoadDetails(bb_node, other_node, synced_node,
813 new BookmarkIndex(profile()), next_node_id_); 814 new BookmarkIndex(profile()), next_node_id_);
814 } 815 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698