OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/bookmarks/bookmark_model.h" | 5 #include "chrome/browser/bookmarks/bookmark_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 | 64 |
65 BookmarkNode::BookmarkNode(int64 id, const GURL& url) | 65 BookmarkNode::BookmarkNode(int64 id, const GURL& url) |
66 : url_(url) { | 66 : url_(url) { |
67 Initialize(id); | 67 Initialize(id); |
68 } | 68 } |
69 | 69 |
70 BookmarkNode::~BookmarkNode() { | 70 BookmarkNode::~BookmarkNode() { |
71 } | 71 } |
72 | 72 |
73 void BookmarkNode::SetTitle(const string16& title) { | 73 void BookmarkNode::SetTitle(const base::string16& title) { |
74 // Replace newlines and other problematic whitespace characters in | 74 // Replace newlines and other problematic whitespace characters in |
75 // folder/bookmark names with spaces. | 75 // folder/bookmark names with spaces. |
76 string16 trimmed_title; | 76 base::string16 trimmed_title; |
77 base::ReplaceChars(title, kInvalidChars, ASCIIToUTF16(" "), &trimmed_title); | 77 base::ReplaceChars(title, kInvalidChars, ASCIIToUTF16(" "), &trimmed_title); |
78 ui::TreeNode<BookmarkNode>::SetTitle(trimmed_title); | 78 ui::TreeNode<BookmarkNode>::SetTitle(trimmed_title); |
79 } | 79 } |
80 | 80 |
81 bool BookmarkNode::IsVisible() const { | 81 bool BookmarkNode::IsVisible() const { |
82 return true; | 82 return true; |
83 } | 83 } |
84 | 84 |
85 bool BookmarkNode::GetMetaInfo(const std::string& key, | 85 bool BookmarkNode::GetMetaInfo(const std::string& key, |
86 std::string* value) const { | 86 std::string* value) const { |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 const gfx::Image& BookmarkModel::GetFavicon(const BookmarkNode* node) { | 391 const gfx::Image& BookmarkModel::GetFavicon(const BookmarkNode* node) { |
392 DCHECK(node); | 392 DCHECK(node); |
393 if (node->favicon_state() == BookmarkNode::INVALID_FAVICON) { | 393 if (node->favicon_state() == BookmarkNode::INVALID_FAVICON) { |
394 BookmarkNode* mutable_node = AsMutable(node); | 394 BookmarkNode* mutable_node = AsMutable(node); |
395 mutable_node->set_favicon_state(BookmarkNode::LOADING_FAVICON); | 395 mutable_node->set_favicon_state(BookmarkNode::LOADING_FAVICON); |
396 LoadFavicon(mutable_node); | 396 LoadFavicon(mutable_node); |
397 } | 397 } |
398 return node->favicon(); | 398 return node->favicon(); |
399 } | 399 } |
400 | 400 |
401 void BookmarkModel::SetTitle(const BookmarkNode* node, const string16& title) { | 401 void BookmarkModel::SetTitle(const BookmarkNode* node, const base::string16& tit
le) { |
402 if (!node) { | 402 if (!node) { |
403 NOTREACHED(); | 403 NOTREACHED(); |
404 return; | 404 return; |
405 } | 405 } |
406 if (node->GetTitle() == title) | 406 if (node->GetTitle() == title) |
407 return; | 407 return; |
408 | 408 |
409 if (is_permanent_node(node)) { | 409 if (is_permanent_node(node)) { |
410 NOTREACHED(); | 410 NOTREACHED(); |
411 return; | 411 return; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 loaded_signal_.Wait(); | 595 loaded_signal_.Wait(); |
596 } | 596 } |
597 | 597 |
598 const BookmarkNode* BookmarkModel::GetNodeByID(int64 id) const { | 598 const BookmarkNode* BookmarkModel::GetNodeByID(int64 id) const { |
599 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. | 599 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. |
600 return GetNodeByID(&root_, id); | 600 return GetNodeByID(&root_, id); |
601 } | 601 } |
602 | 602 |
603 const BookmarkNode* BookmarkModel::AddFolder(const BookmarkNode* parent, | 603 const BookmarkNode* BookmarkModel::AddFolder(const BookmarkNode* parent, |
604 int index, | 604 int index, |
605 const string16& title) { | 605 const base::string16& title) { |
606 if (!loaded_ || is_root_node(parent) || !IsValidIndex(parent, index, true)) { | 606 if (!loaded_ || is_root_node(parent) || !IsValidIndex(parent, index, true)) { |
607 // Can't add to the root. | 607 // Can't add to the root. |
608 NOTREACHED(); | 608 NOTREACHED(); |
609 return NULL; | 609 return NULL; |
610 } | 610 } |
611 | 611 |
612 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), GURL()); | 612 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), GURL()); |
613 new_node->set_date_folder_modified(Time::Now()); | 613 new_node->set_date_folder_modified(Time::Now()); |
614 // Folders shouldn't have line breaks in their titles. | 614 // Folders shouldn't have line breaks in their titles. |
615 new_node->SetTitle(title); | 615 new_node->SetTitle(title); |
616 new_node->set_type(BookmarkNode::FOLDER); | 616 new_node->set_type(BookmarkNode::FOLDER); |
617 | 617 |
618 return AddNode(AsMutable(parent), index, new_node); | 618 return AddNode(AsMutable(parent), index, new_node); |
619 } | 619 } |
620 | 620 |
621 const BookmarkNode* BookmarkModel::AddURL(const BookmarkNode* parent, | 621 const BookmarkNode* BookmarkModel::AddURL(const BookmarkNode* parent, |
622 int index, | 622 int index, |
623 const string16& title, | 623 const base::string16& title, |
624 const GURL& url) { | 624 const GURL& url) { |
625 return AddURLWithCreationTime(parent, index, | 625 return AddURLWithCreationTime(parent, index, |
626 CollapseWhitespace(title, false), | 626 CollapseWhitespace(title, false), |
627 url, Time::Now()); | 627 url, Time::Now()); |
628 } | 628 } |
629 | 629 |
630 const BookmarkNode* BookmarkModel::AddURLWithCreationTime( | 630 const BookmarkNode* BookmarkModel::AddURLWithCreationTime( |
631 const BookmarkNode* parent, | 631 const BookmarkNode* parent, |
632 int index, | 632 int index, |
633 const string16& title, | 633 const base::string16& title, |
634 const GURL& url, | 634 const GURL& url, |
635 const Time& creation_time) { | 635 const Time& creation_time) { |
636 if (!loaded_ || !url.is_valid() || is_root_node(parent) || | 636 if (!loaded_ || !url.is_valid() || is_root_node(parent) || |
637 !IsValidIndex(parent, index, true)) { | 637 !IsValidIndex(parent, index, true)) { |
638 NOTREACHED(); | 638 NOTREACHED(); |
639 return NULL; | 639 return NULL; |
640 } | 640 } |
641 | 641 |
642 // Syncing may result in dates newer than the last modified date. | 642 // Syncing may result in dates newer than the last modified date. |
643 if (creation_time > parent->date_folder_modified()) | 643 if (creation_time > parent->date_folder_modified()) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 | 710 |
711 if (store_.get()) | 711 if (store_.get()) |
712 store_->ScheduleSave(); | 712 store_->ScheduleSave(); |
713 } | 713 } |
714 | 714 |
715 void BookmarkModel::ResetDateFolderModified(const BookmarkNode* node) { | 715 void BookmarkModel::ResetDateFolderModified(const BookmarkNode* node) { |
716 SetDateFolderModified(node, Time()); | 716 SetDateFolderModified(node, Time()); |
717 } | 717 } |
718 | 718 |
719 void BookmarkModel::GetBookmarksWithTitlesMatching( | 719 void BookmarkModel::GetBookmarksWithTitlesMatching( |
720 const string16& text, | 720 const base::string16& text, |
721 size_t max_count, | 721 size_t max_count, |
722 std::vector<BookmarkTitleMatch>* matches) { | 722 std::vector<BookmarkTitleMatch>* matches) { |
723 if (!loaded_) | 723 if (!loaded_) |
724 return; | 724 return; |
725 | 725 |
726 index_->GetBookmarksWithTitlesMatching(text, max_count, matches); | 726 index_->GetBookmarksWithTitlesMatching(text, max_count, matches); |
727 } | 727 } |
728 | 728 |
729 void BookmarkModel::ClearStore() { | 729 void BookmarkModel::ClearStore() { |
730 registrar_.RemoveAll(); | 730 registrar_.RemoveAll(); |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 BookmarkPermanentNode* bb_node = | 1058 BookmarkPermanentNode* bb_node = |
1059 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); | 1059 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); |
1060 BookmarkPermanentNode* other_node = | 1060 BookmarkPermanentNode* other_node = |
1061 CreatePermanentNode(BookmarkNode::OTHER_NODE); | 1061 CreatePermanentNode(BookmarkNode::OTHER_NODE); |
1062 BookmarkPermanentNode* mobile_node = | 1062 BookmarkPermanentNode* mobile_node = |
1063 CreatePermanentNode(BookmarkNode::MOBILE); | 1063 CreatePermanentNode(BookmarkNode::MOBILE); |
1064 return new BookmarkLoadDetails(bb_node, other_node, mobile_node, | 1064 return new BookmarkLoadDetails(bb_node, other_node, mobile_node, |
1065 new BookmarkIndex(profile_), | 1065 new BookmarkIndex(profile_), |
1066 next_node_id_); | 1066 next_node_id_); |
1067 } | 1067 } |
OLD | NEW |