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

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

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 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_ 5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_
6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_ 6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 // BookmarkNode contains information about a starred entry: title, URL, favicon, 44 // BookmarkNode contains information about a starred entry: title, URL, favicon,
45 // id and type. BookmarkNodes are returned from BookmarkModel. 45 // id and type. BookmarkNodes are returned from BookmarkModel.
46 class BookmarkNode : public ui::TreeNode<BookmarkNode> { 46 class BookmarkNode : public ui::TreeNode<BookmarkNode> {
47 public: 47 public:
48 enum Type { 48 enum Type {
49 URL, 49 URL,
50 FOLDER, 50 FOLDER,
51 BOOKMARK_BAR, 51 BOOKMARK_BAR,
52 OTHER_NODE, 52 OTHER_NODE,
53 SYNCED 53 MOBILE
54 }; 54 };
55 55
56 // Creates a new node with an id of 0 and |url|. 56 // Creates a new node with an id of 0 and |url|.
57 explicit BookmarkNode(const GURL& url); 57 explicit BookmarkNode(const GURL& url);
58 // Creates a new node with |id| and |url|. 58 // Creates a new node with |id| and |url|.
59 BookmarkNode(int64 id, const GURL& url); 59 BookmarkNode(int64 id, const GURL& url);
60 60
61 virtual ~BookmarkNode(); 61 virtual ~BookmarkNode();
62 62
63 // Returns an unique id for this node. 63 // Returns an unique id for this node.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 bool is_favicon_loaded() const { return is_favicon_loaded_; } 103 bool is_favicon_loaded() const { return is_favicon_loaded_; }
104 void set_is_favicon_loaded(bool loaded) { is_favicon_loaded_ = loaded; } 104 void set_is_favicon_loaded(bool loaded) { is_favicon_loaded_ = loaded; }
105 105
106 HistoryService::Handle favicon_load_handle() const { 106 HistoryService::Handle favicon_load_handle() const {
107 return favicon_load_handle_; 107 return favicon_load_handle_;
108 } 108 }
109 void set_favicon_load_handle(HistoryService::Handle handle) { 109 void set_favicon_load_handle(HistoryService::Handle handle) {
110 favicon_load_handle_ = handle; 110 favicon_load_handle_ = handle;
111 } 111 }
112 112
113 // Accessor method for controlling the visibility of a bookmark node/sub-tree.
114 // Note that visibility is not propagated down the tree hierarchy so if a
115 // parent node is marked as invisible, a child node may return "Visible". This
116 // function is primarily useful when traversing the model to generate a UI
117 // representation but we may want to suppress some nodes.
118 // TODO(yfriedman): Remove this when enable-synced-bookmarks-folder is
119 // no longer a command line flag.
120 virtual bool IsVisible() const;
121
122 // TODO(sky): Consider adding last visit time here, it'll greatly simplify 113 // TODO(sky): Consider adding last visit time here, it'll greatly simplify
123 // HistoryContentsProvider. 114 // HistoryContentsProvider.
124 115
125 private: 116 private:
126 friend class BookmarkModel; 117 friend class BookmarkModel;
127 118
128 // A helper function to initialize various fields during construction. 119 // A helper function to initialize various fields during construction.
129 void Initialize(int64 id); 120 void Initialize(int64 id);
130 121
131 // Called when the favicon becomes invalid. 122 // Called when the favicon becomes invalid.
(...skipping 21 matching lines...) Expand all
153 // Whether the favicon has been loaded. 144 // Whether the favicon has been loaded.
154 bool is_favicon_loaded_; 145 bool is_favicon_loaded_;
155 146
156 // If non-zero, it indicates we're loading the favicon and this is the handle 147 // If non-zero, it indicates we're loading the favicon and this is the handle
157 // from the HistoryService. 148 // from the HistoryService.
158 HistoryService::Handle favicon_load_handle_; 149 HistoryService::Handle favicon_load_handle_;
159 150
160 DISALLOW_COPY_AND_ASSIGN(BookmarkNode); 151 DISALLOW_COPY_AND_ASSIGN(BookmarkNode);
161 }; 152 };
162 153
163 // BookmarkPermanentNode ------------------------------------------------------
164
165 // The permanent nodes are the three special top level nodes "bookmark_bar",
166 // "synced" and "other". Their visibility is dependent on information from the
167 // profile, hence this special subclass to accomodate them.
168 class BookmarkPermanentNode : public BookmarkNode {
169 public:
170 // Creates a new node with |id| and |url|.
171 BookmarkPermanentNode(int64 id, const GURL& url, Profile* profile);
172
173 virtual ~BookmarkPermanentNode();
174 virtual bool IsVisible() const OVERRIDE;
175
176 private:
177 Profile* profile_;
178
179 DISALLOW_COPY_AND_ASSIGN(BookmarkPermanentNode);
180 };
181
182 // BookmarkModel -------------------------------------------------------------- 154 // BookmarkModel --------------------------------------------------------------
183 155
184 // BookmarkModel provides a directed acyclic graph of URLs and folders. 156 // BookmarkModel provides a directed acyclic graph of URLs and folders.
185 // Three graphs are provided for the three entry points: those on the 'bookmarks 157 // Three graphs are provided for the three entry points: those on the 'bookmarks
186 // bar', those in the 'other bookmarks' folder and those in the 'synced' folder. 158 // bar', those in the 'other bookmarks' folder and those in the 'mobile' folder.
187 // 159 //
188 // An observer may be attached to observe relevant events. 160 // An observer may be attached to observe relevant events.
189 // 161 //
190 // You should NOT directly create a BookmarkModel, instead go through the 162 // You should NOT directly create a BookmarkModel, instead go through the
191 // Profile. 163 // Profile.
192 class BookmarkModel : public content::NotificationObserver, 164 class BookmarkModel : public content::NotificationObserver,
193 public BookmarkService { 165 public BookmarkService {
194 public: 166 public:
195 explicit BookmarkModel(Profile* profile); 167 explicit BookmarkModel(Profile* profile);
196 virtual ~BookmarkModel(); 168 virtual ~BookmarkModel();
(...skipping 14 matching lines...) Expand all
211 // Returns the root node. The 'bookmark bar' node and 'other' node are 183 // Returns the root node. The 'bookmark bar' node and 'other' node are
212 // children of the root node. 184 // children of the root node.
213 const BookmarkNode* root_node() { return &root_; } 185 const BookmarkNode* root_node() { return &root_; }
214 186
215 // Returns the 'bookmark bar' node. This is NULL until loaded. 187 // Returns the 'bookmark bar' node. This is NULL until loaded.
216 const BookmarkNode* bookmark_bar_node() { return bookmark_bar_node_; } 188 const BookmarkNode* bookmark_bar_node() { return bookmark_bar_node_; }
217 189
218 // Returns the 'other' node. This is NULL until loaded. 190 // Returns the 'other' node. This is NULL until loaded.
219 const BookmarkNode* other_node() { return other_node_; } 191 const BookmarkNode* other_node() { return other_node_; }
220 192
221 // Returns the 'synced' node. This is NULL until loaded. 193 // Returns the 'mobile' node. This is NULL until loaded.
222 const BookmarkNode* synced_node() { return synced_node_; } 194 const BookmarkNode* mobile_node() { return mobile_node_; }
223 195
224 bool is_root_node(const BookmarkNode* node) const { return node == &root_; } 196 bool is_root_node(const BookmarkNode* node) const { return node == &root_; }
225 197
226 // Returns whether the given |node| is one of the permanent nodes - root node, 198 // Returns whether the given |node| is one of the permanent nodes - root node,
227 // 'bookmark bar' node, 'other' node or 'synced' node. 199 // 'bookmark bar' node, 'other' node or 'mobile' node.
228 bool is_permanent_node(const BookmarkNode* node) const { 200 bool is_permanent_node(const BookmarkNode* node) const {
229 return node == &root_ || 201 return node == &root_ ||
230 node == bookmark_bar_node_ || 202 node == bookmark_bar_node_ ||
231 node == other_node_ || 203 node == other_node_ ||
232 node == synced_node_; 204 node == mobile_node_;
233 } 205 }
234 206
235 Profile* profile() const { return profile_; } 207 Profile* profile() const { return profile_; }
236 208
237 // Returns the parent the last node was added to. This never returns NULL 209 // Returns the parent the last node was added to. This never returns NULL
238 // (as long as the model is loaded). 210 // (as long as the model is loaded).
239 const BookmarkNode* GetParentForNewNodes(); 211 const BookmarkNode* GetParentForNewNodes();
240 212
241 void AddObserver(BookmarkModelObserver* observer); 213 void AddObserver(BookmarkModelObserver* observer);
242 void RemoveObserver(BookmarkModelObserver* observer); 214 void RemoveObserver(BookmarkModelObserver* observer);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 BookmarkNode* node, 364 BookmarkNode* node,
393 bool was_bookmarked); 365 bool was_bookmarked);
394 366
395 // Implementation of GetNodeByID. 367 // Implementation of GetNodeByID.
396 const BookmarkNode* GetNodeByID(const BookmarkNode* node, int64 id) const; 368 const BookmarkNode* GetNodeByID(const BookmarkNode* node, int64 id) const;
397 369
398 // Returns true if the parent and index are valid. 370 // Returns true if the parent and index are valid.
399 bool IsValidIndex(const BookmarkNode* parent, int index, bool allow_end); 371 bool IsValidIndex(const BookmarkNode* parent, int index, bool allow_end);
400 372
401 // Creates one of the possible permanent nodes (bookmark bar node, other node 373 // Creates one of the possible permanent nodes (bookmark bar node, other node
402 // and synced node) from |type|. 374 // and mobile node) from |type|.
403 BookmarkNode* CreatePermanentNode(BookmarkNode::Type type); 375 BookmarkNode* CreatePermanentNode(BookmarkNode::Type type);
404 376
405 // Notification that a favicon has finished loading. If we can decode the 377 // Notification that a favicon has finished loading. If we can decode the
406 // favicon, FaviconLoaded is invoked. 378 // favicon, FaviconLoaded is invoked.
407 void OnFaviconDataAvailable(FaviconService::Handle handle, 379 void OnFaviconDataAvailable(FaviconService::Handle handle,
408 history::FaviconData favicon); 380 history::FaviconData favicon);
409 381
410 // Invoked from the node to load the favicon. Requests the favicon from the 382 // Invoked from the node to load the favicon. Requests the favicon from the
411 // favicon service. 383 // favicon service.
412 void LoadFavicon(BookmarkNode* node); 384 void LoadFavicon(BookmarkNode* node);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 // Whether the bookmarks file was changed externally. This is set after 416 // Whether the bookmarks file was changed externally. This is set after
445 // loading is complete and once set the value never changes. 417 // loading is complete and once set the value never changes.
446 bool file_changed_; 418 bool file_changed_;
447 419
448 // The root node. This contains the bookmark bar node and the 'other' node as 420 // The root node. This contains the bookmark bar node and the 'other' node as
449 // children. 421 // children.
450 BookmarkNode root_; 422 BookmarkNode root_;
451 423
452 BookmarkNode* bookmark_bar_node_; 424 BookmarkNode* bookmark_bar_node_;
453 BookmarkNode* other_node_; 425 BookmarkNode* other_node_;
454 BookmarkNode* synced_node_; 426 BookmarkNode* mobile_node_;
455 427
456 // The maximum ID assigned to the bookmark nodes in the model. 428 // The maximum ID assigned to the bookmark nodes in the model.
457 int64 next_node_id_; 429 int64 next_node_id_;
458 430
459 // The observers. 431 // The observers.
460 ObserverList<BookmarkModelObserver> observers_; 432 ObserverList<BookmarkModelObserver> observers_;
461 433
462 // Set of nodes ordered by URL. This is not a map to avoid copying the 434 // Set of nodes ordered by URL. This is not a map to avoid copying the
463 // urls. 435 // urls.
464 // WARNING: |nodes_ordered_by_url_set_| is accessed on multiple threads. As 436 // WARNING: |nodes_ordered_by_url_set_| is accessed on multiple threads. As
(...skipping 11 matching lines...) Expand all
476 scoped_ptr<BookmarkIndex> index_; 448 scoped_ptr<BookmarkIndex> index_;
477 449
478 base::WaitableEvent loaded_signal_; 450 base::WaitableEvent loaded_signal_;
479 451
480 scoped_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_; 452 scoped_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_;
481 453
482 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); 454 DISALLOW_COPY_AND_ASSIGN(BookmarkModel);
483 }; 455 };
484 456
485 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_ 457 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_html_writer_unittest.cc ('k') | chrome/browser/bookmarks/bookmark_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698