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

Side by Side Diff: chrome/browser/importer/firefox3_importer.cc

Issue 115895: Ensure that Firefox search engines are imported correctly.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/importer/firefox3_importer.h" 5 #include "chrome/browser/importer/firefox3_importer.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 file_util::AppendToPath(&file, L"search.sqlite"); 318 file_util::AppendToPath(&file, L"search.sqlite");
319 if (!file_util::PathExists(file)) 319 if (!file_util::PathExists(file))
320 return; 320 return;
321 321
322 sqlite3* sqlite; 322 sqlite3* sqlite;
323 if (sqlite3_open(WideToUTF8(file).c_str(), &sqlite) != SQLITE_OK) 323 if (sqlite3_open(WideToUTF8(file).c_str(), &sqlite) != SQLITE_OK)
324 return; 324 return;
325 scoped_ptr_malloc<sqlite3, DBClose> db(sqlite); 325 scoped_ptr_malloc<sqlite3, DBClose> db(sqlite);
326 326
327 SQLStatement s; 327 SQLStatement s;
328 const char* stmt = "SELECT engineid FROM engine_data ORDER BY value ASC"; 328 const char* stmt = "SELECT engineid FROM engine_data "
329 "WHERE engineid NOT IN "
330 "(SELECT engineid FROM engine_data "
331 "WHERE name='hidden') "
332 "ORDER BY value ASC";
329 333
330 if (s.prepare(db.get(), stmt) != SQLITE_OK) 334 if (s.prepare(db.get(), stmt) != SQLITE_OK)
331 return; 335 return;
332 336
333 std::wstring app_path = app_path_; 337 std::wstring app_path = app_path_;
334 file_util::AppendToPath(&app_path, L"searchplugins"); 338 file_util::AppendToPath(&app_path, L"searchplugins");
335 std::wstring profile_path = source_path_; 339 std::wstring profile_path = source_path_;
336 file_util::AppendToPath(&profile_path, L"searchplugins"); 340 file_util::AppendToPath(&profile_path, L"searchplugins");
337 341
338 const std::wstring kAppPrefix = L"[app]/"; 342 // Firefox doesn't store any search engines in its sqlite database unless
339 const std::wstring kProfilePrefix = L"[profile]/"; 343 // the user has changed the standard set of engines. If we find that the
340 while (s.step() == SQLITE_ROW && !cancelled()) { 344 // database is empty, get the standard Firefox set from the app folder.
341 std::wstring file; 345 if (s.step() != SQLITE_ROW) {
342 std::wstring engine = UTF8ToWide(s.column_string(0)); 346 file_util::FileEnumerator engines(FilePath::FromWStringHack(app_path),
343 // The string contains [app]/<name>.xml or [profile]/<name>.xml where the 347 false,
344 // [app] and [profile] need to be replaced with the actual app or profile 348 file_util::FileEnumerator::FILES);
345 // path. 349 for (FilePath engine_path = engines.Next(); !engine_path.value().empty();
346 size_t index = engine.find(kAppPrefix); 350 engine_path = engines.Next()) {
347 if (index != std::wstring::npos) { 351 std::wstring enginew = engine_path.ToWStringHack();
348 file = app_path; 352 files->push_back(enginew);
349 file_util::AppendToPath(
350 &file,
351 engine.substr(index + kAppPrefix.length())); // Remove '[app]/'.
352 } else if ((index = engine.find(kProfilePrefix)) != std::wstring::npos) {
353 file = profile_path;
354 file_util::AppendToPath(
355 &file,
356 engine.substr(index + kProfilePrefix.length())); // Remove
357 // '[profile]/'.
358 } else {
359 NOTREACHED() << "Unexpected Firefox 3 search engine id";
360 continue;
361 } 353 }
362 files->push_back(file); 354 } else {
355 const std::wstring kAppPrefix = L"[app]/";
356 const std::wstring kProfilePrefix = L"[profile]/";
357 do {
358 std::wstring file;
359 std::wstring engine = UTF8ToWide(s.column_string(0));
360
361 // The string contains [app]/<name>.xml or [profile]/<name>.xml where
362 // the [app] and [profile] need to be replaced with the actual app or
363 // profile path.
364 size_t index = engine.find(kAppPrefix);
365 if (index != std::wstring::npos) {
366 // Remove '[app]/'.
367 file = app_path;
368 file_util::AppendToPath(
369 &file,
370 engine.substr(index + kAppPrefix.length()));
371 } else if ((index = engine.find(kProfilePrefix)) !=
372 std::wstring::npos) {
373 // Remove '[profile]/'.
374 file = profile_path;
375 file_util::AppendToPath(
376 &file,
377 engine.substr(index + kProfilePrefix.length()));
378 } else {
379 NOTREACHED() << "Unexpected Firefox 3 search engine id";
380 continue;
381 }
382 files->push_back(file);
383 } while (s.step() == SQLITE_ROW && !cancelled());
363 } 384 }
364 } 385 }
365 386
366 void Firefox3Importer::LoadRootNodeID(sqlite3* db, 387 void Firefox3Importer::LoadRootNodeID(sqlite3* db,
367 int* toolbar_folder_id, 388 int* toolbar_folder_id,
368 int* menu_folder_id, 389 int* menu_folder_id,
369 int* unsorted_folder_id) { 390 int* unsorted_folder_id) {
370 const char kToolbarFolderName[] = "toolbar"; 391 const char kToolbarFolderName[] = "toolbar";
371 const char kMenuFolderName[] = "menu"; 392 const char kMenuFolderName[] = "menu";
372 const char kUnsortedFolderName[] = "unfiled"; 393 const char kUnsortedFolderName[] = "unfiled";
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 518
498 if (!ReencodeFavicon(&data[0], data.size(), &usage.png_data)) 519 if (!ReencodeFavicon(&data[0], data.size(), &usage.png_data))
499 continue; // Unable to decode. 520 continue; // Unable to decode.
500 521
501 usage.urls = i->second; 522 usage.urls = i->second;
502 favicons->push_back(usage); 523 favicons->push_back(usage);
503 } 524 }
504 s.reset(); 525 s.reset();
505 } 526 }
506 } 527 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698