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

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

Issue 8759017: BookmarkModel cleanup. synced_node is now mobile_node and I'm nuking (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to trunk fix sync_integration_tests and extension test Created 9 years 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/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"
13 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
14 #include "base/string_util.h" 13 #include "base/string_util.h"
15 #include "build/build_config.h" 14 #include "build/build_config.h"
16 #include "chrome/browser/bookmarks/bookmark_expanded_state_tracker.h" 15 #include "chrome/browser/bookmarks/bookmark_expanded_state_tracker.h"
17 #include "chrome/browser/bookmarks/bookmark_index.h" 16 #include "chrome/browser/bookmarks/bookmark_index.h"
18 #include "chrome/browser/bookmarks/bookmark_model_observer.h" 17 #include "chrome/browser/bookmarks/bookmark_model_observer.h"
19 #include "chrome/browser/bookmarks/bookmark_storage.h" 18 #include "chrome/browser/bookmarks/bookmark_storage.h"
20 #include "chrome/browser/bookmarks/bookmark_utils.h" 19 #include "chrome/browser/bookmarks/bookmark_utils.h"
21 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/history/history_notifications.h" 21 #include "chrome/browser/history/history_notifications.h"
23 #include "chrome/browser/prefs/pref_service.h" 22 #include "chrome/browser/prefs/pref_service.h"
24 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/common/chrome_notification_types.h" 24 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
28 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
29 #include "grit/generated_resources.h" 27 #include "grit/generated_resources.h"
30 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/l10n/l10n_util_collator.h" 29 #include "ui/base/l10n/l10n_util_collator.h"
32 #include "ui/gfx/codec/png_codec.h" 30 #include "ui/gfx/codec/png_codec.h"
33 31
34 using base::Time; 32 using base::Time;
35 33
36 namespace { 34 namespace {
(...skipping 13 matching lines...) Expand all
50 } 48 }
51 49
52 BookmarkNode::BookmarkNode(int64 id, const GURL& url) 50 BookmarkNode::BookmarkNode(int64 id, const GURL& url)
53 : url_(url) { 51 : url_(url) {
54 Initialize(id); 52 Initialize(id);
55 } 53 }
56 54
57 BookmarkNode::~BookmarkNode() { 55 BookmarkNode::~BookmarkNode() {
58 } 56 }
59 57
60 bool BookmarkNode::IsVisible() const {
61 return true;
62 }
63
64 void BookmarkNode::Initialize(int64 id) { 58 void BookmarkNode::Initialize(int64 id) {
65 id_ = id; 59 id_ = id;
66 type_ = url_.is_empty() ? FOLDER : URL; 60 type_ = url_.is_empty() ? FOLDER : URL;
67 date_added_ = Time::Now(); 61 date_added_ = Time::Now();
68 is_favicon_loaded_ = false; 62 is_favicon_loaded_ = false;
69 favicon_load_handle_ = 0; 63 favicon_load_handle_ = 0;
70 } 64 }
71 65
72 void BookmarkNode::InvalidateFavicon() { 66 void BookmarkNode::InvalidateFavicon() {
73 favicon_ = SkBitmap(); 67 favicon_ = SkBitmap();
74 is_favicon_loaded_ = false; 68 is_favicon_loaded_ = false;
75 } 69 }
76 70
77 // BookmarkPermanentNode ------------------------------------------------------
78
79 BookmarkPermanentNode::BookmarkPermanentNode(int64 id,
80 const GURL& url,
81 Profile* profile)
82 : BookmarkNode(id, url),
83 profile_(profile) {
84 }
85
86 BookmarkPermanentNode::~BookmarkPermanentNode() {
87 }
88
89 bool BookmarkPermanentNode::IsVisible() const {
90 // The synced bookmark folder is invisible if the flag isn't set and there are
91 // no bookmarks under it.
92 return type() != BookmarkNode::SYNCED ||
93 CommandLine::ForCurrentProcess()->HasSwitch(
94 switches::kEnableSyncedBookmarksFolder) ||
95 !empty();
96 }
97
98 // BookmarkModel -------------------------------------------------------------- 71 // BookmarkModel --------------------------------------------------------------
99 72
100 namespace { 73 namespace {
101 74
102 // Comparator used when sorting bookmarks. Folders are sorted first, then 75 // Comparator used when sorting bookmarks. Folders are sorted first, then
103 // bookmarks. 76 // bookmarks.
104 class SortComparator : public std::binary_function<const BookmarkNode*, 77 class SortComparator : public std::binary_function<const BookmarkNode*,
105 const BookmarkNode*, 78 const BookmarkNode*,
106 bool> { 79 bool> {
107 public: 80 public:
(...skipping 18 matching lines...) Expand all
126 99
127 } // namespace 100 } // namespace
128 101
129 BookmarkModel::BookmarkModel(Profile* profile) 102 BookmarkModel::BookmarkModel(Profile* profile)
130 : profile_(profile), 103 : profile_(profile),
131 loaded_(false), 104 loaded_(false),
132 file_changed_(false), 105 file_changed_(false),
133 root_(GURL()), 106 root_(GURL()),
134 bookmark_bar_node_(NULL), 107 bookmark_bar_node_(NULL),
135 other_node_(NULL), 108 other_node_(NULL),
136 synced_node_(NULL), 109 mobile_node_(NULL),
137 next_node_id_(1), 110 next_node_id_(1),
138 observers_(ObserverList<BookmarkModelObserver>::NOTIFY_EXISTING_ONLY), 111 observers_(ObserverList<BookmarkModelObserver>::NOTIFY_EXISTING_ONLY),
139 loaded_signal_(true, false) { 112 loaded_signal_(true, false) {
140 if (!profile_) { 113 if (!profile_) {
141 // Profile is null during testing. 114 // Profile is null during testing.
142 DoneLoading(CreateLoadDetails()); 115 DoneLoading(CreateLoadDetails());
143 } 116 }
144 } 117 }
145 118
146 BookmarkModel::~BookmarkModel() { 119 BookmarkModel::~BookmarkModel() {
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 details->ids_reassigned()) { 564 details->ids_reassigned()) {
592 // If bookmarks file changed externally, the IDs may have changed 565 // If bookmarks file changed externally, the IDs may have changed
593 // externally. In that case, the decoder may have reassigned IDs to make 566 // externally. In that case, the decoder may have reassigned IDs to make
594 // them unique. So when the file has changed externally, we should save the 567 // them unique. So when the file has changed externally, we should save the
595 // bookmarks file to persist new IDs. 568 // bookmarks file to persist new IDs.
596 if (store_.get()) 569 if (store_.get())
597 store_->ScheduleSave(); 570 store_->ScheduleSave();
598 } 571 }
599 bookmark_bar_node_ = details->release_bb_node(); 572 bookmark_bar_node_ = details->release_bb_node();
600 other_node_ = details->release_other_folder_node(); 573 other_node_ = details->release_other_folder_node();
601 synced_node_ = details->release_synced_folder_node(); 574 mobile_node_ = details->release_mobile_folder_node();
602 index_.reset(details->release_index()); 575 index_.reset(details->release_index());
603 576
604 // WARNING: order is important here, various places assume the order is 577 // WARNING: order is important here, various places assume the order is
605 // constant. 578 // constant.
606 root_.Add(bookmark_bar_node_, 0); 579 root_.Add(bookmark_bar_node_, 0);
607 root_.Add(other_node_, 1); 580 root_.Add(other_node_, 1);
608 root_.Add(synced_node_, 2); 581 root_.Add(mobile_node_, 2);
609 582
610 { 583 {
611 base::AutoLock url_lock(url_lock_); 584 base::AutoLock url_lock(url_lock_);
612 // Update nodes_ordered_by_url_set_ from the nodes. 585 // Update nodes_ordered_by_url_set_ from the nodes.
613 PopulateNodesByURL(&root_); 586 PopulateNodesByURL(&root_);
614 } 587 }
615 588
616 loaded_ = true; 589 loaded_ = true;
617 590
618 loaded_signal_.Signal(); 591 loaded_signal_.Signal();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 int index, 695 int index,
723 bool allow_end) { 696 bool allow_end) {
724 return (parent && parent->is_folder() && 697 return (parent && parent->is_folder() &&
725 (index >= 0 && (index < parent->child_count() || 698 (index >= 0 && (index < parent->child_count() ||
726 (allow_end && index == parent->child_count())))); 699 (allow_end && index == parent->child_count()))));
727 } 700 }
728 701
729 BookmarkNode* BookmarkModel::CreatePermanentNode(BookmarkNode::Type type) { 702 BookmarkNode* BookmarkModel::CreatePermanentNode(BookmarkNode::Type type) {
730 DCHECK(type == BookmarkNode::BOOKMARK_BAR || 703 DCHECK(type == BookmarkNode::BOOKMARK_BAR ||
731 type == BookmarkNode::OTHER_NODE || 704 type == BookmarkNode::OTHER_NODE ||
732 type == BookmarkNode::SYNCED); 705 type == BookmarkNode::MOBILE);
733 BookmarkPermanentNode* node = new BookmarkPermanentNode( 706 BookmarkNode* node = new BookmarkNode(generate_next_node_id(), GURL());
734 generate_next_node_id(), GURL(), profile_);
735 node->set_type(type); 707 node->set_type(type);
736 if (type == BookmarkNode::BOOKMARK_BAR) { 708 if (type == BookmarkNode::BOOKMARK_BAR) {
737 node->set_title(l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_FOLDER_NAME)); 709 node->set_title(l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_FOLDER_NAME));
738 } else if (type == BookmarkNode::OTHER_NODE) { 710 } else if (type == BookmarkNode::OTHER_NODE) {
739 node->set_title( 711 node->set_title(
740 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_OTHER_FOLDER_NAME)); 712 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_OTHER_FOLDER_NAME));
741 } else { 713 } else {
742 node->set_title( 714 node->set_title(
743 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_SYNCED_FOLDER_NAME)); 715 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_MOBILE_FOLDER_NAME));
744 } 716 }
745 return node; 717 return node;
746 } 718 }
747 719
748 void BookmarkModel::OnFaviconDataAvailable( 720 void BookmarkModel::OnFaviconDataAvailable(
749 FaviconService::Handle handle, 721 FaviconService::Handle handle,
750 history::FaviconData favicon) { 722 history::FaviconData favicon) {
751 SkBitmap favicon_bitmap; 723 SkBitmap favicon_bitmap;
752 BookmarkNode* node = 724 BookmarkNode* node =
753 load_consumer_.GetClientData( 725 load_consumer_.GetClientData(
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 PopulateNodesByURL(node->GetChild(i)); 804 PopulateNodesByURL(node->GetChild(i));
833 } 805 }
834 806
835 int64 BookmarkModel::generate_next_node_id() { 807 int64 BookmarkModel::generate_next_node_id() {
836 return next_node_id_++; 808 return next_node_id_++;
837 } 809 }
838 810
839 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { 811 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() {
840 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); 812 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR);
841 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); 813 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE);
842 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); 814 BookmarkNode* mobile_node = CreatePermanentNode(BookmarkNode::MOBILE);
843 return new BookmarkLoadDetails(bb_node, other_node, synced_node, 815 return new BookmarkLoadDetails(bb_node, other_node, mobile_node,
844 new BookmarkIndex(profile_), next_node_id_); 816 new BookmarkIndex(profile_), next_node_id_);
845 } 817 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_model.h ('k') | chrome/browser/bookmarks/bookmark_model_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698