| OLD | NEW |
| 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 Loading... |
| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 // Returns the root node. The bookmark bar node and other node are children of | 187 // Returns the root node. The bookmark bar node and other node are children of |
| 187 // the root node. | 188 // the root node. |
| 188 const BookmarkNode* root_node() { return &root_; } | 189 const BookmarkNode* root_node() { return &root_; } |
| 189 | 190 |
| 190 // Returns the bookmark bar node. This is NULL until loaded. | 191 // Returns the bookmark bar node. This is NULL until loaded. |
| 191 const BookmarkNode* GetBookmarkBarNode() { return bookmark_bar_node_; } | 192 const BookmarkNode* GetBookmarkBarNode() { return bookmark_bar_node_; } |
| 192 | 193 |
| 193 // Returns the 'other' node. This is NULL until loaded. | 194 // Returns the 'other' node. This is NULL until loaded. |
| 194 const BookmarkNode* other_node() { return other_node_; } | 195 const BookmarkNode* other_node() { return other_node_; } |
| 195 | 196 |
| 197 // Returns the 'synced' node. This is NULL until loaded. |
| 198 const BookmarkNode* synced_node() { return synced_node_; } |
| 199 |
| 196 // Returns the parent the last node was added to. This never returns NULL | 200 // Returns the parent the last node was added to. This never returns NULL |
| 197 // (as long as the model is loaded). | 201 // (as long as the model is loaded). |
| 198 const BookmarkNode* GetParentForNewNodes(); | 202 const BookmarkNode* GetParentForNewNodes(); |
| 199 | 203 |
| 200 void AddObserver(BookmarkModelObserver* observer) { | 204 void AddObserver(BookmarkModelObserver* observer) { |
| 201 observers_.AddObserver(observer); | 205 observers_.AddObserver(observer); |
| 202 } | 206 } |
| 203 | 207 |
| 204 void RemoveObserver(BookmarkModelObserver* observer) { | 208 void RemoveObserver(BookmarkModelObserver* observer) { |
| 205 observers_.RemoveObserver(observer); | 209 observers_.RemoveObserver(observer); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 const string16& text, | 308 const string16& text, |
| 305 size_t max_count, | 309 size_t max_count, |
| 306 std::vector<bookmark_utils::TitleMatch>* matches); | 310 std::vector<bookmark_utils::TitleMatch>* matches); |
| 307 | 311 |
| 308 Profile* profile() const { return profile_; } | 312 Profile* profile() const { return profile_; } |
| 309 | 313 |
| 310 bool is_root(const BookmarkNode* node) const { return node == &root_; } | 314 bool is_root(const BookmarkNode* node) const { return node == &root_; } |
| 311 bool is_bookmark_bar_node(const BookmarkNode* node) const { | 315 bool is_bookmark_bar_node(const BookmarkNode* node) const { |
| 312 return node == bookmark_bar_node_; | 316 return node == bookmark_bar_node_; |
| 313 } | 317 } |
| 318 bool is_synced_bookmarks_node(const BookmarkNode* node) const { |
| 319 return node == synced_node_; |
| 320 } |
| 314 bool is_other_bookmarks_node(const BookmarkNode* node) const { | 321 bool is_other_bookmarks_node(const BookmarkNode* node) const { |
| 315 return node == other_node_; | 322 return node == other_node_; |
| 316 } | 323 } |
| 317 // Returns whether the given node is one of the permanent nodes - root node, | 324 // Returns whether the given node is one of the permanent nodes - root node, |
| 318 // bookmark bar node or other bookmarks node. | 325 // bookmark bar node or other bookmarks node. |
| 319 bool is_permanent_node(const BookmarkNode* node) const { | 326 bool is_permanent_node(const BookmarkNode* node) const { |
| 320 return is_root(node) || | 327 return is_root(node) || |
| 321 is_bookmark_bar_node(node) || | 328 is_bookmark_bar_node(node) || |
| 322 is_other_bookmarks_node(node); | 329 is_other_bookmarks_node(node) || |
| 330 is_synced_bookmarks_node(node); |
| 323 } | 331 } |
| 324 | 332 |
| 325 // Sets the store to NULL, making it so the BookmarkModel does not persist | 333 // 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 | 334 // any changes to disk. This is only useful during testing to speed up |
| 327 // testing. | 335 // testing. |
| 328 void ClearStore(); | 336 void ClearStore(); |
| 329 | 337 |
| 330 // Returns whether the bookmarks file changed externally. | 338 // Returns whether the bookmarks file changed externally. |
| 331 bool file_changed() const { return file_changed_; } | 339 bool file_changed() const { return file_changed_; } |
| 332 | 340 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 int index, | 381 int index, |
| 374 BookmarkNode* node, | 382 BookmarkNode* node, |
| 375 bool was_bookmarked); | 383 bool was_bookmarked); |
| 376 | 384 |
| 377 // Implementation of GetNodeByID. | 385 // Implementation of GetNodeByID. |
| 378 const BookmarkNode* GetNodeByID(const BookmarkNode* node, int64 id); | 386 const BookmarkNode* GetNodeByID(const BookmarkNode* node, int64 id); |
| 379 | 387 |
| 380 // Returns true if the parent and index are valid. | 388 // Returns true if the parent and index are valid. |
| 381 bool IsValidIndex(const BookmarkNode* parent, int index, bool allow_end); | 389 bool IsValidIndex(const BookmarkNode* parent, int index, bool allow_end); |
| 382 | 390 |
| 383 // Creates the bookmark bar/other nodes. These call into | 391 // Creates the bookmark bar/synced/other nodes. These call into |
| 384 // CreateRootNodeFromStarredEntry. | 392 // CreateRootNodeFromStarredEntry. |
| 385 BookmarkNode* CreateBookmarkNode(); | 393 BookmarkNode* CreateBookmarkNode(); |
| 386 BookmarkNode* CreateOtherBookmarksNode(); | 394 BookmarkNode* CreateOtherBookmarksNode(); |
| 395 BookmarkNode* CreateSyncedBookmarksNode(); |
| 387 | 396 |
| 388 // Creates a root node (either the bookmark bar node or other node) from the | 397 // Creates a root node (either the bookmark bar node or other node) from the |
| 389 // specified starred entry. | 398 // specified starred entry. |
| 390 BookmarkNode* CreateRootNodeFromStarredEntry( | 399 BookmarkNode* CreateRootNodeFromStarredEntry( |
| 391 const history::StarredEntry& entry); | 400 const history::StarredEntry& entry); |
| 392 | 401 |
| 393 // Notification that a favicon has finished loading. If we can decode the | 402 // Notification that a favicon has finished loading. If we can decode the |
| 394 // favicon, FaviconLoaded is invoked. | 403 // favicon, FaviconLoaded is invoked. |
| 395 void OnFaviconDataAvailable(FaviconService::Handle handle, | 404 void OnFaviconDataAvailable(FaviconService::Handle handle, |
| 396 history::FaviconData favicon); | 405 history::FaviconData favicon); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 // Whether the bookmarks file was changed externally. This is set after | 441 // Whether the bookmarks file was changed externally. This is set after |
| 433 // loading is complete and once set the value never changes. | 442 // loading is complete and once set the value never changes. |
| 434 bool file_changed_; | 443 bool file_changed_; |
| 435 | 444 |
| 436 // The root node. This contains the bookmark bar node and the 'other' node as | 445 // The root node. This contains the bookmark bar node and the 'other' node as |
| 437 // children. | 446 // children. |
| 438 BookmarkNode root_; | 447 BookmarkNode root_; |
| 439 | 448 |
| 440 BookmarkNode* bookmark_bar_node_; | 449 BookmarkNode* bookmark_bar_node_; |
| 441 BookmarkNode* other_node_; | 450 BookmarkNode* other_node_; |
| 451 BookmarkNode* synced_node_; |
| 442 | 452 |
| 443 // The maximum ID assigned to the bookmark nodes in the model. | 453 // The maximum ID assigned to the bookmark nodes in the model. |
| 444 int64 next_node_id_; | 454 int64 next_node_id_; |
| 445 | 455 |
| 446 // The observers. | 456 // The observers. |
| 447 ObserverList<BookmarkModelObserver> observers_; | 457 ObserverList<BookmarkModelObserver> observers_; |
| 448 | 458 |
| 449 // Set of nodes ordered by URL. This is not a map to avoid copying the | 459 // Set of nodes ordered by URL. This is not a map to avoid copying the |
| 450 // urls. | 460 // urls. |
| 451 // WARNING: nodes_ordered_by_url_set_ is accessed on multiple threads. As | 461 // 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_. | 462 // such, be sure and wrap all usage of it around url_lock_. |
| 453 typedef std::multiset<BookmarkNode*, NodeURLComparator> NodesOrderedByURLSet; | 463 typedef std::multiset<BookmarkNode*, NodeURLComparator> NodesOrderedByURLSet; |
| 454 NodesOrderedByURLSet nodes_ordered_by_url_set_; | 464 NodesOrderedByURLSet nodes_ordered_by_url_set_; |
| 455 base::Lock url_lock_; | 465 base::Lock url_lock_; |
| 456 | 466 |
| 457 // Used for loading favicons and the empty history request. | 467 // Used for loading favicons and the empty history request. |
| 458 CancelableRequestConsumerTSimple<BookmarkNode*> load_consumer_; | 468 CancelableRequestConsumerTSimple<BookmarkNode*> load_consumer_; |
| 459 | 469 |
| 460 // Reads/writes bookmarks to disk. | 470 // Reads/writes bookmarks to disk. |
| 461 scoped_refptr<BookmarkStorage> store_; | 471 scoped_refptr<BookmarkStorage> store_; |
| 462 | 472 |
| 463 scoped_ptr<BookmarkIndex> index_; | 473 scoped_ptr<BookmarkIndex> index_; |
| 464 | 474 |
| 465 base::WaitableEvent loaded_signal_; | 475 base::WaitableEvent loaded_signal_; |
| 466 | 476 |
| 467 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); | 477 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); |
| 468 }; | 478 }; |
| 469 | 479 |
| 470 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_ | 480 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_H_ |
| OLD | NEW |