OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/history/starred_url_database.h" | 5 #include "chrome/browser/history/starred_url_database.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 break; | 97 break; |
98 case history::StarredEntry::USER_FOLDER: | 98 case history::StarredEntry::USER_FOLDER: |
99 node->set_type(BookmarkNode::FOLDER); | 99 node->set_type(BookmarkNode::FOLDER); |
100 break; | 100 break; |
101 case history::StarredEntry::BOOKMARK_BAR: | 101 case history::StarredEntry::BOOKMARK_BAR: |
102 node->set_type(BookmarkNode::BOOKMARK_BAR); | 102 node->set_type(BookmarkNode::BOOKMARK_BAR); |
103 break; | 103 break; |
104 case history::StarredEntry::OTHER: | 104 case history::StarredEntry::OTHER: |
105 node->set_type(BookmarkNode::OTHER_NODE); | 105 node->set_type(BookmarkNode::OTHER_NODE); |
106 break; | 106 break; |
107 case history::StarredEntry::SYNCED: | 107 case history::StarredEntry::MOBILE: |
108 node->set_type(BookmarkNode::SYNCED); | 108 node->set_type(BookmarkNode::MOBILE); |
109 break; | 109 break; |
110 default: | 110 default: |
111 NOTREACHED(); | 111 NOTREACHED(); |
112 break; | 112 break; |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 } // namespace | 116 } // namespace |
117 | 117 |
118 // static | 118 // static |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 return false; | 580 return false; |
581 | 581 |
582 // Create the bookmark bar and other folder nodes. | 582 // Create the bookmark bar and other folder nodes. |
583 history::StarredEntry entry; | 583 history::StarredEntry entry; |
584 entry.type = history::StarredEntry::BOOKMARK_BAR; | 584 entry.type = history::StarredEntry::BOOKMARK_BAR; |
585 BookmarkNode bookmark_bar_node(0, GURL()); | 585 BookmarkNode bookmark_bar_node(0, GURL()); |
586 ResetBookmarkNode(entry, &bookmark_bar_node); | 586 ResetBookmarkNode(entry, &bookmark_bar_node); |
587 entry.type = history::StarredEntry::OTHER; | 587 entry.type = history::StarredEntry::OTHER; |
588 BookmarkNode other_node(0, GURL()); | 588 BookmarkNode other_node(0, GURL()); |
589 ResetBookmarkNode(entry, &other_node); | 589 ResetBookmarkNode(entry, &other_node); |
590 // NOTE(yfriedman): We don't do anything with the synced star node because it | 590 // NOTE(yfriedman): We don't do anything with the mobile node because it won't |
591 // won't ever exist in the starred node DB. We only need to create it to pass | 591 // ever exist in the starred node DB. We only need to create it to pass to |
592 // to "encode". | 592 // "encode". |
593 entry.type = history::StarredEntry::SYNCED; | 593 entry.type = history::StarredEntry::MOBILE; |
594 BookmarkNode synced_node(0, GURL()); | 594 BookmarkNode mobile_node(0, GURL()); |
595 ResetBookmarkNode(entry, &synced_node); | 595 ResetBookmarkNode(entry, &mobile_node); |
596 | 596 |
597 std::map<history::UIStarID, history::StarID> folder_id_to_id_map; | 597 std::map<history::UIStarID, history::StarID> folder_id_to_id_map; |
598 typedef std::map<history::StarID, BookmarkNode*> IDToNodeMap; | 598 typedef std::map<history::StarID, BookmarkNode*> IDToNodeMap; |
599 IDToNodeMap id_to_node_map; | 599 IDToNodeMap id_to_node_map; |
600 | 600 |
601 history::UIStarID other_folder_folder_id = 0; | 601 history::UIStarID other_folder_folder_id = 0; |
602 history::StarID other_folder_id = 0; | 602 history::StarID other_folder_id = 0; |
603 | 603 |
604 // Iterate through the entries building a mapping between folder_id and id. | 604 // Iterate through the entries building a mapping between folder_id and id. |
605 for (std::vector<history::StarredEntry>::const_iterator i = entries.begin(); | 605 for (std::vector<history::StarredEntry>::const_iterator i = entries.begin(); |
(...skipping 13 matching lines...) Expand all Loading... |
619 if (other_folder_folder_id) { | 619 if (other_folder_folder_id) { |
620 id_to_node_map[other_folder_id] = &other_node; | 620 id_to_node_map[other_folder_id] = &other_node; |
621 folder_id_to_id_map[other_folder_folder_id] = other_folder_id; | 621 folder_id_to_id_map[other_folder_folder_id] = other_folder_id; |
622 } | 622 } |
623 | 623 |
624 // Iterate through the entries again creating the nodes. | 624 // Iterate through the entries again creating the nodes. |
625 for (std::vector<history::StarredEntry>::iterator i = entries.begin(); | 625 for (std::vector<history::StarredEntry>::iterator i = entries.begin(); |
626 i != entries.end(); ++i) { | 626 i != entries.end(); ++i) { |
627 if (!i->parent_folder_id) { | 627 if (!i->parent_folder_id) { |
628 DCHECK(i->type == history::StarredEntry::BOOKMARK_BAR || | 628 DCHECK(i->type == history::StarredEntry::BOOKMARK_BAR || |
629 i->type == history::StarredEntry::SYNCED || | 629 i->type == history::StarredEntry::MOBILE || |
630 i->type == history::StarredEntry::OTHER); | 630 i->type == history::StarredEntry::OTHER); |
631 // Only entries with no parent should be the bookmark bar and other | 631 // Only entries with no parent should be the bookmark bar and other |
632 // bookmarks folders. | 632 // bookmarks folders. |
633 continue; | 633 continue; |
634 } | 634 } |
635 | 635 |
636 BookmarkNode* node = id_to_node_map[i->id]; | 636 BookmarkNode* node = id_to_node_map[i->id]; |
637 if (!node) { | 637 if (!node) { |
638 // Creating a node results in creating the parent. As such, it is | 638 // Creating a node results in creating the parent. As such, it is |
639 // possible for the node representing a folder to have been created before | 639 // possible for the node representing a folder to have been created before |
(...skipping 17 matching lines...) Expand all Loading... |
657 | 657 |
658 // Add the node to its parent. |entries| is ordered by parent then | 658 // Add the node to its parent. |entries| is ordered by parent then |
659 // visual order so that we know we maintain visual order by always adding | 659 // visual order so that we know we maintain visual order by always adding |
660 // to the end. | 660 // to the end. |
661 parent->Add(node, parent->child_count()); | 661 parent->Add(node, parent->child_count()); |
662 } | 662 } |
663 | 663 |
664 // Save to file. | 664 // Save to file. |
665 BookmarkCodec encoder; | 665 BookmarkCodec encoder; |
666 scoped_ptr<Value> encoded_bookmarks( | 666 scoped_ptr<Value> encoded_bookmarks( |
667 encoder.Encode(&bookmark_bar_node, &other_node, &synced_node)); | 667 encoder.Encode(&bookmark_bar_node, &other_node, &mobile_node)); |
668 std::string content; | 668 std::string content; |
669 base::JSONWriter::Write(encoded_bookmarks.get(), true, &content); | 669 base::JSONWriter::Write(encoded_bookmarks.get(), true, &content); |
670 | 670 |
671 return (file_util::WriteFile(path, content.c_str(), | 671 return (file_util::WriteFile(path, content.c_str(), |
672 static_cast<int>(content.length())) != -1); | 672 static_cast<int>(content.length())) != -1); |
673 } | 673 } |
674 | 674 |
675 } // namespace history | 675 } // namespace history |
OLD | NEW |