Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: chrome/browser/history/starred_url_database.cc

Issue 1912: Renames BoomarkBarModel to BookmarkModel. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/logging.h" 8 #include "base/logging.h"
9 #include "base/json_writer.h" 9 #include "base/json_writer.h"
10 #include "chrome/browser/bookmarks/bookmark_bar_model.h"
11 #include "chrome/browser/bookmarks/bookmark_codec.h" 10 #include "chrome/browser/bookmarks/bookmark_codec.h"
11 #include "chrome/browser/bookmarks/bookmark_model.h"
12 #include "chrome/browser/history/history.h" 12 #include "chrome/browser/history/history.h"
13 #include "chrome/browser/history/query_parser.h" 13 #include "chrome/browser/history/query_parser.h"
14 #include "chrome/browser/meta_table_helper.h" 14 #include "chrome/browser/meta_table_helper.h"
15 #include "chrome/common/scoped_vector.h" 15 #include "chrome/common/scoped_vector.h"
16 #include "chrome/common/sqlite_compiled_statement.h" 16 #include "chrome/common/sqlite_compiled_statement.h"
17 #include "chrome/common/sqlite_utils.h" 17 #include "chrome/common/sqlite_utils.h"
18 #include "chrome/common/stl_util-inl.h" 18 #include "chrome/common/stl_util-inl.h"
19 19
20 // The following table is used to store star (aka bookmark) information. This 20 // The following table is used to store star (aka bookmark) information. This
21 // class derives from URLDatabase, which has its own schema. 21 // class derives from URLDatabase, which has its own schema.
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 } 534 }
535 535
536 bool StarredURLDatabase::MigrateBookmarksToFileImpl(const std::wstring& path) { 536 bool StarredURLDatabase::MigrateBookmarksToFileImpl(const std::wstring& path) {
537 std::vector<history::StarredEntry> entries; 537 std::vector<history::StarredEntry> entries;
538 if (!GetAllStarredEntries(&entries)) 538 if (!GetAllStarredEntries(&entries))
539 return false; 539 return false;
540 540
541 // Create the bookmark bar and other folder nodes. 541 // Create the bookmark bar and other folder nodes.
542 history::StarredEntry entry; 542 history::StarredEntry entry;
543 entry.type = history::StarredEntry::BOOKMARK_BAR; 543 entry.type = history::StarredEntry::BOOKMARK_BAR;
544 BookmarkBarNode bookmark_bar_node(NULL, GURL()); 544 BookmarkNode bookmark_bar_node(NULL, GURL());
545 bookmark_bar_node.Reset(entry); 545 bookmark_bar_node.Reset(entry);
546 entry.type = history::StarredEntry::OTHER; 546 entry.type = history::StarredEntry::OTHER;
547 BookmarkBarNode other_node(NULL, GURL()); 547 BookmarkNode other_node(NULL, GURL());
548 other_node.Reset(entry); 548 other_node.Reset(entry);
549 549
550 std::map<history::UIStarID, history::StarID> group_id_to_id_map; 550 std::map<history::UIStarID, history::StarID> group_id_to_id_map;
551 typedef std::map<history::StarID, BookmarkBarNode*> IDToNodeMap; 551 typedef std::map<history::StarID, BookmarkNode*> IDToNodeMap;
552 IDToNodeMap id_to_node_map; 552 IDToNodeMap id_to_node_map;
553 553
554 history::UIStarID other_folder_group_id = 0; 554 history::UIStarID other_folder_group_id = 0;
555 history::StarID other_folder_id = 0; 555 history::StarID other_folder_id = 0;
556 556
557 // Iterate through the entries building a mapping between group_id and id. 557 // Iterate through the entries building a mapping between group_id and id.
558 for (std::vector<history::StarredEntry>::const_iterator i = entries.begin(); 558 for (std::vector<history::StarredEntry>::const_iterator i = entries.begin();
559 i != entries.end(); ++i) { 559 i != entries.end(); ++i) {
560 if (i->type != history::StarredEntry::URL) { 560 if (i->type != history::StarredEntry::URL) {
561 group_id_to_id_map[i->group_id] = i->id; 561 group_id_to_id_map[i->group_id] = i->id;
(...skipping 17 matching lines...) Expand all
579 for (std::vector<history::StarredEntry>::iterator i = entries.begin(); 579 for (std::vector<history::StarredEntry>::iterator i = entries.begin();
580 i != entries.end(); ++i) { 580 i != entries.end(); ++i) {
581 if (!i->parent_group_id) { 581 if (!i->parent_group_id) {
582 DCHECK(i->type == history::StarredEntry::BOOKMARK_BAR || 582 DCHECK(i->type == history::StarredEntry::BOOKMARK_BAR ||
583 i->type == history::StarredEntry::OTHER); 583 i->type == history::StarredEntry::OTHER);
584 // Only entries with no parent should be the bookmark bar and other 584 // Only entries with no parent should be the bookmark bar and other
585 // bookmarks folders. 585 // bookmarks folders.
586 continue; 586 continue;
587 } 587 }
588 588
589 BookmarkBarNode* node = id_to_node_map[i->id]; 589 BookmarkNode* node = id_to_node_map[i->id];
590 if (!node) { 590 if (!node) {
591 // Creating a node results in creating the parent. As such, it is 591 // Creating a node results in creating the parent. As such, it is
592 // possible for the node representing a group to have been created before 592 // possible for the node representing a group to have been created before
593 // encountering the details. 593 // encountering the details.
594 594
595 // The created nodes are owned by the root node. 595 // The created nodes are owned by the root node.
596 node = new BookmarkBarNode(NULL, i->url); 596 node = new BookmarkNode(NULL, i->url);
597 id_to_node_map[i->id] = node; 597 id_to_node_map[i->id] = node;
598 } 598 }
599 node->Reset(*i); 599 node->Reset(*i);
600 600
601 DCHECK(group_id_to_id_map.find(i->parent_group_id) != 601 DCHECK(group_id_to_id_map.find(i->parent_group_id) !=
602 group_id_to_id_map.end()); 602 group_id_to_id_map.end());
603 history::StarID parent_id = group_id_to_id_map[i->parent_group_id]; 603 history::StarID parent_id = group_id_to_id_map[i->parent_group_id];
604 BookmarkBarNode* parent = id_to_node_map[parent_id]; 604 BookmarkNode* parent = id_to_node_map[parent_id];
605 if (!parent) { 605 if (!parent) {
606 // Haven't encountered the parent yet, create it now. 606 // Haven't encountered the parent yet, create it now.
607 parent = new BookmarkBarNode(NULL, GURL()); 607 parent = new BookmarkNode(NULL, GURL());
608 id_to_node_map[parent_id] = parent; 608 id_to_node_map[parent_id] = parent;
609 } 609 }
610 610
611 // Add the node to its parent. |entries| is ordered by parent then 611 // Add the node to its parent. |entries| is ordered by parent then
612 // visual order so that we know we maintain visual order by always adding 612 // visual order so that we know we maintain visual order by always adding
613 // to the end. 613 // to the end.
614 parent->Add(parent->GetChildCount(), node); 614 parent->Add(parent->GetChildCount(), node);
615 } 615 }
616 616
617 // Save to file. 617 // Save to file.
618 BookmarkCodec encoder; 618 BookmarkCodec encoder;
619 scoped_ptr<Value> encoded_bookmarks( 619 scoped_ptr<Value> encoded_bookmarks(
620 encoder.Encode(&bookmark_bar_node, &other_node)); 620 encoder.Encode(&bookmark_bar_node, &other_node));
621 std::string content; 621 std::string content;
622 JSONWriter::Write(encoded_bookmarks.get(), true, &content); 622 JSONWriter::Write(encoded_bookmarks.get(), true, &content);
623 623
624 return (file_util::WriteFile(path, content.c_str(), 624 return (file_util::WriteFile(path, content.c_str(),
625 static_cast<int>(content.length())) != -1); 625 static_cast<int>(content.length())) != -1);
626 } 626 }
627 627
628 } // namespace history 628 } // namespace history
629 629
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698