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

Side by Side Diff: chrome/browser/first_run/first_run_win.cc

Issue 9702103: Clean up first run: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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
OLDNEW
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/first_run/first_run.h" 5 #include "chrome/browser/first_run/first_run.h"
6 6
7 #include <shlobj.h> 7 #include <shlobj.h>
8 #include <windows.h> 8 #include <windows.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 } 334 }
335 335
336 HWND owner_window_; 336 HWND owner_window_;
337 base::ProcessHandle import_process_; 337 base::ProcessHandle import_process_;
338 WorkerThreadTicker ticker_; 338 WorkerThreadTicker ticker_;
339 DISALLOW_COPY_AND_ASSIGN(HungImporterMonitor); 339 DISALLOW_COPY_AND_ASSIGN(HungImporterMonitor);
340 }; 340 };
341 341
342 std::string EncodeImportParams(int importer_type, 342 std::string EncodeImportParams(int importer_type,
343 int options, 343 int options,
344 int skip_first_run_ui, 344 bool skip_first_run_ui) {
345 HWND window) { 345 return base::StringPrintf("%d@%d@%d", importer_type, options,
346 return base::StringPrintf( 346 skip_first_run_ui ? 1 : 0);
347 "%d@%d@%d@%d", importer_type, options, skip_first_run_ui, window);
348 } 347 }
349 348
350 bool DecodeImportParams(const std::string& encoded, 349 bool DecodeImportParams(const std::string& encoded,
351 int* importer_type, 350 int* importer_type,
352 int* options, 351 int* options,
353 int* skip_first_run_ui, 352 bool* skip_first_run_ui) {
354 HWND* window) {
355 std::vector<std::string> parts; 353 std::vector<std::string> parts;
356 base::SplitString(encoded, '@', &parts); 354 base::SplitString(encoded, '@', &parts);
357 if (parts.size() != 4) 355 int skip_first_run_ui_int;
356 if ((parts.size() != 3) || !base::StringToInt(parts[0], importer_type) ||
357 !base::StringToInt(parts[1], options) ||
358 !base::StringToInt(parts[2], &skip_first_run_ui_int))
358 return false; 359 return false;
359 360 *skip_first_run_ui = !!skip_first_run_ui_int;
360 if (!base::StringToInt(parts[0], importer_type))
361 return false;
362
363 if (!base::StringToInt(parts[1], options))
364 return false;
365
366 if (!base::StringToInt(parts[2], skip_first_run_ui))
367 return false;
368
369 int64 window_int;
370 base::StringToInt64(parts[3], &window_int);
371 *window = reinterpret_cast<HWND>(window_int);
372 return true; 361 return true;
373 } 362 }
374 363
375 #if !defined(USE_AURA) 364 #if !defined(USE_AURA)
376 // Imports browser items in this process. The browser and the items to 365 // Imports browser items in this process. The browser and the items to
377 // import are encoded in the command line. 366 // import are encoded in the command line.
378 int ImportFromBrowser(Profile* profile, 367 int ImportFromBrowser(Profile* profile,
379 const CommandLine& cmdline) { 368 const CommandLine& cmdline) {
380 std::string import_info = cmdline.GetSwitchValueASCII(switches::kImport); 369 std::string import_info = cmdline.GetSwitchValueASCII(switches::kImport);
381 if (import_info.empty()) { 370 if (import_info.empty()) {
382 NOTREACHED(); 371 NOTREACHED();
383 return false; 372 return false;
384 } 373 }
385 int importer_type = 0; 374 int importer_type = 0;
386 int items_to_import = 0; 375 int items_to_import = 0;
387 int skip_first_run_ui = 0; 376 bool skip_first_run_ui = false;
388 HWND parent_window = NULL;
389 if (!DecodeImportParams(import_info, &importer_type, &items_to_import, 377 if (!DecodeImportParams(import_info, &importer_type, &items_to_import,
390 &skip_first_run_ui, &parent_window)) { 378 &skip_first_run_ui)) {
391 NOTREACHED(); 379 NOTREACHED();
392 return false; 380 return false;
393 } 381 }
394 scoped_refptr<ImporterHost> importer_host(new ImporterHost); 382 scoped_refptr<ImporterHost> importer_host(new ImporterHost);
395 FirstRunImportObserver importer_observer; 383 FirstRunImportObserver importer_observer;
396 384
397 scoped_refptr<ImporterList> importer_list(new ImporterList(NULL)); 385 scoped_refptr<ImporterList> importer_list(new ImporterList(NULL));
398 importer_list->DetectSourceProfilesHack(); 386 importer_list->DetectSourceProfilesHack();
399 387
400 // If |skip_first_run_ui|, we run in headless mode. This means that if 388 // If |skip_first_run_ui|, we run in headless mode. This means that if
401 // there is user action required the import is automatically canceled. 389 // there is user action required the import is automatically canceled.
402 if (skip_first_run_ui > 0) 390 if (skip_first_run_ui)
403 importer_host->set_headless(); 391 importer_host->set_headless();
404 392
405 importer::ShowImportProgressDialog( 393 importer::ShowImportProgressDialog(static_cast<uint16>(items_to_import),
406 parent_window, 394 importer_host, &importer_observer,
407 static_cast<uint16>(items_to_import), 395 importer_list->GetSourceProfileForImporterType(importer_type), profile,
408 importer_host,
409 &importer_observer,
410 importer_list->GetSourceProfileForImporterType(importer_type),
411 profile,
412 true); 396 true);
413 importer_observer.RunLoop(); 397 importer_observer.RunLoop();
414 return importer_observer.import_result(); 398 return importer_observer.import_result();
415 } 399 }
416 #endif // !defined(USE_AURA) 400 #endif // !defined(USE_AURA)
417 401
418 bool ImportSettingsWin(Profile* profile, 402 bool ImportSettingsWin(Profile* profile,
419 int importer_type, 403 int importer_type,
420 int items_to_import, 404 int items_to_import,
421 const FilePath& import_bookmarks_path, 405 const FilePath& import_bookmarks_path,
422 bool skip_first_run_ui) { 406 bool skip_first_run_ui) {
423 const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); 407 const CommandLine& cmdline = *CommandLine::ForCurrentProcess();
424 CommandLine import_cmd(cmdline.GetProgram()); 408 CommandLine import_cmd(cmdline.GetProgram());
425 409
426 const char* kSwitchNames[] = { 410 const char* kSwitchNames[] = {
427 switches::kUserDataDir, 411 switches::kUserDataDir,
428 switches::kChromeFrame, 412 switches::kChromeFrame,
429 switches::kCountry, 413 switches::kCountry,
430 }; 414 };
431 import_cmd.CopySwitchesFrom(cmdline, kSwitchNames, arraysize(kSwitchNames)); 415 import_cmd.CopySwitchesFrom(cmdline, kSwitchNames, arraysize(kSwitchNames));
432 416
433 // Since ImportSettings is called before the local state is stored on disk 417 // Since ImportSettings is called before the local state is stored on disk
434 // we pass the language as an argument. GetApplicationLocale checks the 418 // we pass the language as an argument. GetApplicationLocale checks the
435 // current command line as fallback. 419 // current command line as fallback.
436 import_cmd.AppendSwitchASCII(switches::kLang, 420 import_cmd.AppendSwitchASCII(switches::kLang,
437 g_browser_process->GetApplicationLocale()); 421 g_browser_process->GetApplicationLocale());
438 422
439 if (items_to_import) { 423 if (items_to_import) {
440 import_cmd.CommandLine::AppendSwitchASCII(switches::kImport, 424 import_cmd.AppendSwitchASCII(switches::kImport,
441 EncodeImportParams(importer_type, items_to_import, 425 EncodeImportParams(importer_type, items_to_import, skip_first_run_ui));
442 skip_first_run_ui ? 1 : 0, NULL));
443 } 426 }
444 427
445 if (!import_bookmarks_path.empty()) { 428 if (!import_bookmarks_path.empty()) {
446 import_cmd.CommandLine::AppendSwitchPath( 429 import_cmd.AppendSwitchPath(switches::kImportFromFile,
447 switches::kImportFromFile, import_bookmarks_path); 430 import_bookmarks_path);
448 } 431 }
449 432
433 // The importer doesn't need to do any background networking tasks so disable
434 // them.
435 import_cmd.CommandLine::AppendSwitch(switches::kDisableBackgroundNetworking);
436
450 // Time to launch the process that is going to do the import. 437 // Time to launch the process that is going to do the import.
451 base::ProcessHandle import_process; 438 base::ProcessHandle import_process;
452 if (!base::LaunchProcess(import_cmd, base::LaunchOptions(), &import_process)) 439 if (!base::LaunchProcess(import_cmd, base::LaunchOptions(), &import_process))
453 return false; 440 return false;
454 441
455 // We block inside the import_runner ctor, pumping messages until the 442 // We block inside the import_runner ctor, pumping messages until the
456 // importer process ends. This can happen either by completing the import 443 // importer process ends. This can happen either by completing the import
457 // or by hang_monitor killing it. 444 // or by hang_monitor killing it.
458 ImportProcessRunner import_runner(import_process); 445 ImportProcessRunner import_runner(import_process);
459 446
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 } 510 }
524 511
525 if (out_prefs->do_import_items || !import_bookmarks_path.empty()) { 512 if (out_prefs->do_import_items || !import_bookmarks_path.empty()) {
526 // There is something to import from the default browser. This launches 513 // There is something to import from the default browser. This launches
527 // the importer process and blocks until done or until it fails. 514 // the importer process and blocks until done or until it fails.
528 scoped_refptr<ImporterList> importer_list(new ImporterList(NULL)); 515 scoped_refptr<ImporterList> importer_list(new ImporterList(NULL));
529 importer_list->DetectSourceProfilesHack(); 516 importer_list->DetectSourceProfilesHack();
530 if (!ImportSettingsWin(NULL, 517 if (!ImportSettingsWin(NULL,
531 importer_list->GetSourceProfileAt(0).importer_type, 518 importer_list->GetSourceProfileAt(0).importer_type,
532 out_prefs->do_import_items, 519 out_prefs->do_import_items,
533 FilePath::FromWStringHack(UTF8ToWide(import_bookmarks_path)), 520 FilePath::FromWStringHack(UTF8ToWide(import_bookmarks_path)), true)) {
534 true)) {
535 LOG(WARNING) << "silent import failed"; 521 LOG(WARNING) << "silent import failed";
536 } 522 }
537 } 523 }
538 } 524 }
539 525
540 } // namespace internal 526 } // namespace internal
541 } // namespace first_run 527 } // namespace first_run
542 528
543 namespace first_run { 529 namespace first_run {
544 530
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 return false; 608 return false;
623 609
624 internal::SetShowWelcomePagePrefIfNeeded(install_prefs.get()); 610 internal::SetShowWelcomePagePrefIfNeeded(install_prefs.get());
625 internal::SetImportPreferencesAndLaunchImport(out_prefs, install_prefs.get()); 611 internal::SetImportPreferencesAndLaunchImport(out_prefs, install_prefs.get());
626 internal::SetDefaultBrowser(install_prefs.get()); 612 internal::SetDefaultBrowser(install_prefs.get());
627 613
628 return false; 614 return false;
629 } 615 }
630 616
631 } // namespace first_run 617 } // namespace first_run
OLDNEW
« no previous file with comments | « chrome/browser/first_run/first_run_linux.cc ('k') | chrome/browser/importer/importer_progress_dialog.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698