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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 // http://www.google.com) and the given icon URL (e.g. | 301 // 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 | 302 // 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 | 303 // OnFaviconsChanged() with non-empty |page_urls| and an empty |icon_url| and |
304 // vice versa. | 304 // vice versa. |
305 void OnFaviconsChanged(const std::set<GURL>& page_urls, | 305 void OnFaviconsChanged(const std::set<GURL>& page_urls, |
306 const GURL& icon_url); | 306 const GURL& icon_url); |
307 | 307 |
308 // Returns the client used by this BookmarkModel. | 308 // Returns the client used by this BookmarkModel. |
309 BookmarkClient* client() const { return client_; } | 309 BookmarkClient* client() const { return client_; } |
310 | 310 |
311 // Turns on/off the capability to undo removing nodes. | |
312 void EnableUndoableRemove(); | |
sky
2015/10/02 15:40:30
I think all the bookkeeping of undo should be kept
jianli
2015/10/06 22:08:24
Done.
| |
313 void DisableUndoableRemove(); | |
314 | |
315 // Undo deleting the node with |node_id| by putting it back to its original | |
316 // position. | |
317 void UndoRemove(int64_t node_id); | |
318 | |
319 // Throws aways the undo info for the deleted node. After this, the deleted | |
320 // node can no longer be restored. | |
321 void DiscardUndoableRemovedNode(int64_t node_id); | |
322 | |
311 private: | 323 private: |
312 friend class BookmarkCodecTest; | 324 friend class BookmarkCodecTest; |
313 friend class BookmarkModelFaviconTest; | 325 friend class BookmarkModelFaviconTest; |
314 friend class BookmarkStorage; | 326 friend class BookmarkStorage; |
315 friend class ScopedGroupBookmarkActions; | 327 friend class ScopedGroupBookmarkActions; |
316 friend class TestBookmarkClient; | 328 friend class TestBookmarkClient; |
317 | 329 |
318 // Used to order BookmarkNodes by URL. | 330 // Used to order BookmarkNodes by URL. |
319 class NodeURLComparator { | 331 class NodeURLComparator { |
320 public: | 332 public: |
321 bool operator()(const BookmarkNode* n1, const BookmarkNode* n2) const { | 333 bool operator()(const BookmarkNode* n1, const BookmarkNode* n2) const { |
322 return n1->url() < n2->url(); | 334 return n1->url() < n2->url(); |
323 } | 335 } |
324 }; | 336 }; |
325 | 337 |
338 // Used to track all the info necessary to bring back a deleted node. | |
339 struct RestorableDeletedNodeInfo { | |
340 int64_t parent_node_id; | |
341 int index; | |
342 BookmarkNode* node; | |
343 }; | |
344 | |
326 // Implementation of IsBookmarked. Before calling this the caller must obtain | 345 // Implementation of IsBookmarked. Before calling this the caller must obtain |
327 // a lock on |url_lock_|. | 346 // a lock on |url_lock_|. |
328 bool IsBookmarkedNoLock(const GURL& url); | 347 bool IsBookmarkedNoLock(const GURL& url); |
329 | 348 |
330 // Removes the node from internal maps and recurses through all children. If | 349 // 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. | 350 // the node is a url, its url is added to removed_urls. |
332 // | 351 // |
333 // This does NOT delete the node. | 352 // This does NOT delete the node. |
334 void RemoveNode(BookmarkNode* node, std::set<GURL>* removed_urls); | 353 void RemoveNode(BookmarkNode* node, std::set<GURL>* removed_urls); |
335 | 354 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 // Sets the maximum node ID to the given value. | 417 // Sets the maximum node ID to the given value. |
399 // This is used by BookmarkCodec to report the maximum ID after it's done | 418 // This is used by BookmarkCodec to report the maximum ID after it's done |
400 // decoding since during decoding codec assigns node IDs. | 419 // decoding since during decoding codec assigns node IDs. |
401 void set_next_node_id(int64_t id) { next_node_id_ = id; } | 420 void set_next_node_id(int64_t id) { next_node_id_ = id; } |
402 | 421 |
403 // Creates and returns a new BookmarkLoadDetails. It's up to the caller to | 422 // Creates and returns a new BookmarkLoadDetails. It's up to the caller to |
404 // delete the returned object. | 423 // delete the returned object. |
405 scoped_ptr<BookmarkLoadDetails> CreateLoadDetails( | 424 scoped_ptr<BookmarkLoadDetails> CreateLoadDetails( |
406 const std::string& accept_languages); | 425 const std::string& accept_languages); |
407 | 426 |
427 // Discards all removed nodes that are tracked for restoring. | |
428 void DiscardAllUndoableRemovedNodes(); | |
429 | |
408 BookmarkClient* const client_; | 430 BookmarkClient* const client_; |
409 | 431 |
410 // Whether the initial set of data has been loaded. | 432 // Whether the initial set of data has been loaded. |
411 bool loaded_; | 433 bool loaded_; |
412 | 434 |
413 // The root node. This contains the bookmark bar node, the 'other' node and | 435 // The root node. This contains the bookmark bar node, the 'other' node and |
414 // the mobile node as children. | 436 // the mobile node as children. |
415 BookmarkNode root_; | 437 BookmarkNode root_; |
416 | 438 |
417 BookmarkPermanentNode* bookmark_bar_node_; | 439 BookmarkPermanentNode* bookmark_bar_node_; |
(...skipping 24 matching lines...) Expand all Loading... | |
442 | 464 |
443 base::WaitableEvent loaded_signal_; | 465 base::WaitableEvent loaded_signal_; |
444 | 466 |
445 // See description of IsDoingExtensiveChanges above. | 467 // See description of IsDoingExtensiveChanges above. |
446 int extensive_changes_; | 468 int extensive_changes_; |
447 | 469 |
448 scoped_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_; | 470 scoped_ptr<BookmarkExpandedStateTracker> expanded_state_tracker_; |
449 | 471 |
450 std::set<std::string> non_cloned_keys_; | 472 std::set<std::string> non_cloned_keys_; |
451 | 473 |
474 // Whether or not to support undoing node removal. | |
475 bool undoable_remove_enabled_; | |
476 | |
477 // Tracks those deleted nodes that can be restored by the undo operations. | |
478 std::map<int64_t, RestorableDeletedNodeInfo> undoable_deleted_nodes_; | |
479 | |
452 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); | 480 DISALLOW_COPY_AND_ASSIGN(BookmarkModel); |
453 }; | 481 }; |
454 | 482 |
455 } // namespace bookmarks | 483 } // namespace bookmarks |
456 | 484 |
457 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ | 485 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_H_ |
OLD | NEW |