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

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

Issue 149310: Always persist bookmark IDs.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 9
10 #include <set> 10 #include <set>
(...skipping 29 matching lines...) Expand all
40 // BookmarkNode contains information about a starred entry: title, URL, favicon, 40 // BookmarkNode contains information about a starred entry: title, URL, favicon,
41 // star id and type. BookmarkNodes are returned from a BookmarkModel. 41 // star id and type. BookmarkNodes are returned from a BookmarkModel.
42 // 42 //
43 class BookmarkNode : public TreeNode<BookmarkNode> { 43 class BookmarkNode : public TreeNode<BookmarkNode> {
44 friend class BookmarkModel; 44 friend class BookmarkModel;
45 45
46 public: 46 public:
47 // Creates a new node with the specified url and id of 0 47 // Creates a new node with the specified url and id of 0
48 explicit BookmarkNode(const GURL& url); 48 explicit BookmarkNode(const GURL& url);
49 // Creates a new node with the specified url and id. 49 // Creates a new node with the specified url and id.
50 BookmarkNode(int id, const GURL& url); 50 BookmarkNode(int64 id, const GURL& url);
51 virtual ~BookmarkNode() {} 51 virtual ~BookmarkNode() {}
52 52
53 // Returns the URL. 53 // Returns the URL.
54 const GURL& GetURL() const { return url_; } 54 const GURL& GetURL() const { return url_; }
55 55
56 // Returns a unique id for this node. 56 // Returns a unique id for this node.
57 // 57 // For bookmark nodes that are managed by the bookmark model, the IDs are
58 // NOTE: this id is only unique for the session and NOT unique across 58 // persisted across sessions.
59 // sessions. Don't persist it! 59 int64 id() const { return id_; }
60 int id() const { return id_; }
61 // Sets the id to the given value. 60 // Sets the id to the given value.
62 void set_id(int id) { id_ = id; } 61 void set_id(int64 id) { id_ = id; }
63 62
64 // Returns the type of this node. 63 // Returns the type of this node.
65 history::StarredEntry::Type GetType() const { return type_; } 64 history::StarredEntry::Type GetType() const { return type_; }
66 void SetType(history::StarredEntry::Type type) { type_ = type; } 65 void SetType(history::StarredEntry::Type type) { type_ = type; }
67 66
68 // Returns the time the bookmark/group was added. 67 // Returns the time the bookmark/group was added.
69 const base::Time& date_added() const { return date_added_; } 68 const base::Time& date_added() const { return date_added_; }
70 // Sets the time the bookmark/group was added. 69 // Sets the time the bookmark/group was added.
71 void set_date_added(const base::Time& date) { date_added_ = date; } 70 void set_date_added(const base::Time& date) { date_added_ = date; }
72 71
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 112
114 // Resets the properties of the node from the supplied entry. 113 // Resets the properties of the node from the supplied entry.
115 // This is used by the bookmark model and not really useful outside of it. 114 // This is used by the bookmark model and not really useful outside of it.
116 void Reset(const history::StarredEntry& entry); 115 void Reset(const history::StarredEntry& entry);
117 116
118 // TODO(sky): Consider adding last visit time here, it'll greatly simplify 117 // TODO(sky): Consider adding last visit time here, it'll greatly simplify
119 // HistoryContentsProvider. 118 // HistoryContentsProvider.
120 119
121 private: 120 private:
122 // helper to initialize various fields during construction. 121 // helper to initialize various fields during construction.
123 void Initialize(int id); 122 void Initialize(int64 id);
124 123
125 // Unique identifier for this node. 124 // Unique identifier for this node.
126 int id_; 125 int64 id_;
127 126
128 // Whether the favicon has been loaded. 127 // Whether the favicon has been loaded.
129 bool loaded_favicon_; 128 bool loaded_favicon_;
130 129
131 // The favicon. 130 // The favicon.
132 SkBitmap favicon_; 131 SkBitmap favicon_;
133 132
134 // If non-zero, it indicates we're loading the favicon and this is the handle 133 // If non-zero, it indicates we're loading the favicon and this is the handle
135 // from the HistoryService. 134 // from the HistoryService.
136 HistoryService::Handle favicon_load_handle_; 135 HistoryService::Handle favicon_load_handle_;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 // Returns true if there is a bookmark for the specified URL. This method is 279 // Returns true if there is a bookmark for the specified URL. This method is
281 // thread safe. See BookmarkService for more details on this. 280 // thread safe. See BookmarkService for more details on this.
282 virtual bool IsBookmarked(const GURL& url); 281 virtual bool IsBookmarked(const GURL& url);
283 282
284 // Blocks until loaded; this is NOT invoked on the main thread. See 283 // Blocks until loaded; this is NOT invoked on the main thread. See
285 // BookmarkService for more details on this. 284 // BookmarkService for more details on this.
286 virtual void BlockTillLoaded(); 285 virtual void BlockTillLoaded();
287 286
288 // Returns the node with the specified id, or NULL if there is no node with 287 // Returns the node with the specified id, or NULL if there is no node with
289 // the specified id. 288 // the specified id.
290 const BookmarkNode* GetNodeByID(int id); 289 const BookmarkNode* GetNodeByID(int64 id);
291 290
292 // Adds a new group node at the specified position. 291 // Adds a new group node at the specified position.
293 const BookmarkNode* AddGroup(const BookmarkNode* parent, 292 const BookmarkNode* AddGroup(const BookmarkNode* parent,
294 int index, 293 int index,
295 const std::wstring& title); 294 const std::wstring& title);
296 295
297 // Adds a url at the specified position. 296 // Adds a url at the specified position.
298 const BookmarkNode* AddURL(const BookmarkNode* parent, 297 const BookmarkNode* AddURL(const BookmarkNode* parent,
299 int index, 298 int index,
300 const std::wstring& title, 299 const std::wstring& title,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 return is_root(node) || 342 return is_root(node) ||
344 is_bookmark_bar_node(node) || 343 is_bookmark_bar_node(node) ||
345 is_other_bookmarks_node(node); 344 is_other_bookmarks_node(node);
346 } 345 }
347 346
348 // Sets the store to NULL, making it so the BookmarkModel does not persist 347 // Sets the store to NULL, making it so the BookmarkModel does not persist
349 // any changes to disk. This is only useful during testing to speed up 348 // any changes to disk. This is only useful during testing to speed up
350 // testing. 349 // testing.
351 void ClearStore(); 350 void ClearStore();
352 351
353 // Sets/returns whether or not bookmark IDs are persisted or not.
354 bool PersistIDs() const { return persist_ids_; }
355 void SetPersistIDs(bool value);
356
357 // Returns whether the bookmarks file changed externally. 352 // Returns whether the bookmarks file changed externally.
358 bool file_changed() const { return file_changed_; } 353 bool file_changed() const { return file_changed_; }
359 354
360 private: 355 private:
361 // Used to order BookmarkNodes by URL. 356 // Used to order BookmarkNodes by URL.
362 class NodeURLComparator { 357 class NodeURLComparator {
363 public: 358 public:
364 bool operator()(const BookmarkNode* n1, const BookmarkNode* n2) const { 359 bool operator()(const BookmarkNode* n1, const BookmarkNode* n2) const {
365 return n1->GetURL() < n2->GetURL(); 360 return n1->GetURL() < n2->GetURL();
366 } 361 }
(...skipping 25 matching lines...) Expand all
392 387
393 // Adds the node at the specified position and sends notification. If 388 // Adds the node at the specified position and sends notification. If
394 // was_bookmarked is true, it indicates a bookmark already existed for the 389 // was_bookmarked is true, it indicates a bookmark already existed for the
395 // URL. 390 // URL.
396 BookmarkNode* AddNode(BookmarkNode* parent, 391 BookmarkNode* AddNode(BookmarkNode* parent,
397 int index, 392 int index,
398 BookmarkNode* node, 393 BookmarkNode* node,
399 bool was_bookmarked); 394 bool was_bookmarked);
400 395
401 // Implementation of GetNodeByID. 396 // Implementation of GetNodeByID.
402 const BookmarkNode* GetNodeByID(const BookmarkNode* node, int id); 397 const BookmarkNode* GetNodeByID(const BookmarkNode* node, int64 id);
403 398
404 // Returns true if the parent and index are valid. 399 // Returns true if the parent and index are valid.
405 bool IsValidIndex(const BookmarkNode* parent, int index, bool allow_end); 400 bool IsValidIndex(const BookmarkNode* parent, int index, bool allow_end);
406 401
407 // Sets the date modified time of the specified node. 402 // Sets the date modified time of the specified node.
408 void SetDateGroupModified(const BookmarkNode* parent, const base::Time time); 403 void SetDateGroupModified(const BookmarkNode* parent, const base::Time time);
409 404
410 // Creates the bookmark bar/other nodes. These call into 405 // Creates the bookmark bar/other nodes. These call into
411 // CreateRootNodeFromStarredEntry. 406 // CreateRootNodeFromStarredEntry.
412 BookmarkNode* CreateBookmarkNode(); 407 BookmarkNode* CreateBookmarkNode();
(...skipping 19 matching lines...) Expand all
432 427
433 // If we're waiting on a favicon for node, the load request is canceled. 428 // If we're waiting on a favicon for node, the load request is canceled.
434 void CancelPendingFavIconLoadRequests(BookmarkNode* node); 429 void CancelPendingFavIconLoadRequests(BookmarkNode* node);
435 430
436 // NotificationObserver. 431 // NotificationObserver.
437 virtual void Observe(NotificationType type, 432 virtual void Observe(NotificationType type,
438 const NotificationSource& source, 433 const NotificationSource& source,
439 const NotificationDetails& details); 434 const NotificationDetails& details);
440 435
441 // Generates and returns the next node ID. 436 // Generates and returns the next node ID.
442 int generate_next_node_id(); 437 int64 generate_next_node_id();
443 438
444 // Sets the maximum node ID to the given value. 439 // Sets the maximum node ID to the given value.
445 // This is used by BookmarkCodec to report the maximum ID after it's done 440 // This is used by BookmarkCodec to report the maximum ID after it's done
446 // decoding since during decoding codec can assign IDs to nodes if IDs are 441 // decoding since during decoding codec assigns node IDs.
447 // persisted. 442 void set_next_node_id(int64 id) { next_node_id_ = id; }
448 void set_next_node_id(int id) { next_node_id_ = id; }
449 443
450 // Records that the bookmarks file was changed externally. 444 // Records that the bookmarks file was changed externally.
451 void SetFileChanged(); 445 void SetFileChanged();
452 446
453 // Creates and returns a new LoadDetails. It's up to the caller to delete 447 // Creates and returns a new LoadDetails. It's up to the caller to delete
454 // the returned object. 448 // the returned object.
455 BookmarkStorage::LoadDetails* CreateLoadDetails(); 449 BookmarkStorage::LoadDetails* CreateLoadDetails();
456 450
457 // Registers bookmarks related prefs.
458 void RegisterPreferences();
459 // Loads bookmark related preferences.
460 void LoadPreferences();
461
462 NotificationRegistrar registrar_; 451 NotificationRegistrar registrar_;
463 452
464 Profile* profile_; 453 Profile* profile_;
465 454
466 // Whether the initial set of data has been loaded. 455 // Whether the initial set of data has been loaded.
467 bool loaded_; 456 bool loaded_;
468 457
469 // Whether to persist bookmark IDs.
470 bool persist_ids_;
471
472 // Whether the bookmarks file was changed externally. This is set after 458 // Whether the bookmarks file was changed externally. This is set after
473 // loading is complete and once set the value never changes. 459 // loading is complete and once set the value never changes.
474 bool file_changed_; 460 bool file_changed_;
475 461
476 // The root node. This contains the bookmark bar node and the 'other' node as 462 // The root node. This contains the bookmark bar node and the 'other' node as
477 // children. 463 // children.
478 BookmarkNode root_; 464 BookmarkNode root_;
479 465
480 BookmarkNode* bookmark_bar_node_; 466 BookmarkNode* bookmark_bar_node_;
481 BookmarkNode* other_node_; 467 BookmarkNode* other_node_;
482 468
483 // The maximum ID assigned to the bookmark nodes in the model. 469 // The maximum ID assigned to the bookmark nodes in the model.
484 int next_node_id_; 470 int64 next_node_id_;
485 471
486 // The observers. 472 // The observers.
487 ObserverList<BookmarkModelObserver> observers_; 473 ObserverList<BookmarkModelObserver> observers_;
488 474
489 // Set of nodes ordered by URL. This is not a map to avoid copying the 475 // Set of nodes ordered by URL. This is not a map to avoid copying the
490 // urls. 476 // urls.
491 // WARNING: nodes_ordered_by_url_set_ is accessed on multiple threads. As 477 // WARNING: nodes_ordered_by_url_set_ is accessed on multiple threads. As
492 // such, be sure and wrap all usage of it around url_lock_. 478 // such, be sure and wrap all usage of it around url_lock_.
493 typedef std::multiset<BookmarkNode*, NodeURLComparator> NodesOrderedByURLSet; 479 typedef std::multiset<BookmarkNode*, NodeURLComparator> NodesOrderedByURLSet;
494 NodesOrderedByURLSet nodes_ordered_by_url_set_; 480 NodesOrderedByURLSet nodes_ordered_by_url_set_;
495 Lock url_lock_; 481 Lock url_lock_;
496 482
497 // Used for loading favicons and the empty history request. 483 // Used for loading favicons and the empty history request.
498 CancelableRequestConsumerTSimple<BookmarkNode*> load_consumer_; 484 CancelableRequestConsumerTSimple<BookmarkNode*> load_consumer_;
499 485
500 // Reads/writes bookmarks to disk. 486 // Reads/writes bookmarks to disk.
501 scoped_refptr<BookmarkStorage> store_; 487 scoped_refptr<BookmarkStorage> store_;
502 488
503 scoped_ptr<BookmarkIndex> index_; 489 scoped_ptr<BookmarkIndex> index_;
504 490
505 base::WaitableEvent loaded_signal_; 491 base::WaitableEvent loaded_signal_;
506 492
507 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); 493 DISALLOW_COPY_AND_ASSIGN(BookmarkModel);
508 }; 494 };
509 495
510 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_ 496 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_drag_data.cc ('k') | chrome/browser/bookmarks/bookmark_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698