| 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/importer/firefox3_importer.h" | 5 #include "chrome/browser/importer/firefox3_importer.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // redirects, since we don't want them to appear in history. | 122 // redirects, since we don't want them to appear in history. |
| 123 // Firefox transition types are defined in: | 123 // Firefox transition types are defined in: |
| 124 // toolkit/components/places/public/nsINavHistoryService.idl | 124 // toolkit/components/places/public/nsINavHistoryService.idl |
| 125 const char* query = "SELECT h.url, h.title, h.visit_count, " | 125 const char* query = "SELECT h.url, h.title, h.visit_count, " |
| 126 "h.hidden, h.typed, v.visit_date " | 126 "h.hidden, h.typed, v.visit_date " |
| 127 "FROM moz_places h JOIN moz_historyvisits v " | 127 "FROM moz_places h JOIN moz_historyvisits v " |
| 128 "ON h.id = v.place_id " | 128 "ON h.id = v.place_id " |
| 129 "WHERE v.visit_type <= 3"; | 129 "WHERE v.visit_type <= 3"; |
| 130 | 130 |
| 131 sql::Statement s(db.GetUniqueStatement(query)); | 131 sql::Statement s(db.GetUniqueStatement(query)); |
| 132 if (!s) | |
| 133 return; | |
| 134 | 132 |
| 135 std::vector<history::URLRow> rows; | 133 std::vector<history::URLRow> rows; |
| 136 while (s.Step() && !cancelled()) { | 134 while (s.Step() && !cancelled()) { |
| 137 GURL url(s.ColumnString(0)); | 135 GURL url(s.ColumnString(0)); |
| 138 | 136 |
| 139 // Filter out unwanted URLs. | 137 // Filter out unwanted URLs. |
| 140 if (!CanImportURL(url)) | 138 if (!CanImportURL(url)) |
| 141 continue; | 139 continue; |
| 142 | 140 |
| 143 history::URLRow row(url); | 141 history::URLRow row(url); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 FaviconMap favicon_map; | 188 FaviconMap favicon_map; |
| 191 | 189 |
| 192 // TODO(jcampan): http://b/issue?id=1196285 we do not support POST based | 190 // TODO(jcampan): http://b/issue?id=1196285 we do not support POST based |
| 193 // keywords yet. We won't include them in the list. | 191 // keywords yet. We won't include them in the list. |
| 194 std::set<int> post_keyword_ids; | 192 std::set<int> post_keyword_ids; |
| 195 const char* query = "SELECT b.id FROM moz_bookmarks b " | 193 const char* query = "SELECT b.id FROM moz_bookmarks b " |
| 196 "INNER JOIN moz_items_annos ia ON ia.item_id = b.id " | 194 "INNER JOIN moz_items_annos ia ON ia.item_id = b.id " |
| 197 "INNER JOIN moz_anno_attributes aa ON ia.anno_attribute_id = aa.id " | 195 "INNER JOIN moz_anno_attributes aa ON ia.anno_attribute_id = aa.id " |
| 198 "WHERE aa.name = 'bookmarkProperties/POSTData'"; | 196 "WHERE aa.name = 'bookmarkProperties/POSTData'"; |
| 199 sql::Statement s(db.GetUniqueStatement(query)); | 197 sql::Statement s(db.GetUniqueStatement(query)); |
| 200 if (s) { | 198 |
| 201 while (s.Step() && !cancelled()) | 199 if (!s.is_valid()) |
| 202 post_keyword_ids.insert(s.ColumnInt(0)); | |
| 203 } else { | |
| 204 NOTREACHED(); | |
| 205 return; | 200 return; |
| 206 } | 201 |
| 202 while (s.Step() && !cancelled()) |
| 203 post_keyword_ids.insert(s.ColumnInt(0)); |
| 207 | 204 |
| 208 for (size_t i = 0; i < list.size(); ++i) { | 205 for (size_t i = 0; i < list.size(); ++i) { |
| 209 BookmarkItem* item = list[i]; | 206 BookmarkItem* item = list[i]; |
| 210 | 207 |
| 211 if (item->type == TYPE_FOLDER) { | 208 if (item->type == TYPE_FOLDER) { |
| 212 // Folders are added implicitly on adding children, so we only explicitly | 209 // Folders are added implicitly on adding children, so we only explicitly |
| 213 // add empty folders. | 210 // add empty folders. |
| 214 if (!item->empty_folder) | 211 if (!item->empty_folder) |
| 215 continue; | 212 continue; |
| 216 } else if (item->type == TYPE_BOOKMARK) { | 213 } else if (item->type == TYPE_BOOKMARK) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 if (!db.Open(file)) | 360 if (!db.Open(file)) |
| 364 return; | 361 return; |
| 365 | 362 |
| 366 const char* query = "SELECT engineid FROM engine_data " | 363 const char* query = "SELECT engineid FROM engine_data " |
| 367 "WHERE engineid NOT IN " | 364 "WHERE engineid NOT IN " |
| 368 "(SELECT engineid FROM engine_data " | 365 "(SELECT engineid FROM engine_data " |
| 369 "WHERE name='hidden') " | 366 "WHERE name='hidden') " |
| 370 "ORDER BY value ASC"; | 367 "ORDER BY value ASC"; |
| 371 | 368 |
| 372 sql::Statement s(db.GetUniqueStatement(query)); | 369 sql::Statement s(db.GetUniqueStatement(query)); |
| 373 if (!s) | 370 if (!s.is_valid()) |
| 374 return; | 371 return; |
| 375 | 372 |
| 376 FilePath app_path = app_path_.AppendASCII("searchplugins"); | 373 FilePath app_path = app_path_.AppendASCII("searchplugins"); |
| 377 FilePath profile_path = source_path_.AppendASCII("searchplugins"); | 374 FilePath profile_path = source_path_.AppendASCII("searchplugins"); |
| 378 | 375 |
| 379 // Firefox doesn't store a search engine in its sqlite database unless the | 376 // Firefox doesn't store a search engine in its sqlite database unless the |
| 380 // user has added a engine. So we get search engines from sqlite db as well | 377 // user has added a engine. So we get search engines from sqlite db as well |
| 381 // as from the file system. | 378 // as from the file system. |
| 382 if (s.Step()) { | 379 if (s.Step()) { |
| 383 const std::string kAppPrefix("[app]/"); | 380 const std::string kAppPrefix("[app]/"); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 void Firefox3Importer::LoadRootNodeID(sql::Connection* db, | 432 void Firefox3Importer::LoadRootNodeID(sql::Connection* db, |
| 436 int* toolbar_folder_id, | 433 int* toolbar_folder_id, |
| 437 int* menu_folder_id, | 434 int* menu_folder_id, |
| 438 int* unsorted_folder_id) { | 435 int* unsorted_folder_id) { |
| 439 static const char* kToolbarFolderName = "toolbar"; | 436 static const char* kToolbarFolderName = "toolbar"; |
| 440 static const char* kMenuFolderName = "menu"; | 437 static const char* kMenuFolderName = "menu"; |
| 441 static const char* kUnsortedFolderName = "unfiled"; | 438 static const char* kUnsortedFolderName = "unfiled"; |
| 442 | 439 |
| 443 const char* query = "SELECT root_name, folder_id FROM moz_bookmarks_roots"; | 440 const char* query = "SELECT root_name, folder_id FROM moz_bookmarks_roots"; |
| 444 sql::Statement s(db->GetUniqueStatement(query)); | 441 sql::Statement s(db->GetUniqueStatement(query)); |
| 445 if (!s) | |
| 446 return; | |
| 447 | 442 |
| 448 while (s.Step()) { | 443 while (s.Step()) { |
| 449 std::string folder = s.ColumnString(0); | 444 std::string folder = s.ColumnString(0); |
| 450 int id = s.ColumnInt(1); | 445 int id = s.ColumnInt(1); |
| 451 if (folder == kToolbarFolderName) | 446 if (folder == kToolbarFolderName) |
| 452 *toolbar_folder_id = id; | 447 *toolbar_folder_id = id; |
| 453 else if (folder == kMenuFolderName) | 448 else if (folder == kMenuFolderName) |
| 454 *menu_folder_id = id; | 449 *menu_folder_id = id; |
| 455 else if (folder == kUnsortedFolderName) | 450 else if (folder == kUnsortedFolderName) |
| 456 *unsorted_folder_id = id; | 451 *unsorted_folder_id = id; |
| 457 } | 452 } |
| 458 } | 453 } |
| 459 | 454 |
| 460 void Firefox3Importer::LoadLivemarkIDs(sql::Connection* db, | 455 void Firefox3Importer::LoadLivemarkIDs(sql::Connection* db, |
| 461 std::set<int>* livemark) { | 456 std::set<int>* livemark) { |
| 462 static const char* kFeedAnnotation = "livemark/feedURI"; | 457 static const char* kFeedAnnotation = "livemark/feedURI"; |
| 463 livemark->clear(); | 458 livemark->clear(); |
| 464 | 459 |
| 465 const char* query = "SELECT b.item_id " | 460 const char* query = "SELECT b.item_id " |
| 466 "FROM moz_anno_attributes a " | 461 "FROM moz_anno_attributes a " |
| 467 "JOIN moz_items_annos b ON a.id = b.anno_attribute_id " | 462 "JOIN moz_items_annos b ON a.id = b.anno_attribute_id " |
| 468 "WHERE a.name = ? "; | 463 "WHERE a.name = ? "; |
| 469 sql::Statement s(db->GetUniqueStatement(query)); | 464 sql::Statement s(db->GetUniqueStatement(query)); |
| 470 if (!s) | 465 s.BindString(0, kFeedAnnotation); |
| 471 return; | |
| 472 | 466 |
| 473 s.BindString(0, kFeedAnnotation); | |
| 474 while (s.Step() && !cancelled()) | 467 while (s.Step() && !cancelled()) |
| 475 livemark->insert(s.ColumnInt(0)); | 468 livemark->insert(s.ColumnInt(0)); |
| 476 } | 469 } |
| 477 | 470 |
| 478 void Firefox3Importer::GetTopBookmarkFolder(sql::Connection* db, | 471 void Firefox3Importer::GetTopBookmarkFolder(sql::Connection* db, |
| 479 int folder_id, | 472 int folder_id, |
| 480 BookmarkList* list) { | 473 BookmarkList* list) { |
| 481 const char* query = "SELECT b.title " | 474 const char* query = "SELECT b.title " |
| 482 "FROM moz_bookmarks b " | 475 "FROM moz_bookmarks b " |
| 483 "WHERE b.type = 2 AND b.id = ? " | 476 "WHERE b.type = 2 AND b.id = ? " |
| 484 "ORDER BY b.position"; | 477 "ORDER BY b.position"; |
| 485 sql::Statement s(db->GetUniqueStatement(query)); | 478 sql::Statement s(db->GetUniqueStatement(query)); |
| 486 if (!s) | 479 s.BindInt(0, folder_id); |
| 487 return; | |
| 488 | 480 |
| 489 s.BindInt(0, folder_id); | |
| 490 if (s.Step()) { | 481 if (s.Step()) { |
| 491 BookmarkItem* item = new BookmarkItem; | 482 BookmarkItem* item = new BookmarkItem; |
| 492 item->parent = -1; // The top level folder has no parent. | 483 item->parent = -1; // The top level folder has no parent. |
| 493 item->id = folder_id; | 484 item->id = folder_id; |
| 494 item->title = s.ColumnString16(0); | 485 item->title = s.ColumnString16(0); |
| 495 item->type = TYPE_FOLDER; | 486 item->type = TYPE_FOLDER; |
| 496 item->favicon = 0; | 487 item->favicon = 0; |
| 497 item->empty_folder = true; | 488 item->empty_folder = true; |
| 498 list->push_back(item); | 489 list->push_back(item); |
| 499 } | 490 } |
| 500 } | 491 } |
| 501 | 492 |
| 502 void Firefox3Importer::GetWholeBookmarkFolder(sql::Connection* db, | 493 void Firefox3Importer::GetWholeBookmarkFolder(sql::Connection* db, |
| 503 BookmarkList* list, | 494 BookmarkList* list, |
| 504 size_t position, | 495 size_t position, |
| 505 bool* empty_folder) { | 496 bool* empty_folder) { |
| 506 if (position >= list->size()) { | 497 if (position >= list->size()) { |
| 507 NOTREACHED(); | 498 NOTREACHED(); |
| 508 return; | 499 return; |
| 509 } | 500 } |
| 510 | 501 |
| 511 const char* query = "SELECT b.id, h.url, COALESCE(b.title, h.title), " | 502 const char* query = "SELECT b.id, h.url, COALESCE(b.title, h.title), " |
| 512 "b.type, k.keyword, b.dateAdded, h.favicon_id " | 503 "b.type, k.keyword, b.dateAdded, h.favicon_id " |
| 513 "FROM moz_bookmarks b " | 504 "FROM moz_bookmarks b " |
| 514 "LEFT JOIN moz_places h ON b.fk = h.id " | 505 "LEFT JOIN moz_places h ON b.fk = h.id " |
| 515 "LEFT JOIN moz_keywords k ON k.id = b.keyword_id " | 506 "LEFT JOIN moz_keywords k ON k.id = b.keyword_id " |
| 516 "WHERE b.type IN (1,2) AND b.parent = ? " | 507 "WHERE b.type IN (1,2) AND b.parent = ? " |
| 517 "ORDER BY b.position"; | 508 "ORDER BY b.position"; |
| 518 sql::Statement s(db->GetUniqueStatement(query)); | 509 sql::Statement s(db->GetUniqueStatement(query)); |
| 519 if (!s) | 510 s.BindInt(0, (*list)[position]->id); |
| 520 return; | |
| 521 | 511 |
| 522 s.BindInt(0, (*list)[position]->id); | |
| 523 BookmarkList temp_list; | 512 BookmarkList temp_list; |
| 524 while (s.Step()) { | 513 while (s.Step()) { |
| 525 BookmarkItem* item = new BookmarkItem; | 514 BookmarkItem* item = new BookmarkItem; |
| 526 item->parent = static_cast<int>(position); | 515 item->parent = static_cast<int>(position); |
| 527 item->id = s.ColumnInt(0); | 516 item->id = s.ColumnInt(0); |
| 528 item->url = GURL(s.ColumnString(1)); | 517 item->url = GURL(s.ColumnString(1)); |
| 529 item->title = s.ColumnString16(2); | 518 item->title = s.ColumnString16(2); |
| 530 item->type = static_cast<BookmarkItemType>(s.ColumnInt(3)); | 519 item->type = static_cast<BookmarkItemType>(s.ColumnInt(3)); |
| 531 item->keyword = s.ColumnString(4); | 520 item->keyword = s.ColumnString(4); |
| 532 item->date_added = base::Time::FromTimeT(s.ColumnInt64(5)/1000000); | 521 item->date_added = base::Time::FromTimeT(s.ColumnInt64(5)/1000000); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 547 GetWholeBookmarkFolder(db, list, list->size() - 1, &(*i)->empty_folder); | 536 GetWholeBookmarkFolder(db, list, list->size() - 1, &(*i)->empty_folder); |
| 548 } | 537 } |
| 549 } | 538 } |
| 550 | 539 |
| 551 void Firefox3Importer::LoadFavicons( | 540 void Firefox3Importer::LoadFavicons( |
| 552 sql::Connection* db, | 541 sql::Connection* db, |
| 553 const FaviconMap& favicon_map, | 542 const FaviconMap& favicon_map, |
| 554 std::vector<history::ImportedFaviconUsage>* favicons) { | 543 std::vector<history::ImportedFaviconUsage>* favicons) { |
| 555 const char* query = "SELECT url, data FROM moz_favicons WHERE id=?"; | 544 const char* query = "SELECT url, data FROM moz_favicons WHERE id=?"; |
| 556 sql::Statement s(db->GetUniqueStatement(query)); | 545 sql::Statement s(db->GetUniqueStatement(query)); |
| 557 if (!s) | 546 |
| 547 if (!s.is_valid()) |
| 558 return; | 548 return; |
| 559 | 549 |
| 560 for (FaviconMap::const_iterator i = favicon_map.begin(); | 550 for (FaviconMap::const_iterator i = favicon_map.begin(); |
| 561 i != favicon_map.end(); ++i) { | 551 i != favicon_map.end(); ++i) { |
| 562 s.BindInt64(0, i->first); | 552 s.BindInt64(0, i->first); |
| 563 if (s.Step()) { | 553 if (s.Step()) { |
| 564 history::ImportedFaviconUsage usage; | 554 history::ImportedFaviconUsage usage; |
| 565 | 555 |
| 566 usage.favicon_url = GURL(s.ColumnString(0)); | 556 usage.favicon_url = GURL(s.ColumnString(0)); |
| 567 if (!usage.favicon_url.is_valid()) | 557 if (!usage.favicon_url.is_valid()) |
| 568 continue; // Don't bother importing favicons with invalid URLs. | 558 continue; // Don't bother importing favicons with invalid URLs. |
| 569 | 559 |
| 570 std::vector<unsigned char> data; | 560 std::vector<unsigned char> data; |
| 571 s.ColumnBlobAsVector(1, &data); | 561 s.ColumnBlobAsVector(1, &data); |
| 572 if (data.empty()) | 562 if (data.empty()) |
| 573 continue; // Data definitely invalid. | 563 continue; // Data definitely invalid. |
| 574 | 564 |
| 575 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) | 565 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) |
| 576 continue; // Unable to decode. | 566 continue; // Unable to decode. |
| 577 | 567 |
| 578 usage.urls = i->second; | 568 usage.urls = i->second; |
| 579 favicons->push_back(usage); | 569 favicons->push_back(usage); |
| 580 } | 570 } |
| 581 s.Reset(); | 571 s.Reset(); |
| 582 } | 572 } |
| 583 } | 573 } |
| OLD | NEW |