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 <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
19 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
20 #include "components/bookmarks/browser/bookmark_client.h" | |
21 #include "components/bookmarks/browser/bookmark_node.h" | 20 #include "components/bookmarks/browser/bookmark_node.h" |
22 #include "components/keyed_service/core/keyed_service.h" | 21 #include "components/keyed_service/core/keyed_service.h" |
23 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
24 #include "url/gurl.h" | 23 #include "url/gurl.h" |
25 | 24 |
26 class PrefService; | 25 class PrefService; |
27 | 26 |
28 namespace base { | 27 namespace base { |
29 class FilePath; | 28 class FilePath; |
30 class SequencedTaskRunner; | 29 class SequencedTaskRunner; |
| 30 struct UserMetricsAction; |
31 } | 31 } |
32 | 32 |
33 namespace favicon_base { | 33 namespace favicon_base { |
34 struct FaviconImageResult; | 34 struct FaviconImageResult; |
35 } | 35 } |
36 | 36 |
37 namespace query_parser { | 37 namespace query_parser { |
38 enum class MatchingAlgorithm; | 38 enum class MatchingAlgorithm; |
39 } | 39 } |
40 | 40 |
41 namespace bookmarks { | 41 namespace bookmarks { |
42 | 42 |
| 43 class BookmarkClient; |
43 class BookmarkCodecTest; | 44 class BookmarkCodecTest; |
44 class BookmarkExpandedStateTracker; | 45 class BookmarkExpandedStateTracker; |
45 class BookmarkIndex; | 46 class BookmarkIndex; |
| 47 class BookmarkIndexTest; |
46 class BookmarkLoadDetails; | 48 class BookmarkLoadDetails; |
| 49 struct BookmarkMatch; |
47 class BookmarkModelObserver; | 50 class BookmarkModelObserver; |
48 class BookmarkStorage; | 51 class BookmarkStorage; |
49 class ScopedGroupBookmarkActions; | 52 class ScopedGroupBookmarkActions; |
50 class TestBookmarkClient; | 53 class TestBookmarkClient; |
51 struct BookmarkMatch; | |
52 | 54 |
53 // BookmarkModel -------------------------------------------------------------- | 55 // BookmarkModel -------------------------------------------------------------- |
54 | 56 |
55 // BookmarkModel provides a directed acyclic graph of URLs and folders. | 57 // BookmarkModel provides a directed acyclic graph of URLs and folders. |
56 // Three graphs are provided for the three entry points: those on the 'bookmarks | 58 // Three graphs are provided for the three entry points: those on the 'bookmarks |
57 // bar', those in the 'other bookmarks' folder and those in the 'mobile' folder. | 59 // bar', those in the 'other bookmarks' folder and those in the 'mobile' folder. |
58 // | 60 // |
59 // An observer may be attached to observe relevant events. | 61 // An observer may be attached to observe relevant events. |
60 // | 62 // |
61 // You should NOT directly create a BookmarkModel, instead go through the | 63 // You should NOT directly create a BookmarkModel, instead go through the |
62 // BookmarkModelFactory. | 64 // BookmarkModelFactory. |
63 class BookmarkModel : public KeyedService { | 65 class BookmarkModel : public KeyedService { |
64 public: | 66 public: |
65 struct URLAndTitle { | 67 struct URLAndTitle { |
66 GURL url; | 68 GURL url; |
67 base::string16 title; | 69 base::string16 title; |
68 }; | 70 }; |
69 | 71 |
70 explicit BookmarkModel(BookmarkClient* client); | 72 explicit BookmarkModel(scoped_ptr<BookmarkClient> bookmark_client); |
71 ~BookmarkModel() override; | 73 ~BookmarkModel() override; |
72 | 74 |
73 // KeyedService: | 75 // KeyedService: |
74 void Shutdown() override; | 76 void Shutdown() override; |
75 | 77 |
76 // Loads the bookmarks. This is called upon creation of the | 78 // Loads the bookmarks. This is called upon creation of the |
77 // BookmarkModel. You need not invoke this directly. | 79 // BookmarkModel. You need not invoke this directly. |
78 // All load operations will be executed on |io_task_runner| and the completion | 80 // All load operations will be executed on |io_task_runner| and the completion |
79 // callback will be called from |ui_task_runner|. | 81 // callback will be called from |ui_task_runner|. |
80 void Load(PrefService* pref_service, | 82 void Load(PrefService* pref_service, |
(...skipping 23 matching lines...) Expand all Loading... |
104 const BookmarkNode* managed_node() const { return managed_node_; } | 106 const BookmarkNode* managed_node() const { return managed_node_; } |
105 | 107 |
106 // The top-level supervised bookmarks folder, defined by the custodian of a | 108 // The top-level supervised bookmarks folder, defined by the custodian of a |
107 // supervised user. This is null until loaded. | 109 // supervised user. This is null until loaded. |
108 const BookmarkNode* supervised_node() const { return supervised_node_; } | 110 const BookmarkNode* supervised_node() const { return supervised_node_; } |
109 | 111 |
110 bool is_root_node(const BookmarkNode* node) const { return node == &root_; } | 112 bool is_root_node(const BookmarkNode* node) const { return node == &root_; } |
111 | 113 |
112 // Returns whether the given |node| is one of the permanent nodes - root node, | 114 // Returns whether the given |node| is one of the permanent nodes - root node, |
113 // 'bookmark bar' node, 'other' node or 'mobile' node, or one of the root | 115 // 'bookmark bar' node, 'other' node or 'mobile' node, or one of the root |
114 // nodes supplied by the |client_|. | 116 // nodes supplied by the |bookmark_client_|. |
115 bool is_permanent_node(const BookmarkNode* node) const { | 117 bool is_permanent_node(const BookmarkNode* node) const { |
116 return node && (node == &root_ || node->parent() == &root_); | 118 return node && (node == &root_ || node->parent() == &root_); |
117 } | 119 } |
118 | 120 |
119 // Returns the parent the last node was added to. This never returns NULL | 121 // Returns the parent the last node was added to. This never returns NULL |
120 // (as long as the model is loaded). | 122 // (as long as the model is loaded). |
121 const BookmarkNode* GetParentForNewNodes(); | 123 const BookmarkNode* GetParentForNewNodes(); |
122 | 124 |
123 void AddObserver(BookmarkModelObserver* observer); | 125 void AddObserver(BookmarkModelObserver* observer); |
124 void RemoveObserver(BookmarkModelObserver* observer); | 126 void RemoveObserver(BookmarkModelObserver* observer); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 | 315 |
314 // Returns true if this node can be edited by the user. | 316 // Returns true if this node can be edited by the user. |
315 // TODO(joaodasilva): the model should check this more aggressively, and | 317 // TODO(joaodasilva): the model should check this more aggressively, and |
316 // should give the client a means to temporarily disable those checks. | 318 // should give the client a means to temporarily disable those checks. |
317 // http://crbug.com/49598 | 319 // http://crbug.com/49598 |
318 bool CanBeEditedByUser(const BookmarkNode* node); | 320 bool CanBeEditedByUser(const BookmarkNode* node); |
319 | 321 |
320 // Returns true if the permanent node |node| should always be visible. | 322 // Returns true if the permanent node |node| should always be visible. |
321 bool IsPermanentNodeVisible(const BookmarkPermanentNode* node); | 323 bool IsPermanentNodeVisible(const BookmarkPermanentNode* node); |
322 | 324 |
323 // Forward the |action| to |client_| to record it. See | 325 // Forward the |action| to |bookmark_client_| to record it. See |
324 // BookmarkClient::RecordAction for more information. | 326 // BookmarkClient::RecordAction for more information. |
325 void RecordAction(const base::UserMetricsAction& action); | 327 void RecordAction(const base::UserMetricsAction& action); |
326 | 328 |
327 private: | 329 private: |
328 friend class BookmarkCodecTest; | 330 friend class BookmarkCodecTest; |
| 331 friend class BookmarkIndexTest; |
329 friend class BookmarkStorage; | 332 friend class BookmarkStorage; |
330 friend class ScopedGroupBookmarkActions; | 333 friend class ScopedGroupBookmarkActions; |
331 friend class TestBookmarkClient; | 334 friend class TestBookmarkClient; |
332 | 335 |
333 // Used to order BookmarkNodes by URL. | 336 // Used to order BookmarkNodes by URL. |
334 class NodeURLComparator { | 337 class NodeURLComparator { |
335 public: | 338 public: |
336 bool operator()(const BookmarkNode* n1, const BookmarkNode* n2) const { | 339 bool operator()(const BookmarkNode* n1, const BookmarkNode* n2) const { |
337 return n1->url() < n2->url(); | 340 return n1->url() < n2->url(); |
338 } | 341 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 | 429 |
427 // Returns whether the permanent node is a top-level permanent node. | 430 // Returns whether the permanent node is a top-level permanent node. |
428 bool IsTopLevelPermanentNode(const BookmarkPermanentNode* node); | 431 bool IsTopLevelPermanentNode(const BookmarkPermanentNode* node); |
429 | 432 |
430 // Returns true if the permanent node can have its title updated. | 433 // Returns true if the permanent node can have its title updated. |
431 bool CanSetPermanentNodeTitle(const BookmarkNode* node); | 434 bool CanSetPermanentNodeTitle(const BookmarkNode* node); |
432 | 435 |
433 // Returns true if touch icons are preferred over favicons. | 436 // Returns true if touch icons are preferred over favicons. |
434 bool PreferTouchIcon(); | 437 bool PreferTouchIcon(); |
435 | 438 |
436 BookmarkClient* const client_; | 439 scoped_ptr<BookmarkClient> bookmark_client_; |
437 | 440 |
438 // Whether the initial set of data has been loaded. | 441 // Whether the initial set of data has been loaded. |
439 bool loaded_; | 442 bool loaded_; |
440 | 443 |
441 // The root node. This contains the bookmark bar node, the 'other' node and | 444 // The root node. This contains the bookmark bar node, the 'other' node and |
442 // the mobile node as children. | 445 // the mobile node as children. |
443 BookmarkNode root_; | 446 BookmarkNode root_; |
444 | 447 |
445 BookmarkPermanentNode* bookmark_bar_node_; | 448 BookmarkPermanentNode* bookmark_bar_node_; |
446 BookmarkPermanentNode* other_node_; | 449 BookmarkPermanentNode* other_node_; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 scoped_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_; | 481 scoped_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_; |
479 | 482 |
480 std::set<std::string> non_cloned_keys_; | 483 std::set<std::string> non_cloned_keys_; |
481 | 484 |
482 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); | 485 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); |
483 }; | 486 }; |
484 | 487 |
485 } // namespace bookmarks | 488 } // namespace bookmarks |
486 | 489 |
487 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ | 490 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ |
OLD | NEW |