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> |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 // | 61 // |
62 // You should NOT directly create a BookmarkModel, instead go through the | 62 // You should NOT directly create a BookmarkModel, instead go through the |
63 // BookmarkModelFactory. | 63 // BookmarkModelFactory. |
64 class BookmarkModel : public KeyedService { | 64 class BookmarkModel : public KeyedService { |
65 public: | 65 public: |
66 struct URLAndTitle { | 66 struct URLAndTitle { |
67 GURL url; | 67 GURL url; |
68 base::string16 title; | 68 base::string16 title; |
69 }; | 69 }; |
70 | 70 |
71 class UndoDelegate { | |
sky
2015/10/07 16:30:15
Move into it's own header (see chromium specific s
jianli
2015/10/07 23:26:55
Done.
| |
72 public: | |
73 // Called when a bookmark node was deleted. The delegate takes the ownership | |
74 // of the deleted node. | |
75 // | |
76 // |parent_node_id| the id of the parent of the node that will be removed. | |
77 // |index| the index of the node about to be removed in |parent|. | |
78 // |node| is the node to be deleted. | |
79 virtual void OnBookmarkNodeDeleted(BookmarkModel* model, | |
80 int64_t parent_node_id, | |
sky
2015/10/07 16:30:15
I would rather supply the BoomarkNode as the paren
jianli
2015/10/07 23:26:55
Done.
| |
81 int index, | |
82 BookmarkNode* node) = 0; | |
sky
2015/10/07 16:30:15
Use scoped_ptr to clarify ownership.
jianli
2015/10/07 23:26:55
Done.
| |
83 }; | |
84 | |
71 explicit BookmarkModel(BookmarkClient* client); | 85 explicit BookmarkModel(BookmarkClient* client); |
72 ~BookmarkModel() override; | 86 ~BookmarkModel() override; |
73 | 87 |
74 // KeyedService: | 88 // KeyedService: |
75 void Shutdown() override; | 89 void Shutdown() override; |
76 | 90 |
77 // Loads the bookmarks. This is called upon creation of the | 91 // Loads the bookmarks. This is called upon creation of the |
78 // BookmarkModel. You need not invoke this directly. | 92 // BookmarkModel. You need not invoke this directly. |
79 // All load operations will be executed on |io_task_runner| and the completion | 93 // All load operations will be executed on |io_task_runner| and the completion |
80 // callback will be called from |ui_task_runner|. | 94 // callback will be called from |ui_task_runner|. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 | 227 |
214 // Adds a url with a specific creation date and meta info. | 228 // Adds a url with a specific creation date and meta info. |
215 const BookmarkNode* AddURLWithCreationTimeAndMetaInfo( | 229 const BookmarkNode* AddURLWithCreationTimeAndMetaInfo( |
216 const BookmarkNode* parent, | 230 const BookmarkNode* parent, |
217 int index, | 231 int index, |
218 const base::string16& title, | 232 const base::string16& title, |
219 const GURL& url, | 233 const GURL& url, |
220 const base::Time& creation_time, | 234 const base::Time& creation_time, |
221 const BookmarkNode::MetaInfoMap* meta_info); | 235 const BookmarkNode::MetaInfoMap* meta_info); |
222 | 236 |
237 // Adds the |node| at |parent| in the specified |index| and notifies its | |
238 // observers. | |
239 BookmarkNode* AddNode(BookmarkNode* parent, | |
sky
2015/10/07 16:30:15
I don't want this to be public. Expose an interfac
jianli
2015/10/07 23:26:56
Done.
| |
240 int index, | |
241 BookmarkNode* node); | |
242 | |
223 // Sorts the children of |parent|, notifying observers by way of the | 243 // Sorts the children of |parent|, notifying observers by way of the |
224 // BookmarkNodeChildrenReordered method. | 244 // BookmarkNodeChildrenReordered method. |
225 void SortChildren(const BookmarkNode* parent); | 245 void SortChildren(const BookmarkNode* parent); |
226 | 246 |
227 // Order the children of |parent| as specified in |ordered_nodes|. This | 247 // Order the children of |parent| as specified in |ordered_nodes|. This |
228 // function should only be used to reorder the child nodes of |parent| and | 248 // function should only be used to reorder the child nodes of |parent| and |
229 // is not meant to move nodes between different parent. Notifies observers | 249 // is not meant to move nodes between different parent. Notifies observers |
230 // using the BookmarkNodeChildrenReordered method. | 250 // using the BookmarkNodeChildrenReordered method. |
231 void ReorderChildren(const BookmarkNode* parent, | 251 void ReorderChildren(const BookmarkNode* parent, |
232 const std::vector<const BookmarkNode*>& ordered_nodes); | 252 const std::vector<const BookmarkNode*>& ordered_nodes); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 // http://www.google.com) and the given icon URL (e.g. | 321 // 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 | 322 // 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 | 323 // OnFaviconsChanged() with non-empty |page_urls| and an empty |icon_url| and |
304 // vice versa. | 324 // vice versa. |
305 void OnFaviconsChanged(const std::set<GURL>& page_urls, | 325 void OnFaviconsChanged(const std::set<GURL>& page_urls, |
306 const GURL& icon_url); | 326 const GURL& icon_url); |
307 | 327 |
308 // Returns the client used by this BookmarkModel. | 328 // Returns the client used by this BookmarkModel. |
309 BookmarkClient* client() const { return client_; } | 329 BookmarkClient* client() const { return client_; } |
310 | 330 |
331 void set_undo_delegate(UndoDelegate* undo_delegate) { | |
332 undo_delegate_ = undo_delegate; | |
333 } | |
334 | |
311 private: | 335 private: |
312 friend class BookmarkCodecTest; | 336 friend class BookmarkCodecTest; |
313 friend class BookmarkModelFaviconTest; | 337 friend class BookmarkModelFaviconTest; |
314 friend class BookmarkStorage; | 338 friend class BookmarkStorage; |
315 friend class ScopedGroupBookmarkActions; | 339 friend class ScopedGroupBookmarkActions; |
316 friend class TestBookmarkClient; | 340 friend class TestBookmarkClient; |
317 | 341 |
318 // Used to order BookmarkNodes by URL. | 342 // Used to order BookmarkNodes by URL. |
319 class NodeURLComparator { | 343 class NodeURLComparator { |
320 public: | 344 public: |
(...skipping 26 matching lines...) Expand all Loading... | |
347 void RemoveNodeAndGetRemovedUrls(BookmarkNode* node, | 371 void RemoveNodeAndGetRemovedUrls(BookmarkNode* node, |
348 std::set<GURL>* removed_urls); | 372 std::set<GURL>* removed_urls); |
349 | 373 |
350 // Removes the node from its parent, sends notification, and deletes it. | 374 // Removes the node from its parent, sends notification, and deletes it. |
351 // type specifies how the node should be removed. | 375 // type specifies how the node should be removed. |
352 void RemoveAndDeleteNode(BookmarkNode* delete_me); | 376 void RemoveAndDeleteNode(BookmarkNode* delete_me); |
353 | 377 |
354 // Remove |node| from |nodes_ordered_by_url_set_| and |index_|. | 378 // Remove |node| from |nodes_ordered_by_url_set_| and |index_|. |
355 void RemoveNodeFromInternalMaps(BookmarkNode* node); | 379 void RemoveNodeFromInternalMaps(BookmarkNode* node); |
356 | 380 |
357 // Adds the |node| at |parent| in the specified |index| and notifies its | |
358 // observers. | |
359 BookmarkNode* AddNode(BookmarkNode* parent, | |
360 int index, | |
361 BookmarkNode* node); | |
362 | |
363 // Adds the |node| to |nodes_ordered_by_url_set_| and |index_|. | 381 // Adds the |node| to |nodes_ordered_by_url_set_| and |index_|. |
364 void AddNodeToInternalMaps(BookmarkNode* node); | 382 void AddNodeToInternalMaps(BookmarkNode* node); |
365 | 383 |
366 // Returns true if the parent and index are valid. | 384 // Returns true if the parent and index are valid. |
367 bool IsValidIndex(const BookmarkNode* parent, int index, bool allow_end); | 385 bool IsValidIndex(const BookmarkNode* parent, int index, bool allow_end); |
368 | 386 |
369 // Creates one of the possible permanent nodes (bookmark bar node, other node | 387 // Creates one of the possible permanent nodes (bookmark bar node, other node |
370 // and mobile node) from |type|. | 388 // and mobile node) from |type|. |
371 BookmarkPermanentNode* CreatePermanentNode(BookmarkNode::Type type); | 389 BookmarkPermanentNode* CreatePermanentNode(BookmarkNode::Type type); |
372 | 390 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 | 460 |
443 base::WaitableEvent loaded_signal_; | 461 base::WaitableEvent loaded_signal_; |
444 | 462 |
445 // See description of IsDoingExtensiveChanges above. | 463 // See description of IsDoingExtensiveChanges above. |
446 int extensive_changes_; | 464 int extensive_changes_; |
447 | 465 |
448 scoped_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_; | 466 scoped_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_; |
449 | 467 |
450 std::set<std::string> non_cloned_keys_; | 468 std::set<std::string> non_cloned_keys_; |
451 | 469 |
470 UndoDelegate* undo_delegate_; | |
471 | |
452 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); | 472 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); |
453 }; | 473 }; |
454 | 474 |
455 } // namespace bookmarks | 475 } // namespace bookmarks |
456 | 476 |
457 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ | 477 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ |
OLD | NEW |