| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ | 5 #ifndef COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ |
| 6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ | 6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 19 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
| 20 #include "base/synchronization/waitable_event.h" | 20 #include "base/synchronization/waitable_event.h" |
| 21 #include "components/bookmarks/browser/bookmark_client.h" | 21 #include "components/bookmarks/browser/bookmark_client.h" |
| 22 #include "components/bookmarks/browser/bookmark_node.h" | 22 #include "components/bookmarks/browser/bookmark_node.h" |
| 23 #include "components/bookmarks/browser/bookmark_undo_provider.h" |
| 23 #include "components/keyed_service/core/keyed_service.h" | 24 #include "components/keyed_service/core/keyed_service.h" |
| 24 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
| 25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 26 | 27 |
| 27 class PrefService; | 28 class PrefService; |
| 28 | 29 |
| 29 namespace base { | 30 namespace base { |
| 30 class FilePath; | 31 class FilePath; |
| 31 class SequencedTaskRunner; | 32 class SequencedTaskRunner; |
| 32 } | 33 } |
| 33 | 34 |
| 34 namespace favicon_base { | 35 namespace favicon_base { |
| 35 struct FaviconImageResult; | 36 struct FaviconImageResult; |
| 36 } | 37 } |
| 37 | 38 |
| 38 namespace query_parser { | 39 namespace query_parser { |
| 39 enum class MatchingAlgorithm; | 40 enum class MatchingAlgorithm; |
| 40 } | 41 } |
| 41 | 42 |
| 42 namespace bookmarks { | 43 namespace bookmarks { |
| 43 | 44 |
| 44 class BookmarkCodecTest; | 45 class BookmarkCodecTest; |
| 45 class BookmarkExpandedStateTracker; | 46 class BookmarkExpandedStateTracker; |
| 46 class BookmarkIndex; | 47 class BookmarkIndex; |
| 47 class BookmarkLoadDetails; | 48 class BookmarkLoadDetails; |
| 48 class BookmarkModelObserver; | 49 class BookmarkModelObserver; |
| 49 class BookmarkStorage; | 50 class BookmarkStorage; |
| 51 class BookmarkUndoDelegate; |
| 50 class ScopedGroupBookmarkActions; | 52 class ScopedGroupBookmarkActions; |
| 51 class TestBookmarkClient; | 53 class TestBookmarkClient; |
| 52 struct BookmarkMatch; | 54 struct BookmarkMatch; |
| 53 | 55 |
| 54 // BookmarkModel -------------------------------------------------------------- | 56 // BookmarkModel -------------------------------------------------------------- |
| 55 | 57 |
| 56 // BookmarkModel provides a directed acyclic graph of URLs and folders. | 58 // BookmarkModel provides a directed acyclic graph of URLs and folders. |
| 57 // Three graphs are provided for the three entry points: those on the 'bookmarks | 59 // Three graphs are provided for the three entry points: those on the 'bookmarks |
| 58 // bar', those in the 'other bookmarks' folder and those in the 'mobile' folder. | 60 // bar', those in the 'other bookmarks' folder and those in the 'mobile' folder. |
| 59 // | 61 // |
| 60 // An observer may be attached to observe relevant events. | 62 // An observer may be attached to observe relevant events. |
| 61 // | 63 // |
| 62 // You should NOT directly create a BookmarkModel, instead go through the | 64 // You should NOT directly create a BookmarkModel, instead go through the |
| 63 // BookmarkModelFactory. | 65 // BookmarkModelFactory. |
| 64 class BookmarkModel : public KeyedService { | 66 class BookmarkModel : public BookmarkUndoProvider, |
| 67 public KeyedService { |
| 65 public: | 68 public: |
| 66 struct URLAndTitle { | 69 struct URLAndTitle { |
| 67 GURL url; | 70 GURL url; |
| 68 base::string16 title; | 71 base::string16 title; |
| 69 }; | 72 }; |
| 70 | 73 |
| 71 explicit BookmarkModel(BookmarkClient* client); | 74 explicit BookmarkModel(BookmarkClient* client); |
| 72 ~BookmarkModel() override; | 75 ~BookmarkModel() override; |
| 73 | 76 |
| 74 // KeyedService: | 77 // KeyedService: |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 // http://www.google.com) and the given icon URL (e.g. | 304 // http://www.google.com) and the given icon URL (e.g. |
| 302 // http://www.google.com/favicon.ico) have changed. It is valid to call | 305 // http://www.google.com/favicon.ico) have changed. It is valid to call |
| 303 // OnFaviconsChanged() with non-empty |page_urls| and an empty |icon_url| and | 306 // OnFaviconsChanged() with non-empty |page_urls| and an empty |icon_url| and |
| 304 // vice versa. | 307 // vice versa. |
| 305 void OnFaviconsChanged(const std::set<GURL>& page_urls, | 308 void OnFaviconsChanged(const std::set<GURL>& page_urls, |
| 306 const GURL& icon_url); | 309 const GURL& icon_url); |
| 307 | 310 |
| 308 // Returns the client used by this BookmarkModel. | 311 // Returns the client used by this BookmarkModel. |
| 309 BookmarkClient* client() const { return client_; } | 312 BookmarkClient* client() const { return client_; } |
| 310 | 313 |
| 314 void SetUndoDelegate(BookmarkUndoDelegate* undo_delegate); |
| 315 |
| 311 private: | 316 private: |
| 312 friend class BookmarkCodecTest; | 317 friend class BookmarkCodecTest; |
| 313 friend class BookmarkModelFaviconTest; | 318 friend class BookmarkModelFaviconTest; |
| 314 friend class BookmarkStorage; | 319 friend class BookmarkStorage; |
| 315 friend class ScopedGroupBookmarkActions; | 320 friend class ScopedGroupBookmarkActions; |
| 316 friend class TestBookmarkClient; | 321 friend class TestBookmarkClient; |
| 317 | 322 |
| 318 // Used to order BookmarkNodes by URL. | 323 // Used to order BookmarkNodes by URL. |
| 319 class NodeURLComparator { | 324 class NodeURLComparator { |
| 320 public: | 325 public: |
| 321 bool operator()(const BookmarkNode* n1, const BookmarkNode* n2) const { | 326 bool operator()(const BookmarkNode* n1, const BookmarkNode* n2) const { |
| 322 return n1->url() < n2->url(); | 327 return n1->url() < n2->url(); |
| 323 } | 328 } |
| 324 }; | 329 }; |
| 325 | 330 |
| 331 // BookmarkUndoProvider: |
| 332 void RestoreRemovedNode(const BookmarkNode* parent, |
| 333 int index, |
| 334 scoped_ptr<BookmarkNode> node) override; |
| 335 |
| 336 // Notifies the observers for adding every descedent of |node|. |
| 337 void NotifyNodeAddedForAllDescendents(const BookmarkNode* node); |
| 338 |
| 326 // Implementation of IsBookmarked. Before calling this the caller must obtain | 339 // Implementation of IsBookmarked. Before calling this the caller must obtain |
| 327 // a lock on |url_lock_|. | 340 // a lock on |url_lock_|. |
| 328 bool IsBookmarkedNoLock(const GURL& url); | 341 bool IsBookmarkedNoLock(const GURL& url); |
| 329 | 342 |
| 330 // Removes the node from internal maps and recurses through all children. If | 343 // Removes the node from internal maps and recurses through all children. If |
| 331 // the node is a url, its url is added to removed_urls. | 344 // the node is a url, its url is added to removed_urls. |
| 332 // | 345 // |
| 333 // This does NOT delete the node. | 346 // This does NOT delete the node. |
| 334 void RemoveNode(BookmarkNode* node, std::set<GURL>* removed_urls); | 347 void RemoveNode(BookmarkNode* node, std::set<GURL>* removed_urls); |
| 335 | 348 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 // Sets the maximum node ID to the given value. | 411 // Sets the maximum node ID to the given value. |
| 399 // This is used by BookmarkCodec to report the maximum ID after it's done | 412 // This is used by BookmarkCodec to report the maximum ID after it's done |
| 400 // decoding since during decoding codec assigns node IDs. | 413 // decoding since during decoding codec assigns node IDs. |
| 401 void set_next_node_id(int64_t id) { next_node_id_ = id; } | 414 void set_next_node_id(int64_t id) { next_node_id_ = id; } |
| 402 | 415 |
| 403 // Creates and returns a new BookmarkLoadDetails. It's up to the caller to | 416 // Creates and returns a new BookmarkLoadDetails. It's up to the caller to |
| 404 // delete the returned object. | 417 // delete the returned object. |
| 405 scoped_ptr<BookmarkLoadDetails> CreateLoadDetails( | 418 scoped_ptr<BookmarkLoadDetails> CreateLoadDetails( |
| 406 const std::string& accept_languages); | 419 const std::string& accept_languages); |
| 407 | 420 |
| 421 BookmarkUndoDelegate* undo_delegate() const; |
| 422 |
| 408 BookmarkClient* const client_; | 423 BookmarkClient* const client_; |
| 409 | 424 |
| 410 // Whether the initial set of data has been loaded. | 425 // Whether the initial set of data has been loaded. |
| 411 bool loaded_; | 426 bool loaded_; |
| 412 | 427 |
| 413 // The root node. This contains the bookmark bar node, the 'other' node and | 428 // The root node. This contains the bookmark bar node, the 'other' node and |
| 414 // the mobile node as children. | 429 // the mobile node as children. |
| 415 BookmarkNode root_; | 430 BookmarkNode root_; |
| 416 | 431 |
| 417 BookmarkPermanentNode* bookmark_bar_node_; | 432 BookmarkPermanentNode* bookmark_bar_node_; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 442 | 457 |
| 443 base::WaitableEvent loaded_signal_; | 458 base::WaitableEvent loaded_signal_; |
| 444 | 459 |
| 445 // See description of IsDoingExtensiveChanges above. | 460 // See description of IsDoingExtensiveChanges above. |
| 446 int extensive_changes_; | 461 int extensive_changes_; |
| 447 | 462 |
| 448 scoped_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_; | 463 scoped_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_; |
| 449 | 464 |
| 450 std::set<std::string> non_cloned_keys_; | 465 std::set<std::string> non_cloned_keys_; |
| 451 | 466 |
| 467 BookmarkUndoDelegate* undo_delegate_; |
| 468 scoped_ptr<BookmarkUndoDelegate> empty_undo_delegate_; |
| 469 |
| 452 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); | 470 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); |
| 453 }; | 471 }; |
| 454 | 472 |
| 455 } // namespace bookmarks | 473 } // namespace bookmarks |
| 456 | 474 |
| 457 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ | 475 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ |
| OLD | NEW |