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

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

Issue 7012005: Revert "Revert 84829 - Initial implementation of "Synced Bookmarks" folder." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Trying to set .json eol-style Created 9 years, 7 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 #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 "build/build_config.h" 9 #include "build/build_config.h"
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 // star id and type. BookmarkNodes are returned from a BookmarkModel. 43 // star id and type. BookmarkNodes are returned from a BookmarkModel.
44 // 44 //
45 class BookmarkNode : public ui::TreeNode<BookmarkNode> { 45 class BookmarkNode : public ui::TreeNode<BookmarkNode> {
46 friend class BookmarkModel; 46 friend class BookmarkModel;
47 47
48 public: 48 public:
49 enum Type { 49 enum Type {
50 URL, 50 URL,
51 FOLDER, 51 FOLDER,
52 BOOKMARK_BAR, 52 BOOKMARK_BAR,
53 OTHER_NODE 53 OTHER_NODE,
54 SYNCED
54 }; 55 };
55 // Creates a new node with the specified url and id of 0 56 // Creates a new node with the specified url and id of 0
56 explicit BookmarkNode(const GURL& url); 57 explicit BookmarkNode(const GURL& url);
57 // Creates a new node with the specified url and id. 58 // Creates a new node with the specified url and id.
58 BookmarkNode(int64 id, const GURL& url); 59 BookmarkNode(int64 id, const GURL& url);
59 virtual ~BookmarkNode(); 60 virtual ~BookmarkNode();
60 61
61 // Returns the URL. 62 // Returns the URL.
62 const GURL& GetURL() const { return url_; } 63 const GURL& GetURL() const { return url_; }
63 // Sets the URL to the given value. 64 // Sets the URL to the given value.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // this does not. 103 // this does not.
103 const SkBitmap& favicon() const { return favicon_; } 104 const SkBitmap& favicon() const { return favicon_; }
104 void set_favicon(const SkBitmap& icon) { favicon_ = icon; } 105 void set_favicon(const SkBitmap& icon) { favicon_ = icon; }
105 106
106 // The following methods are used by the bookmark model, and are not 107 // The following methods are used by the bookmark model, and are not
107 // really useful outside of it. 108 // really useful outside of it.
108 109
109 bool is_favicon_loaded() const { return loaded_favicon_; } 110 bool is_favicon_loaded() const { return loaded_favicon_; }
110 void set_favicon_loaded(bool value) { loaded_favicon_ = value; } 111 void set_favicon_loaded(bool value) { loaded_favicon_ = value; }
111 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 bool IsVisible() const;
121
112 HistoryService::Handle favicon_load_handle() const { 122 HistoryService::Handle favicon_load_handle() const {
113 return favicon_load_handle_; 123 return favicon_load_handle_;
114 } 124 }
115 void set_favicon_load_handle(HistoryService::Handle handle) { 125 void set_favicon_load_handle(HistoryService::Handle handle) {
116 favicon_load_handle_ = handle; 126 favicon_load_handle_ = handle;
117 } 127 }
118 128
119 // Called when the favicon becomes invalid. 129 // Called when the favicon becomes invalid.
120 void InvalidateFavicon(); 130 void InvalidateFavicon();
121 131
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // Returns the root node. The bookmark bar node and other node are children of 196 // Returns the root node. The bookmark bar node and other node are children of
187 // the root node. 197 // the root node.
188 const BookmarkNode* root_node() { return &root_; } 198 const BookmarkNode* root_node() { return &root_; }
189 199
190 // Returns the bookmark bar node. This is NULL until loaded. 200 // Returns the bookmark bar node. This is NULL until loaded.
191 const BookmarkNode* GetBookmarkBarNode() { return bookmark_bar_node_; } 201 const BookmarkNode* GetBookmarkBarNode() { return bookmark_bar_node_; }
192 202
193 // Returns the 'other' node. This is NULL until loaded. 203 // Returns the 'other' node. This is NULL until loaded.
194 const BookmarkNode* other_node() { return other_node_; } 204 const BookmarkNode* other_node() { return other_node_; }
195 205
206 // Returns the 'synced' node. This is NULL until loaded.
207 const BookmarkNode* synced_node() { return synced_node_; }
208
196 // 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
197 // (as long as the model is loaded). 210 // (as long as the model is loaded).
198 const BookmarkNode* GetParentForNewNodes(); 211 const BookmarkNode* GetParentForNewNodes();
199 212
200 void AddObserver(BookmarkModelObserver* observer) { 213 void AddObserver(BookmarkModelObserver* observer) {
201 observers_.AddObserver(observer); 214 observers_.AddObserver(observer);
202 } 215 }
203 216
204 void RemoveObserver(BookmarkModelObserver* observer) { 217 void RemoveObserver(BookmarkModelObserver* observer) {
205 observers_.RemoveObserver(observer); 218 observers_.RemoveObserver(observer);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 const string16& text, 317 const string16& text,
305 size_t max_count, 318 size_t max_count,
306 std::vector<bookmark_utils::TitleMatch>* matches); 319 std::vector<bookmark_utils::TitleMatch>* matches);
307 320
308 Profile* profile() const { return profile_; } 321 Profile* profile() const { return profile_; }
309 322
310 bool is_root(const BookmarkNode* node) const { return node == &root_; } 323 bool is_root(const BookmarkNode* node) const { return node == &root_; }
311 bool is_bookmark_bar_node(const BookmarkNode* node) const { 324 bool is_bookmark_bar_node(const BookmarkNode* node) const {
312 return node == bookmark_bar_node_; 325 return node == bookmark_bar_node_;
313 } 326 }
327 bool is_synced_bookmarks_node(const BookmarkNode* node) const {
328 return node == synced_node_;
329 }
314 bool is_other_bookmarks_node(const BookmarkNode* node) const { 330 bool is_other_bookmarks_node(const BookmarkNode* node) const {
315 return node == other_node_; 331 return node == other_node_;
316 } 332 }
317 // Returns whether the given node is one of the permanent nodes - root node, 333 // Returns whether the given node is one of the permanent nodes - root node,
318 // bookmark bar node or other bookmarks node. 334 // bookmark bar node or other bookmarks node.
319 bool is_permanent_node(const BookmarkNode* node) const { 335 bool is_permanent_node(const BookmarkNode* node) const {
320 return is_root(node) || 336 return is_root(node) ||
321 is_bookmark_bar_node(node) || 337 is_bookmark_bar_node(node) ||
322 is_other_bookmarks_node(node); 338 is_other_bookmarks_node(node) ||
339 is_synced_bookmarks_node(node);
323 } 340 }
324 341
325 // Sets the store to NULL, making it so the BookmarkModel does not persist 342 // Sets the store to NULL, making it so the BookmarkModel does not persist
326 // any changes to disk. This is only useful during testing to speed up 343 // any changes to disk. This is only useful during testing to speed up
327 // testing. 344 // testing.
328 void ClearStore(); 345 void ClearStore();
329 346
330 // Returns whether the bookmarks file changed externally. 347 // Returns whether the bookmarks file changed externally.
331 bool file_changed() const { return file_changed_; } 348 bool file_changed() const { return file_changed_; }
332 349
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 int index, 390 int index,
374 BookmarkNode* node, 391 BookmarkNode* node,
375 bool was_bookmarked); 392 bool was_bookmarked);
376 393
377 // Implementation of GetNodeByID. 394 // Implementation of GetNodeByID.
378 const BookmarkNode* GetNodeByID(const BookmarkNode* node, int64 id); 395 const BookmarkNode* GetNodeByID(const BookmarkNode* node, int64 id);
379 396
380 // Returns true if the parent and index are valid. 397 // Returns true if the parent and index are valid.
381 bool IsValidIndex(const BookmarkNode* parent, int index, bool allow_end); 398 bool IsValidIndex(const BookmarkNode* parent, int index, bool allow_end);
382 399
383 // Creates the bookmark bar/other nodes. These call into 400 // Creates the bookmark bar/synced/other nodes. These call into
384 // CreateRootNodeFromStarredEntry. 401 // CreateRootNodeFromStarredEntry.
385 BookmarkNode* CreateBookmarkNode(); 402 BookmarkNode* CreateBookmarkNode();
386 BookmarkNode* CreateOtherBookmarksNode(); 403 BookmarkNode* CreateOtherBookmarksNode();
404 BookmarkNode* CreateSyncedBookmarksNode();
387 405
388 // Creates a root node (either the bookmark bar node or other node) from the 406 // Creates a root node (either the bookmark bar node or other node) from the
389 // specified starred entry. 407 // specified starred entry.
390 BookmarkNode* CreateRootNodeFromStarredEntry( 408 BookmarkNode* CreateRootNodeFromStarredEntry(
391 const history::StarredEntry& entry); 409 const history::StarredEntry& entry);
392 410
393 // Notification that a favicon has finished loading. If we can decode the 411 // Notification that a favicon has finished loading. If we can decode the
394 // favicon, FaviconLoaded is invoked. 412 // favicon, FaviconLoaded is invoked.
395 void OnFaviconDataAvailable(FaviconService::Handle handle, 413 void OnFaviconDataAvailable(FaviconService::Handle handle,
396 history::FaviconData favicon); 414 history::FaviconData favicon);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 // Whether the bookmarks file was changed externally. This is set after 450 // Whether the bookmarks file was changed externally. This is set after
433 // loading is complete and once set the value never changes. 451 // loading is complete and once set the value never changes.
434 bool file_changed_; 452 bool file_changed_;
435 453
436 // The root node. This contains the bookmark bar node and the 'other' node as 454 // The root node. This contains the bookmark bar node and the 'other' node as
437 // children. 455 // children.
438 BookmarkNode root_; 456 BookmarkNode root_;
439 457
440 BookmarkNode* bookmark_bar_node_; 458 BookmarkNode* bookmark_bar_node_;
441 BookmarkNode* other_node_; 459 BookmarkNode* other_node_;
460 BookmarkNode* synced_node_;
442 461
443 // The maximum ID assigned to the bookmark nodes in the model. 462 // The maximum ID assigned to the bookmark nodes in the model.
444 int64 next_node_id_; 463 int64 next_node_id_;
445 464
446 // The observers. 465 // The observers.
447 ObserverList<BookmarkModelObserver> observers_; 466 ObserverList<BookmarkModelObserver> observers_;
448 467
449 // Set of nodes ordered by URL. This is not a map to avoid copying the 468 // Set of nodes ordered by URL. This is not a map to avoid copying the
450 // urls. 469 // urls.
451 // WARNING: nodes_ordered_by_url_set_ is accessed on multiple threads. As 470 // WARNING: nodes_ordered_by_url_set_ is accessed on multiple threads. As
452 // such, be sure and wrap all usage of it around url_lock_. 471 // such, be sure and wrap all usage of it around url_lock_.
453 typedef std::multiset<BookmarkNode*, NodeURLComparator> NodesOrderedByURLSet; 472 typedef std::multiset<BookmarkNode*, NodeURLComparator> NodesOrderedByURLSet;
454 NodesOrderedByURLSet nodes_ordered_by_url_set_; 473 NodesOrderedByURLSet nodes_ordered_by_url_set_;
455 base::Lock url_lock_; 474 base::Lock url_lock_;
456 475
457 // Used for loading favicons and the empty history request. 476 // Used for loading favicons and the empty history request.
458 CancelableRequestConsumerTSimple<BookmarkNode*> load_consumer_; 477 CancelableRequestConsumerTSimple<BookmarkNode*> load_consumer_;
459 478
460 // Reads/writes bookmarks to disk. 479 // Reads/writes bookmarks to disk.
461 scoped_refptr<BookmarkStorage> store_; 480 scoped_refptr<BookmarkStorage> store_;
462 481
463 scoped_ptr<BookmarkIndex> index_; 482 scoped_ptr<BookmarkIndex> index_;
464 483
465 base::WaitableEvent loaded_signal_; 484 base::WaitableEvent loaded_signal_;
466 485
467 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); 486 DISALLOW_COPY_AND_ASSIGN(BookmarkModel);
468 }; 487 };
469 488
470 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_ 489 #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