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

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

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