| 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/first_run/first_run.h" | 5 #include "chrome/browser/first_run/first_run.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/environment.h" | 12 #include "base/environment.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 17 #include "base/process_util.h" | 17 #include "base/process_util.h" |
| 18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
| 19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
| 21 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
| 22 #include "base/time.h" | 22 #include "base/time.h" |
| 23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 24 #include "base/win/metro.h" | 24 #include "base/win/metro.h" |
| 25 #include "base/win/object_watcher.h" | 25 #include "base/win/object_watcher.h" |
| 26 #include "base/win/windows_version.h" | 26 #include "base/win/windows_version.h" |
| 27 #include "chrome/browser/browser_process.h" | 27 #include "chrome/browser/browser_process.h" |
| 28 #include "chrome/browser/first_run/first_run_import_observer.h" | |
| 29 #include "chrome/browser/first_run/first_run_internal.h" | 28 #include "chrome/browser/first_run/first_run_internal.h" |
| 30 #include "chrome/browser/importer/importer_host.h" | 29 #include "chrome/browser/importer/importer_host.h" |
| 31 #include "chrome/browser/importer/importer_list.h" | 30 #include "chrome/browser/importer/importer_list.h" |
| 32 #include "chrome/browser/importer/importer_progress_dialog.h" | |
| 33 #include "chrome/browser/process_singleton.h" | 31 #include "chrome/browser/process_singleton.h" |
| 34 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
| 35 #include "chrome/browser/shell_integration.h" | 33 #include "chrome/browser/shell_integration.h" |
| 36 #include "chrome/common/chrome_constants.h" | 34 #include "chrome/common/chrome_constants.h" |
| 37 #include "chrome/common/chrome_paths.h" | 35 #include "chrome/common/chrome_paths.h" |
| 38 #include "chrome/common/chrome_result_codes.h" | 36 #include "chrome/common/chrome_result_codes.h" |
| 39 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
| 40 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
| 41 #include "chrome/common/worker_thread_ticker.h" | 39 #include "chrome/common/worker_thread_ticker.h" |
| 42 #include "chrome/installer/util/browser_distribution.h" | 40 #include "chrome/installer/util/browser_distribution.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 !base::StringToInt(parts[1], options) || | 274 !base::StringToInt(parts[1], options) || |
| 277 !base::StringToInt(parts[2], &skip_first_run_ui_int)) | 275 !base::StringToInt(parts[2], &skip_first_run_ui_int)) |
| 278 return false; | 276 return false; |
| 279 *skip_first_run_ui = !!skip_first_run_ui_int; | 277 *skip_first_run_ui = !!skip_first_run_ui_int; |
| 280 return true; | 278 return true; |
| 281 } | 279 } |
| 282 | 280 |
| 283 #if !defined(USE_AURA) | 281 #if !defined(USE_AURA) |
| 284 // Imports browser items in this process. The browser and the items to | 282 // Imports browser items in this process. The browser and the items to |
| 285 // import are encoded in the command line. | 283 // import are encoded in the command line. |
| 286 int ImportFromBrowser(Profile* profile, | 284 bool ImportFromBrowser(Profile* profile, |
| 287 const CommandLine& cmdline) { | 285 const CommandLine& cmdline) { |
| 288 std::string import_info = cmdline.GetSwitchValueASCII(switches::kImport); | 286 std::string import_info = cmdline.GetSwitchValueASCII(switches::kImport); |
| 289 if (import_info.empty()) { | 287 if (import_info.empty()) { |
| 290 NOTREACHED(); | 288 NOTREACHED(); |
| 291 return false; | 289 return false; |
| 292 } | 290 } |
| 293 int importer_type = 0; | 291 int importer_type = 0; |
| 294 int items_to_import = 0; | 292 int items_to_import = 0; |
| 295 bool skip_first_run_ui = false; | 293 bool skip_first_run_ui = false; |
| 296 if (!DecodeImportParams(import_info, &importer_type, &items_to_import, | 294 if (!DecodeImportParams(import_info, &importer_type, &items_to_import, |
| 297 &skip_first_run_ui)) { | 295 &skip_first_run_ui)) { |
| 298 NOTREACHED(); | 296 NOTREACHED(); |
| 299 return false; | 297 return false; |
| 300 } | 298 } |
| 301 scoped_refptr<ImporterHost> importer_host(new ImporterHost); | 299 scoped_refptr<ImporterHost> importer_host(new ImporterHost); |
| 302 FirstRunImportObserver importer_observer; | |
| 303 | 300 |
| 304 scoped_refptr<ImporterList> importer_list(new ImporterList(NULL)); | 301 scoped_refptr<ImporterList> importer_list(new ImporterList(NULL)); |
| 305 importer_list->DetectSourceProfilesHack(); | 302 importer_list->DetectSourceProfilesHack(); |
| 306 | 303 |
| 307 // If |skip_first_run_ui|, we run in headless mode. This means that if | 304 // If |skip_first_run_ui|, we run in headless mode. This means that if |
| 308 // there is user action required the import is automatically canceled. | 305 // there is user action required the import is automatically canceled. |
| 309 if (skip_first_run_ui) | 306 if (skip_first_run_ui) |
| 310 importer_host->set_headless(); | 307 importer_host->set_headless(); |
| 311 | 308 |
| 312 importer::ShowImportProgressDialog(static_cast<uint16>(items_to_import), | 309 scoped_ptr<first_run::internal::ImportEndedObserver> observer( |
| 313 importer_host, &importer_observer, | 310 new first_run::internal::ImportEndedObserver); |
| 311 importer_host->SetObserver(observer.get()); |
| 312 importer_host->StartImportSettings( |
| 314 importer_list->GetSourceProfileForImporterType(importer_type), profile, | 313 importer_list->GetSourceProfileForImporterType(importer_type), profile, |
| 315 true); | 314 static_cast<uint16>(items_to_import), new ProfileWriter(profile), true); |
| 316 importer_observer.RunLoop(); | 315 // If the import process has not errored out, block on it. |
| 317 return importer_observer.import_result(); | 316 if (!observer->ended()) { |
| 317 observer->set_should_quit_message_loop(); |
| 318 MessageLoop::current()->Run(); |
| 319 } |
| 320 // TODO(gab): This method will be go away as part of http://crbug.com/219419/, |
| 321 // so it is fine to hardcode |true| here for now. |
| 322 return true; |
| 318 } | 323 } |
| 319 #endif // !defined(USE_AURA) | 324 #endif // !defined(USE_AURA) |
| 320 | 325 |
| 321 bool ImportSettingsWin(Profile* profile, | 326 bool ImportSettingsWin(Profile* profile, |
| 322 int importer_type, | 327 int importer_type, |
| 323 int items_to_import, | 328 int items_to_import, |
| 324 const base::FilePath& import_bookmarks_path, | 329 const base::FilePath& import_bookmarks_path, |
| 325 bool skip_first_run_ui) { | 330 bool skip_first_run_ui) { |
| 326 if (!items_to_import && import_bookmarks_path.empty()) { | 331 if (!items_to_import && import_bookmarks_path.empty()) { |
| 327 return true; | 332 return true; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 | 515 |
| 511 base::FilePath MasterPrefsPath() { | 516 base::FilePath MasterPrefsPath() { |
| 512 // The standard location of the master prefs is next to the chrome binary. | 517 // The standard location of the master prefs is next to the chrome binary. |
| 513 base::FilePath master_prefs; | 518 base::FilePath master_prefs; |
| 514 if (!PathService::Get(base::DIR_EXE, &master_prefs)) | 519 if (!PathService::Get(base::DIR_EXE, &master_prefs)) |
| 515 return base::FilePath(); | 520 return base::FilePath(); |
| 516 return master_prefs.AppendASCII(installer::kDefaultMasterPrefs); | 521 return master_prefs.AppendASCII(installer::kDefaultMasterPrefs); |
| 517 } | 522 } |
| 518 | 523 |
| 519 } // namespace first_run | 524 } // namespace first_run |
| OLD | NEW |