| 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/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" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/history/history_types.h" | 16 #include "chrome/browser/history/history_types.h" |
| 17 #include "chrome/browser/importer/firefox2_importer.h" | 17 #include "chrome/browser/importer/bookmarks_file_importer.h" |
| 18 #include "chrome/browser/importer/firefox_importer_utils.h" | 18 #include "chrome/browser/importer/firefox_importer_utils.h" |
| 19 #include "chrome/browser/importer/importer_bridge.h" | 19 #include "chrome/browser/importer/importer_bridge.h" |
| 20 #include "chrome/browser/importer/importer_util.h" | 20 #include "chrome/browser/importer/importer_util.h" |
| 21 #include "chrome/browser/importer/nss_decryptor.h" | 21 #include "chrome/browser/importer/nss_decryptor.h" |
| 22 #include "chrome/browser/search_engines/template_url.h" | 22 #include "chrome/browser/search_engines/template_url.h" |
| 23 #include "chrome/common/time_format.h" | 23 #include "chrome/common/time_format.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/common/password_form.h" | 25 #include "content/public/common/password_form.h" |
| 26 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
| 27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 52 | 52 |
| 53 TemplateURLData data; | 53 TemplateURLData data; |
| 54 // We set short name by using the title if it exists. | 54 // We set short name by using the title if it exists. |
| 55 // Otherwise, we use the shortcut. | 55 // Otherwise, we use the shortcut. |
| 56 data.short_name = title.empty() ? keyword : title; | 56 data.short_name = title.empty() ? keyword : title; |
| 57 data.SetKeyword(keyword); | 57 data.SetKeyword(keyword); |
| 58 data.SetURL(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url.spec()))); | 58 data.SetURL(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url.spec()))); |
| 59 return new TemplateURL(NULL, data); | 59 return new TemplateURL(NULL, data); |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Loads the default bookmarks in the Firefox installed at |app_path|, |
| 63 // and stores their locations in |urls|. |
| 64 void LoadDefaultBookmarks(const base::FilePath& app_path, |
| 65 std::set<GURL>* urls) { |
| 66 base::FilePath file = app_path.AppendASCII("defaults") |
| 67 .AppendASCII("profile") |
| 68 .AppendASCII("bookmarks.html"); |
| 69 urls->clear(); |
| 70 |
| 71 std::vector<ProfileWriter::BookmarkEntry> bookmarks; |
| 72 BookmarksFileImporter::ImportBookmarksFile(file, NULL, &bookmarks, NULL); |
| 73 for (size_t i = 0; i < bookmarks.size(); ++i) |
| 74 urls->insert(bookmarks[i].url); |
| 75 } |
| 76 |
| 62 } // namespace | 77 } // namespace |
| 63 | 78 |
| 64 struct Firefox3Importer::BookmarkItem { | 79 struct Firefox3Importer::BookmarkItem { |
| 65 int parent; | 80 int parent; |
| 66 int id; | 81 int id; |
| 67 GURL url; | 82 GURL url; |
| 68 string16 title; | 83 string16 title; |
| 69 BookmarkItemType type; | 84 BookmarkItemType type; |
| 70 std::string keyword; | 85 std::string keyword; |
| 71 base::Time date_added; | 86 base::Time date_added; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 // Get the bookmark folders that we are interested in. | 197 // Get the bookmark folders that we are interested in. |
| 183 int toolbar_folder_id = -1; | 198 int toolbar_folder_id = -1; |
| 184 int menu_folder_id = -1; | 199 int menu_folder_id = -1; |
| 185 int unsorted_folder_id = -1; | 200 int unsorted_folder_id = -1; |
| 186 LoadRootNodeID(&db, &toolbar_folder_id, &menu_folder_id, &unsorted_folder_id); | 201 LoadRootNodeID(&db, &toolbar_folder_id, &menu_folder_id, &unsorted_folder_id); |
| 187 | 202 |
| 188 // Load livemark IDs. | 203 // Load livemark IDs. |
| 189 std::set<int> livemark_id; | 204 std::set<int> livemark_id; |
| 190 LoadLivemarkIDs(&db, &livemark_id); | 205 LoadLivemarkIDs(&db, &livemark_id); |
| 191 | 206 |
| 192 // Load the default bookmarks. Its storage is the same as Firefox 2. | 207 // Load the default bookmarks. |
| 193 std::set<GURL> default_urls; | 208 std::set<GURL> default_urls; |
| 194 Firefox2Importer::LoadDefaultBookmarks(app_path_, &default_urls); | 209 LoadDefaultBookmarks(app_path_, &default_urls); |
| 195 | 210 |
| 196 BookmarkList list; | 211 BookmarkList list; |
| 197 GetTopBookmarkFolder(&db, toolbar_folder_id, &list); | 212 GetTopBookmarkFolder(&db, toolbar_folder_id, &list); |
| 198 GetTopBookmarkFolder(&db, menu_folder_id, &list); | 213 GetTopBookmarkFolder(&db, menu_folder_id, &list); |
| 199 GetTopBookmarkFolder(&db, unsorted_folder_id, &list); | 214 GetTopBookmarkFolder(&db, unsorted_folder_id, &list); |
| 200 size_t count = list.size(); | 215 size_t count = list.size(); |
| 201 for (size_t i = 0; i < count; ++i) | 216 for (size_t i = 0; i < count; ++i) |
| 202 GetWholeBookmarkFolder(&db, &list, i, NULL); | 217 GetWholeBookmarkFolder(&db, &list, i, NULL); |
| 203 | 218 |
| 204 std::vector<ProfileWriter::BookmarkEntry> bookmarks; | 219 std::vector<ProfileWriter::BookmarkEntry> bookmarks; |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 | 595 |
| 581 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) | 596 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) |
| 582 continue; // Unable to decode. | 597 continue; // Unable to decode. |
| 583 | 598 |
| 584 usage.urls = i->second; | 599 usage.urls = i->second; |
| 585 favicons->push_back(usage); | 600 favicons->push_back(usage); |
| 586 } | 601 } |
| 587 s.Reset(true); | 602 s.Reset(true); |
| 588 } | 603 } |
| 589 } | 604 } |
| OLD | NEW |