| 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 "app/sql/statement.h" | 7 #include "app/sql/statement.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 node->set_type(BookmarkNode::SYNCED); | 108 node->set_type(BookmarkNode::SYNCED); |
| 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 |
| 119 const int64 StarredURLDatabase::kBookmarkBarID = 1; |
| 120 |
| 118 StarredURLDatabase::StarredURLDatabase() { | 121 StarredURLDatabase::StarredURLDatabase() { |
| 119 } | 122 } |
| 120 | 123 |
| 121 StarredURLDatabase::~StarredURLDatabase() { | 124 StarredURLDatabase::~StarredURLDatabase() { |
| 122 } | 125 } |
| 123 | 126 |
| 124 bool StarredURLDatabase::MigrateBookmarksToFile(const FilePath& path) { | 127 bool StarredURLDatabase::MigrateBookmarksToFile(const FilePath& path) { |
| 125 if (!GetDB().DoesTableExist("starred")) | 128 if (!GetDB().DoesTableExist("starred")) |
| 126 return true; | 129 return true; |
| 127 | 130 |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 if (i->type != history::StarredEntry::URL) { | 602 if (i->type != history::StarredEntry::URL) { |
| 600 folder_id_to_id_map[i->folder_id] = i->id; | 603 folder_id_to_id_map[i->folder_id] = i->id; |
| 601 if (i->type == history::StarredEntry::OTHER) { | 604 if (i->type == history::StarredEntry::OTHER) { |
| 602 other_folder_id = i->id; | 605 other_folder_id = i->id; |
| 603 other_folder_folder_id = i->folder_id; | 606 other_folder_folder_id = i->folder_id; |
| 604 } | 607 } |
| 605 } | 608 } |
| 606 } | 609 } |
| 607 | 610 |
| 608 // Register the bookmark bar and other folder nodes in the maps. | 611 // Register the bookmark bar and other folder nodes in the maps. |
| 609 id_to_node_map[HistoryService::kBookmarkBarID] = &bookmark_bar_node; | 612 id_to_node_map[kBookmarkBarID] = &bookmark_bar_node; |
| 610 folder_id_to_id_map[HistoryService::kBookmarkBarID] = | 613 folder_id_to_id_map[kBookmarkBarID] = kBookmarkBarID; |
| 611 HistoryService::kBookmarkBarID; | |
| 612 if (other_folder_folder_id) { | 614 if (other_folder_folder_id) { |
| 613 id_to_node_map[other_folder_id] = &other_node; | 615 id_to_node_map[other_folder_id] = &other_node; |
| 614 folder_id_to_id_map[other_folder_folder_id] = other_folder_id; | 616 folder_id_to_id_map[other_folder_folder_id] = other_folder_id; |
| 615 } | 617 } |
| 616 | 618 |
| 617 // Iterate through the entries again creating the nodes. | 619 // Iterate through the entries again creating the nodes. |
| 618 for (std::vector<history::StarredEntry>::iterator i = entries.begin(); | 620 for (std::vector<history::StarredEntry>::iterator i = entries.begin(); |
| 619 i != entries.end(); ++i) { | 621 i != entries.end(); ++i) { |
| 620 if (!i->parent_folder_id) { | 622 if (!i->parent_folder_id) { |
| 621 DCHECK(i->type == history::StarredEntry::BOOKMARK_BAR || | 623 DCHECK(i->type == history::StarredEntry::BOOKMARK_BAR || |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 scoped_ptr<Value> encoded_bookmarks( | 661 scoped_ptr<Value> encoded_bookmarks( |
| 660 encoder.Encode(&bookmark_bar_node, &other_node, &synced_node)); | 662 encoder.Encode(&bookmark_bar_node, &other_node, &synced_node)); |
| 661 std::string content; | 663 std::string content; |
| 662 base::JSONWriter::Write(encoded_bookmarks.get(), true, &content); | 664 base::JSONWriter::Write(encoded_bookmarks.get(), true, &content); |
| 663 | 665 |
| 664 return (file_util::WriteFile(path, content.c_str(), | 666 return (file_util::WriteFile(path, content.c_str(), |
| 665 static_cast<int>(content.length())) != -1); | 667 static_cast<int>(content.length())) != -1); |
| 666 } | 668 } |
| 667 | 669 |
| 668 } // namespace history | 670 } // namespace history |
| OLD | NEW |