Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/utility/importer/firefox_importer.h" | 5 #include "chrome/utility/importer/firefox_importer.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 // Loads the default bookmarks in the Firefox installed at |app_path|, | 44 // Loads the default bookmarks in the Firefox installed at |app_path|, |
| 45 // and stores their locations in |urls|. | 45 // and stores their locations in |urls|. |
| 46 void LoadDefaultBookmarks(const base::FilePath& app_path, | 46 void LoadDefaultBookmarks(const base::FilePath& app_path, |
| 47 std::set<GURL>* urls) { | 47 std::set<GURL>* urls) { |
| 48 base::FilePath file = app_path.AppendASCII("defaults") | 48 base::FilePath file = app_path.AppendASCII("defaults") |
| 49 .AppendASCII("profile") | 49 .AppendASCII("profile") |
| 50 .AppendASCII("bookmarks.html"); | 50 .AppendASCII("bookmarks.html"); |
| 51 urls->clear(); | 51 urls->clear(); |
| 52 | 52 |
| 53 std::vector<ImportedBookmarkEntry> bookmarks; | 53 std::vector<ImportedBookmarkEntry> bookmarks; |
| 54 std::vector<importer::URLKeywordInfo> url_keywords; | |
| 54 bookmark_html_reader::ImportBookmarksFile(base::Callback<bool(void)>(), | 55 bookmark_html_reader::ImportBookmarksFile(base::Callback<bool(void)>(), |
| 55 base::Callback<bool(const GURL&)>(), | 56 base::Callback<bool(const GURL&)>(), |
| 56 file, | 57 file, |
| 57 &bookmarks, | 58 &bookmarks, |
| 59 &url_keywords, | |
| 58 NULL); | 60 NULL); |
| 59 for (size_t i = 0; i < bookmarks.size(); ++i) | 61 for (size_t i = 0; i < bookmarks.size(); ++i) |
| 60 urls->insert(bookmarks[i].url); | 62 urls->insert(bookmarks[i].url); |
| 61 } | 63 } |
| 62 | 64 |
| 63 // Returns true if |url| has a valid scheme that we allow to import. We | 65 // Returns true if |url| has a valid scheme that we allow to import. We |
| 64 // filter out the URL with a unsupported scheme. | 66 // filter out the URL with a unsupported scheme. |
| 65 bool CanImportURL(const GURL& url) { | 67 bool CanImportURL(const GURL& url) { |
| 66 // The URL is not valid. | 68 // The URL is not valid. |
| 67 if (!url.is_valid()) | 69 if (!url.is_valid()) |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 | 247 |
| 246 for (size_t i = 0; i < list.size(); ++i) { | 248 for (size_t i = 0; i < list.size(); ++i) { |
| 247 BookmarkItem* item = list[i]; | 249 BookmarkItem* item = list[i]; |
| 248 | 250 |
| 249 if (item->type == TYPE_FOLDER) { | 251 if (item->type == TYPE_FOLDER) { |
| 250 // Folders are added implicitly on adding children, so we only explicitly | 252 // Folders are added implicitly on adding children, so we only explicitly |
| 251 // add empty folders. | 253 // add empty folders. |
| 252 if (!item->empty_folder) | 254 if (!item->empty_folder) |
| 253 continue; | 255 continue; |
| 254 } else if (item->type == TYPE_BOOKMARK) { | 256 } else if (item->type == TYPE_BOOKMARK) { |
| 255 // Import only valid bookmarks | 257 // Import only valid bookmarks. |
| 256 if (!CanImportURL(item->url)) | 258 if (!CanImportURL(item->url)) { |
| 259 base::string16 decoded_url; | |
| 260 // Import invalid bookmark's keyword as search engine. | |
|
Peter Kasting
2014/10/01 01:02:55
How is the functionality from this file different
Tapu Ghose
2014/10/07 02:02:45
I agree.
| |
| 261 if (!item->keyword.empty() && | |
| 262 bookmark_html_reader::CanImportURLAsSearchEngine(item->url, | |
| 263 &decoded_url)) { | |
| 264 importer::URLKeywordInfo url_keyword_info; | |
| 265 // Since |item->url| is invalid, set raw_url property of | |
| 266 // |url_keyword_info| which will be used in importing as search | |
| 267 // engine. | |
| 268 url_keyword_info.raw_url = decoded_url; | |
| 269 url_keyword_info.keyword.assign(base::UTF8ToUTF16(item->keyword)); | |
| 270 url_keyword_info.display_name = item->title; | |
| 271 url_keywords.push_back(url_keyword_info); | |
| 272 } | |
|
Ilya Sherman
2014/09/30 20:54:13
Please add test coverage for these changes
Tapu Ghose
2014/10/07 02:02:45
Added a new bookmark entry into places.sql files p
Ilya Sherman
2014/10/07 22:08:22
Let's get this CL fully sorted out, with all tests
Tapu Ghose
2014/10/12 00:58:19
Tests passing for me locally.
| |
| 257 continue; | 273 continue; |
| 274 } | |
| 258 } else { | 275 } else { |
| 259 continue; | 276 continue; |
| 260 } | 277 } |
| 261 | 278 |
| 262 // Skip the default bookmarks and unwanted URLs. | 279 // Skip the default bookmarks and unwanted URLs. |
| 263 if (default_urls.find(item->url) != default_urls.end() || | 280 if (default_urls.find(item->url) != default_urls.end() || |
| 264 post_keyword_ids.find(item->id) != post_keyword_ids.end()) | 281 post_keyword_ids.find(item->id) != post_keyword_ids.end()) |
| 265 continue; | 282 continue; |
| 266 | 283 |
| 267 // Find the bookmark path by tracing their links to parent folders. | 284 // Find the bookmark path by tracing their links to parent folders. |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 766 | 783 |
| 767 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) | 784 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) |
| 768 continue; // Unable to decode. | 785 continue; // Unable to decode. |
| 769 | 786 |
| 770 usage.urls = i->second; | 787 usage.urls = i->second; |
| 771 favicons->push_back(usage); | 788 favicons->push_back(usage); |
| 772 } | 789 } |
| 773 s.Reset(true); | 790 s.Reset(true); |
| 774 } | 791 } |
| 775 } | 792 } |
| OLD | NEW |