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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 |
10 #include <map> | 11 #include <map> |
| 12 #include <memory> |
11 #include <set> | 13 #include <set> |
12 #include <vector> | 14 #include <vector> |
13 | 15 |
14 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
15 #include "base/macros.h" | 17 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | |
18 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
19 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
20 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
21 #include "base/synchronization/waitable_event.h" | 22 #include "base/synchronization/waitable_event.h" |
22 #include "components/bookmarks/browser/bookmark_client.h" | 23 #include "components/bookmarks/browser/bookmark_client.h" |
23 #include "components/bookmarks/browser/bookmark_node.h" | 24 #include "components/bookmarks/browser/bookmark_node.h" |
24 #include "components/bookmarks/browser/bookmark_undo_provider.h" | 25 #include "components/bookmarks/browser/bookmark_undo_provider.h" |
25 #include "components/keyed_service/core/keyed_service.h" | 26 #include "components/keyed_service/core/keyed_service.h" |
26 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
27 #include "url/gurl.h" | 28 #include "url/gurl.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // You should NOT directly create a BookmarkModel, instead go through the | 66 // You should NOT directly create a BookmarkModel, instead go through the |
66 // BookmarkModelFactory. | 67 // BookmarkModelFactory. |
67 class BookmarkModel : public BookmarkUndoProvider, | 68 class BookmarkModel : public BookmarkUndoProvider, |
68 public KeyedService { | 69 public KeyedService { |
69 public: | 70 public: |
70 struct URLAndTitle { | 71 struct URLAndTitle { |
71 GURL url; | 72 GURL url; |
72 base::string16 title; | 73 base::string16 title; |
73 }; | 74 }; |
74 | 75 |
75 explicit BookmarkModel(scoped_ptr<BookmarkClient> client); | 76 explicit BookmarkModel(std::unique_ptr<BookmarkClient> client); |
76 ~BookmarkModel() override; | 77 ~BookmarkModel() override; |
77 | 78 |
78 // KeyedService: | 79 // KeyedService: |
79 void Shutdown() override; | 80 void Shutdown() override; |
80 | 81 |
81 // Loads the bookmarks. This is called upon creation of the | 82 // Loads the bookmarks. This is called upon creation of the |
82 // BookmarkModel. You need not invoke this directly. | 83 // BookmarkModel. You need not invoke this directly. |
83 // All load operations will be executed on |io_task_runner| and the completion | 84 // All load operations will be executed on |io_task_runner| and the completion |
84 // callback will be called from |ui_task_runner|. | 85 // callback will be called from |ui_task_runner|. |
85 void Load(PrefService* pref_service, | 86 void Load(PrefService* pref_service, |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 class NodeURLComparator { | 325 class NodeURLComparator { |
325 public: | 326 public: |
326 bool operator()(const BookmarkNode* n1, const BookmarkNode* n2) const { | 327 bool operator()(const BookmarkNode* n1, const BookmarkNode* n2) const { |
327 return n1->url() < n2->url(); | 328 return n1->url() < n2->url(); |
328 } | 329 } |
329 }; | 330 }; |
330 | 331 |
331 // BookmarkUndoProvider: | 332 // BookmarkUndoProvider: |
332 void RestoreRemovedNode(const BookmarkNode* parent, | 333 void RestoreRemovedNode(const BookmarkNode* parent, |
333 int index, | 334 int index, |
334 scoped_ptr<BookmarkNode> node) override; | 335 std::unique_ptr<BookmarkNode> node) override; |
335 | 336 |
336 // Notifies the observers for adding every descedent of |node|. | 337 // Notifies the observers for adding every descedent of |node|. |
337 void NotifyNodeAddedForAllDescendents(const BookmarkNode* node); | 338 void NotifyNodeAddedForAllDescendents(const BookmarkNode* node); |
338 | 339 |
339 // Implementation of IsBookmarked. Before calling this the caller must obtain | 340 // Implementation of IsBookmarked. Before calling this the caller must obtain |
340 // a lock on |url_lock_|. | 341 // a lock on |url_lock_|. |
341 bool IsBookmarkedNoLock(const GURL& url); | 342 bool IsBookmarkedNoLock(const GURL& url); |
342 | 343 |
343 // Removes the node from internal maps and recurses through all children. If | 344 // Removes the node from internal maps and recurses through all children. If |
344 // the node is a url, its url is added to removed_urls. | 345 // the node is a url, its url is added to removed_urls. |
345 // | 346 // |
346 // This does NOT delete the node. | 347 // This does NOT delete the node. |
347 void RemoveNode(BookmarkNode* node, std::set<GURL>* removed_urls); | 348 void RemoveNode(BookmarkNode* node, std::set<GURL>* removed_urls); |
348 | 349 |
349 // Invoked when loading is finished. Sets |loaded_| and notifies observers. | 350 // Invoked when loading is finished. Sets |loaded_| and notifies observers. |
350 // BookmarkModel takes ownership of |details|. | 351 // BookmarkModel takes ownership of |details|. |
351 void DoneLoading(scoped_ptr<BookmarkLoadDetails> details); | 352 void DoneLoading(std::unique_ptr<BookmarkLoadDetails> details); |
352 | 353 |
353 // Populates |nodes_ordered_by_url_set_| from root. | 354 // Populates |nodes_ordered_by_url_set_| from root. |
354 void PopulateNodesByURL(BookmarkNode* node); | 355 void PopulateNodesByURL(BookmarkNode* node); |
355 | 356 |
356 // Removes the node from its parent, but does not delete it. No notifications | 357 // Removes the node from its parent, but does not delete it. No notifications |
357 // are sent. |removed_urls| is populated with the urls which no longer have | 358 // are sent. |removed_urls| is populated with the urls which no longer have |
358 // any bookmarks associated with them. | 359 // any bookmarks associated with them. |
359 // This method should be called after acquiring |url_lock_|. | 360 // This method should be called after acquiring |url_lock_|. |
360 void RemoveNodeAndGetRemovedUrls(BookmarkNode* node, | 361 void RemoveNodeAndGetRemovedUrls(BookmarkNode* node, |
361 std::set<GURL>* removed_urls); | 362 std::set<GURL>* removed_urls); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 // Generates and returns the next node ID. | 409 // Generates and returns the next node ID. |
409 int64_t generate_next_node_id(); | 410 int64_t generate_next_node_id(); |
410 | 411 |
411 // Sets the maximum node ID to the given value. | 412 // Sets the maximum node ID to the given value. |
412 // This is used by BookmarkCodec to report the maximum ID after it's done | 413 // This is used by BookmarkCodec to report the maximum ID after it's done |
413 // decoding since during decoding codec assigns node IDs. | 414 // decoding since during decoding codec assigns node IDs. |
414 void set_next_node_id(int64_t id) { next_node_id_ = id; } | 415 void set_next_node_id(int64_t id) { next_node_id_ = id; } |
415 | 416 |
416 // Creates and returns a new BookmarkLoadDetails. It's up to the caller to | 417 // Creates and returns a new BookmarkLoadDetails. It's up to the caller to |
417 // delete the returned object. | 418 // delete the returned object. |
418 scoped_ptr<BookmarkLoadDetails> CreateLoadDetails(); | 419 std::unique_ptr<BookmarkLoadDetails> CreateLoadDetails(); |
419 | 420 |
420 BookmarkUndoDelegate* undo_delegate() const; | 421 BookmarkUndoDelegate* undo_delegate() const; |
421 | 422 |
422 scoped_ptr<BookmarkClient> client_; | 423 std::unique_ptr<BookmarkClient> client_; |
423 | 424 |
424 // Whether the initial set of data has been loaded. | 425 // Whether the initial set of data has been loaded. |
425 bool loaded_; | 426 bool loaded_; |
426 | 427 |
427 // 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 |
428 // the mobile node as children. | 429 // the mobile node as children. |
429 BookmarkNode root_; | 430 BookmarkNode root_; |
430 | 431 |
431 BookmarkPermanentNode* bookmark_bar_node_; | 432 BookmarkPermanentNode* bookmark_bar_node_; |
432 BookmarkPermanentNode* other_node_; | 433 BookmarkPermanentNode* other_node_; |
(...skipping 10 matching lines...) Expand all Loading... |
443 // WARNING: |nodes_ordered_by_url_set_| is accessed on multiple threads. As | 444 // WARNING: |nodes_ordered_by_url_set_| is accessed on multiple threads. As |
444 // such, be sure and wrap all usage of it around |url_lock_|. | 445 // such, be sure and wrap all usage of it around |url_lock_|. |
445 typedef std::multiset<BookmarkNode*, NodeURLComparator> NodesOrderedByURLSet; | 446 typedef std::multiset<BookmarkNode*, NodeURLComparator> NodesOrderedByURLSet; |
446 NodesOrderedByURLSet nodes_ordered_by_url_set_; | 447 NodesOrderedByURLSet nodes_ordered_by_url_set_; |
447 base::Lock url_lock_; | 448 base::Lock url_lock_; |
448 | 449 |
449 // Used for loading favicons. | 450 // Used for loading favicons. |
450 base::CancelableTaskTracker cancelable_task_tracker_; | 451 base::CancelableTaskTracker cancelable_task_tracker_; |
451 | 452 |
452 // Reads/writes bookmarks to disk. | 453 // Reads/writes bookmarks to disk. |
453 scoped_ptr<BookmarkStorage> store_; | 454 std::unique_ptr<BookmarkStorage> store_; |
454 | 455 |
455 scoped_ptr<BookmarkIndex> index_; | 456 std::unique_ptr<BookmarkIndex> index_; |
456 | 457 |
457 base::WaitableEvent loaded_signal_; | 458 base::WaitableEvent loaded_signal_; |
458 | 459 |
459 // See description of IsDoingExtensiveChanges above. | 460 // See description of IsDoingExtensiveChanges above. |
460 int extensive_changes_; | 461 int extensive_changes_; |
461 | 462 |
462 scoped_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_; | 463 std::unique_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_; |
463 | 464 |
464 std::set<std::string> non_cloned_keys_; | 465 std::set<std::string> non_cloned_keys_; |
465 | 466 |
466 BookmarkUndoDelegate* undo_delegate_; | 467 BookmarkUndoDelegate* undo_delegate_; |
467 scoped_ptr<BookmarkUndoDelegate> empty_undo_delegate_; | 468 std::unique_ptr<BookmarkUndoDelegate> empty_undo_delegate_; |
468 | 469 |
469 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); | 470 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); |
470 }; | 471 }; |
471 | 472 |
472 } // namespace bookmarks | 473 } // namespace bookmarks |
473 | 474 |
474 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ | 475 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ |
OLD | NEW |