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

Side by Side Diff: chrome/utility/importer/firefox_importer.cc

Issue 616763002: Importing certain bookmarks from firefox and HTML file as search engines. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 6 years, 2 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
OLDNEW
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
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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 241
240 if (!s.is_valid()) 242 if (!s.is_valid())
241 return; 243 return;
242 244
243 while (s.Step() && !cancelled()) 245 while (s.Step() && !cancelled())
244 post_keyword_ids.insert(s.ColumnInt(0)); 246 post_keyword_ids.insert(s.ColumnInt(0));
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) {
Peter Kasting 2014/10/07 23:17:39 Nit: Slightly shorter: if (item->type != TYPE_BOO
Tapu Ghose 2014/10/12 00:58:21 Done.
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 importer::URLKeywordInfo search_engine_info;
260 // Import invalid bookmark's keyword as search engine.
Peter Kasting 2014/10/07 23:17:39 This comment sounds unconditional, which isn't tru
Tapu Ghose 2014/10/12 00:58:21 Acknowledged.
261 if (!item->keyword.empty() &&
262 bookmark_html_reader::CanImportURLAsSearchEngine(item->url,
263 base::UTF8ToUTF16(item->keyword),
264 item->title,
265 &search_engine_info)) {
266 url_keywords.push_back(search_engine_info);
267 }
257 continue; 268 continue;
269 }
258 } else { 270 } else {
259 continue; 271 continue;
260 } 272 }
261 273
262 // Skip the default bookmarks and unwanted URLs. 274 // Skip the default bookmarks and unwanted URLs.
263 if (default_urls.find(item->url) != default_urls.end() || 275 if (default_urls.find(item->url) != default_urls.end() ||
264 post_keyword_ids.find(item->id) != post_keyword_ids.end()) 276 post_keyword_ids.find(item->id) != post_keyword_ids.end())
265 continue; 277 continue;
266 278
267 // Find the bookmark path by tracing their links to parent folders. 279 // Find the bookmark path by tracing their links to parent folders.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 321
310 bookmarks.push_back(entry); 322 bookmarks.push_back(entry);
311 323
312 if (item->type == TYPE_BOOKMARK) { 324 if (item->type == TYPE_BOOKMARK) {
313 if (item->favicon) 325 if (item->favicon)
314 favicon_map[item->favicon].insert(item->url); 326 favicon_map[item->favicon].insert(item->url);
315 327
316 // This bookmark has a keyword, we should import it. 328 // This bookmark has a keyword, we should import it.
317 if (!item->keyword.empty() && item->url.is_valid()) { 329 if (!item->keyword.empty() && item->url.is_valid()) {
318 importer::URLKeywordInfo url_keyword_info; 330 importer::URLKeywordInfo url_keyword_info;
319 url_keyword_info.url = item->url; 331 url_keyword_info.raw_url.assign(base::UTF8ToUTF16(item->url.spec()));
320 url_keyword_info.keyword.assign(base::UTF8ToUTF16(item->keyword)); 332 url_keyword_info.keyword.assign(base::UTF8ToUTF16(item->keyword));
321 url_keyword_info.display_name = item->title; 333 url_keyword_info.display_name = item->title;
322 url_keywords.push_back(url_keyword_info); 334 url_keywords.push_back(url_keyword_info);
323 } 335 }
324 } 336 }
325 } 337 }
326 338
327 STLDeleteElements(&list); 339 STLDeleteElements(&list);
328 340
329 // Write into profile. 341 // Write into profile.
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 778
767 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) 779 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data))
768 continue; // Unable to decode. 780 continue; // Unable to decode.
769 781
770 usage.urls = i->second; 782 usage.urls = i->second;
771 favicons->push_back(usage); 783 favicons->push_back(usage);
772 } 784 }
773 s.Reset(true); 785 s.Reset(true);
774 } 786 }
775 } 787 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698