| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.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/stringprintf.h" | 17 #include "base/stringprintf.h" |
| 18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
| 22 #include "chrome/browser/extensions/updater/extension_updater.h" | 22 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 23 #include "chrome/browser/first_run/first_run_internal.h" | 23 #include "chrome/browser/first_run/first_run_internal.h" |
| 24 #include "chrome/browser/google/google_util.h" | 24 #include "chrome/browser/google/google_util.h" |
| 25 #include "chrome/browser/importer/external_process_importer_host.h" | 25 #include "chrome/browser/importer/external_process_importer_host.h" |
| 26 #include "chrome/browser/importer/importer_host.h" | 26 #include "chrome/browser/importer/importer_host.h" |
| 27 #include "chrome/browser/importer/importer_list.h" | 27 #include "chrome/browser/importer/importer_list.h" |
| 28 #include "chrome/browser/importer/importer_progress_observer.h" | 28 #include "chrome/browser/importer/importer_progress_observer.h" |
| 29 #include "chrome/browser/importer/importer_type.h" | 29 #include "chrome/browser/importer/importer_type.h" |
| 30 #include "chrome/browser/importer/profile_writer.h" | |
| 31 #include "chrome/browser/profiles/profile_manager.h" | 30 #include "chrome/browser/profiles/profile_manager.h" |
| 32 #include "chrome/browser/search_engines/template_url_service.h" | 31 #include "chrome/browser/search_engines/template_url_service.h" |
| 33 #include "chrome/browser/search_engines/template_url_service_factory.h" | 32 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 34 #include "chrome/browser/shell_integration.h" | 33 #include "chrome/browser/shell_integration.h" |
| 35 #include "chrome/browser/signin/signin_manager.h" | 34 #include "chrome/browser/signin/signin_manager.h" |
| 36 #include "chrome/browser/signin/signin_manager_factory.h" | 35 #include "chrome/browser/signin/signin_manager_factory.h" |
| 37 #include "chrome/browser/signin/signin_tracker.h" | 36 #include "chrome/browser/signin/signin_tracker.h" |
| 38 #include "chrome/browser/ui/browser.h" | 37 #include "chrome/browser/ui/browser.h" |
| 39 #include "chrome/browser/ui/browser_finder.h" | 38 #include "chrome/browser/ui/browser_finder.h" |
| 40 #include "chrome/browser/ui/global_error/global_error_service.h" | 39 #include "chrome/browser/ui/global_error/global_error_service.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 55 #include "content/public/browser/notification_types.h" | 54 #include "content/public/browser/notification_types.h" |
| 56 #include "content/public/browser/user_metrics.h" | 55 #include "content/public/browser/user_metrics.h" |
| 57 #include "content/public/browser/web_contents.h" | 56 #include "content/public/browser/web_contents.h" |
| 58 #include "google_apis/gaia/gaia_auth_util.h" | 57 #include "google_apis/gaia/gaia_auth_util.h" |
| 59 #include "googleurl/src/gurl.h" | 58 #include "googleurl/src/gurl.h" |
| 60 | 59 |
| 61 using content::UserMetricsAction; | 60 using content::UserMetricsAction; |
| 62 | 61 |
| 63 namespace { | 62 namespace { |
| 64 | 63 |
| 65 // A bitfield formed from values in AutoImportState to record the state of | |
| 66 // AutoImport. This is used in testing to verify import startup actions that | |
| 67 // occur before an observer can be registered in the test. | |
| 68 uint16 g_auto_import_state = first_run::AUTO_IMPORT_NONE; | |
| 69 | |
| 70 // Flags for functions of similar name. | 64 // Flags for functions of similar name. |
| 71 bool g_should_show_welcome_page = false; | 65 bool g_should_show_welcome_page = false; |
| 72 bool g_should_do_autofill_personal_data_manager_first_run = false; | 66 bool g_should_do_autofill_personal_data_manager_first_run = false; |
| 73 | 67 |
| 74 // This class acts as an observer for the ImporterProgressObserver::ImportEnded | 68 // Flags indicating whether a first-run profile auto import was performed, and |
| 75 // callback. When the import process is started, certain errors may cause | 69 // whether the importer process exited successfully. |
| 76 // ImportEnded() to be called synchronously, but the typical case is that | 70 bool did_perform_profile_import = false; |
| 77 // ImportEnded() is called asynchronously. Thus we have to handle both cases. | 71 bool profile_import_exited_successfully = false; |
| 78 class ImportEndedObserver : public importer::ImporterProgressObserver { | |
| 79 public: | |
| 80 ImportEndedObserver() : ended_(false), | |
| 81 should_quit_message_loop_(false) {} | |
| 82 virtual ~ImportEndedObserver() {} | |
| 83 | |
| 84 // importer::ImporterProgressObserver: | |
| 85 virtual void ImportStarted() OVERRIDE {} | |
| 86 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} | |
| 87 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} | |
| 88 virtual void ImportEnded() OVERRIDE { | |
| 89 ended_ = true; | |
| 90 if (should_quit_message_loop_) | |
| 91 MessageLoop::current()->Quit(); | |
| 92 } | |
| 93 | |
| 94 void set_should_quit_message_loop() { | |
| 95 should_quit_message_loop_ = true; | |
| 96 } | |
| 97 | |
| 98 bool ended() const { | |
| 99 return ended_; | |
| 100 } | |
| 101 | |
| 102 private: | |
| 103 // Set if the import has ended. | |
| 104 bool ended_; | |
| 105 | |
| 106 bool should_quit_message_loop_; | |
| 107 }; | |
| 108 | 72 |
| 109 // Helper class that performs delayed first-run tasks that need more of the | 73 // Helper class that performs delayed first-run tasks that need more of the |
| 110 // chrome infrastructure to be up and running before they can be attempted. | 74 // chrome infrastructure to be up and running before they can be attempted. |
| 111 class FirstRunDelayedTasks : public content::NotificationObserver { | 75 class FirstRunDelayedTasks : public content::NotificationObserver { |
| 112 public: | 76 public: |
| 113 enum Tasks { | 77 enum Tasks { |
| 114 NO_TASK, | 78 NO_TASK, |
| 115 INSTALL_EXTENSIONS | 79 INSTALL_EXTENSIONS |
| 116 }; | 80 }; |
| 117 | 81 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 if (user_prefs->GetBoolean(pref_path)) | 184 if (user_prefs->GetBoolean(pref_path)) |
| 221 *items |= import_type; | 185 *items |= import_type; |
| 222 } else { // no policy (recommended or managed) is set | 186 } else { // no policy (recommended or managed) is set |
| 223 if (should_import) | 187 if (should_import) |
| 224 *items |= import_type; | 188 *items |= import_type; |
| 225 } | 189 } |
| 226 | 190 |
| 227 user_prefs->ClearPref(pref_path); | 191 user_prefs->ClearPref(pref_path); |
| 228 } | 192 } |
| 229 | 193 |
| 230 // Launches the import, via |importer_host|, from |source_profile| into | 194 // Imports bookmarks from an html file. The path to the file is provided in |
| 231 // |target_profile| for the items specified in the |items_to_import| bitfield. | 195 // the command line. |
| 232 // This may be done in a separate process depending on the platform, but it will | 196 void ImportFromFile(Profile* profile, const CommandLine& cmdline) { |
| 233 // always block until done. | 197 base::FilePath file_path = |
| 234 void ImportFromSourceProfile(ImporterHost* importer_host, | 198 cmdline.GetSwitchValuePath(switches::kImportFromFile); |
| 235 const importer::SourceProfile& source_profile, | 199 if (file_path.empty()) { |
| 236 Profile* target_profile, | 200 NOTREACHED(); |
| 237 uint16 items_to_import) { | 201 return; |
| 238 ImportEndedObserver observer; | 202 } |
| 203 |
| 204 // Deletes itself. |
| 205 ImporterHost* importer_host = new ImporterHost; |
| 206 importer_host->set_headless(); |
| 207 |
| 208 importer::SourceProfile source_profile; |
| 209 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; |
| 210 source_profile.source_path = file_path; |
| 211 |
| 212 first_run::internal::ImportEndedObserver observer; |
| 239 importer_host->SetObserver(&observer); | 213 importer_host->SetObserver(&observer); |
| 240 importer_host->StartImportSettings(source_profile, | 214 importer_host->StartImportSettings( |
| 241 target_profile, | 215 source_profile, profile, importer::FAVORITES, new ProfileWriter(profile)); |
| 242 items_to_import, | |
| 243 new ProfileWriter(target_profile)); | |
| 244 // If the import process has not errored out, block on it. | 216 // If the import process has not errored out, block on it. |
| 245 if (!observer.ended()) { | 217 if (!observer.ended()) { |
| 246 observer.set_should_quit_message_loop(); | 218 observer.set_should_quit_message_loop(); |
| 247 MessageLoop::current()->Run(); | 219 MessageLoop::current()->Run(); |
| 248 } | 220 } |
| 249 } | 221 } |
| 250 | 222 |
| 251 // Imports bookmarks from an html file whose path is provided by | |
| 252 // |import_bookmarks_path|. | |
| 253 void ImportFromFile(Profile* profile, | |
| 254 ImporterHost* file_importer_host, | |
| 255 const std::string& import_bookmarks_path) { | |
| 256 importer::SourceProfile source_profile; | |
| 257 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; | |
| 258 | |
| 259 const base::FilePath::StringType& import_bookmarks_path_str = | |
| 260 #if defined(OS_WIN) | |
| 261 UTF8ToUTF16(import_bookmarks_path); | |
| 262 #else | |
| 263 import_bookmarks_path; | |
| 264 #endif | |
| 265 source_profile.source_path = base::FilePath(import_bookmarks_path_str); | |
| 266 | |
| 267 ImportFromSourceProfile(file_importer_host, source_profile, profile, | |
| 268 importer::FAVORITES); | |
| 269 g_auto_import_state |= first_run::AUTO_IMPORT_BOOKMARKS_FILE_IMPORTED; | |
| 270 } | |
| 271 | |
| 272 // Imports settings from the first profile in |importer_list|. | |
| 273 void ImportSettings(Profile* profile, | |
| 274 ImporterHost* importer_host, | |
| 275 scoped_refptr<ImporterList> importer_list, | |
| 276 int items_to_import) { | |
| 277 const importer::SourceProfile& source_profile = | |
| 278 importer_list->GetSourceProfileAt(0); | |
| 279 | |
| 280 // Ensure that importers aren't requested to import items that they do not | |
| 281 // support. If there is no overlap, skip. | |
| 282 items_to_import &= source_profile.services_supported; | |
| 283 if (items_to_import == 0) | |
| 284 return; | |
| 285 | |
| 286 ImportFromSourceProfile(importer_host, source_profile, profile, | |
| 287 items_to_import); | |
| 288 g_auto_import_state |= first_run::AUTO_IMPORT_PROFILE_IMPORTED; | |
| 289 } | |
| 290 | |
| 291 GURL UrlFromString(const std::string& in) { | 223 GURL UrlFromString(const std::string& in) { |
| 292 return GURL(in); | 224 return GURL(in); |
| 293 } | 225 } |
| 294 | 226 |
| 295 void ConvertStringVectorToGURLVector( | 227 void ConvertStringVectorToGURLVector( |
| 296 const std::vector<std::string>& src, | 228 const std::vector<std::string>& src, |
| 297 std::vector<GURL>* ret) { | 229 std::vector<GURL>* ret) { |
| 298 ret->resize(src.size()); | 230 ret->resize(src.size()); |
| 299 std::transform(src.begin(), src.end(), ret->begin(), &UrlFromString); | 231 std::transform(src.begin(), src.end(), ret->begin(), &UrlFromString); |
| 300 } | 232 } |
| 301 | 233 |
| 302 } // namespace | 234 } // namespace |
| 303 | 235 |
| 304 namespace first_run { | 236 namespace first_run { |
| 305 namespace internal { | 237 namespace internal { |
| 306 | 238 |
| 307 FirstRunState first_run_ = FIRST_RUN_UNKNOWN; | 239 FirstRunState first_run_ = FIRST_RUN_UNKNOWN; |
| 308 | 240 |
| 309 static base::LazyInstance<base::FilePath> master_prefs_path_for_testing | 241 static base::LazyInstance<base::FilePath> master_prefs_path_for_testing |
| 310 = LAZY_INSTANCE_INITIALIZER; | 242 = LAZY_INSTANCE_INITIALIZER; |
| 311 | 243 |
| 244 // TODO(gab): This will go back inline above when it is moved to first_run.cc |
| 245 // (see TODO above), but needs to be separate for now to satisfy clang error: |
| 246 // "[chromium-style] virtual methods with non-empty bodies shouldn't be declared |
| 247 // inline". |
| 248 void ImportEndedObserver::ImportEnded() { |
| 249 ended_ = true; |
| 250 if (should_quit_message_loop_) |
| 251 MessageLoop::current()->Quit(); |
| 252 } |
| 253 |
| 312 installer::MasterPreferences* | 254 installer::MasterPreferences* |
| 313 LoadMasterPrefs(base::FilePath* master_prefs_path) { | 255 LoadMasterPrefs(base::FilePath* master_prefs_path) { |
| 314 if (!master_prefs_path_for_testing.Get().empty()) | 256 if (!master_prefs_path_for_testing.Get().empty()) |
| 315 *master_prefs_path = master_prefs_path_for_testing.Get(); | 257 *master_prefs_path = master_prefs_path_for_testing.Get(); |
| 316 else | 258 else |
| 317 *master_prefs_path = base::FilePath(MasterPrefsPath()); | 259 *master_prefs_path = base::FilePath(MasterPrefsPath()); |
| 318 if (master_prefs_path->empty()) | 260 if (master_prefs_path->empty()) |
| 319 return NULL; | 261 return NULL; |
| 320 installer::MasterPreferences* install_prefs = | 262 installer::MasterPreferences* install_prefs = |
| 321 new installer::MasterPreferences(*master_prefs_path); | 263 new installer::MasterPreferences(*master_prefs_path); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 &value) && value) { | 347 &value) && value) { |
| 406 out_prefs->make_chrome_default = true; | 348 out_prefs->make_chrome_default = true; |
| 407 } | 349 } |
| 408 | 350 |
| 409 if (install_prefs.GetBool( | 351 if (install_prefs.GetBool( |
| 410 installer::master_preferences::kSuppressFirstRunDefaultBrowserPrompt, | 352 installer::master_preferences::kSuppressFirstRunDefaultBrowserPrompt, |
| 411 &value) && value) { | 353 &value) && value) { |
| 412 out_prefs->suppress_first_run_default_browser_prompt = true; | 354 out_prefs->suppress_first_run_default_browser_prompt = true; |
| 413 } | 355 } |
| 414 | 356 |
| 415 install_prefs.GetString( | |
| 416 installer::master_preferences::kDistroImportBookmarksFromFilePref, | |
| 417 &out_prefs->import_bookmarks_path); | |
| 418 | |
| 419 out_prefs->variations_seed = install_prefs.GetVariationsSeed(); | 357 out_prefs->variations_seed = install_prefs.GetVariationsSeed(); |
| 420 | 358 |
| 421 install_prefs.GetString( | 359 install_prefs.GetString( |
| 422 installer::master_preferences::kDistroSuppressDefaultBrowserPromptPref, | 360 installer::master_preferences::kDistroSuppressDefaultBrowserPromptPref, |
| 423 &out_prefs->suppress_default_browser_prompt_for_version); | 361 &out_prefs->suppress_default_browser_prompt_for_version); |
| 424 } | 362 } |
| 425 | 363 |
| 426 void SetDefaultBrowser(installer::MasterPreferences* install_prefs){ | 364 void SetDefaultBrowser(installer::MasterPreferences* install_prefs){ |
| 427 // Even on the first run we only allow for the user choice to take effect if | 365 // Even on the first run we only allow for the user choice to take effect if |
| 428 // no policy has been set by the admin. | 366 // no policy has been set by the admin. |
| 429 if (!g_browser_process->local_state()->IsManagedPreference( | 367 if (!g_browser_process->local_state()->IsManagedPreference( |
| 430 prefs::kDefaultBrowserSettingEnabled)) { | 368 prefs::kDefaultBrowserSettingEnabled)) { |
| 431 bool value = false; | 369 bool value = false; |
| 432 if (install_prefs->GetBool( | 370 if (install_prefs->GetBool( |
| 433 installer::master_preferences::kMakeChromeDefaultForUser, | 371 installer::master_preferences::kMakeChromeDefaultForUser, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 445 // -- Platform-specific functions -- | 383 // -- Platform-specific functions -- |
| 446 | 384 |
| 447 #if !defined(OS_LINUX) && !defined(OS_BSD) | 385 #if !defined(OS_LINUX) && !defined(OS_BSD) |
| 448 bool IsOrganicFirstRun() { | 386 bool IsOrganicFirstRun() { |
| 449 std::string brand; | 387 std::string brand; |
| 450 google_util::GetBrand(&brand); | 388 google_util::GetBrand(&brand); |
| 451 return google_util::IsOrganicFirstRun(brand); | 389 return google_util::IsOrganicFirstRun(brand); |
| 452 } | 390 } |
| 453 #endif | 391 #endif |
| 454 | 392 |
| 393 int ImportBookmarkFromFileIfNeeded(Profile* profile, |
| 394 const CommandLine& cmdline) { |
| 395 if (cmdline.HasSwitch(switches::kImportFromFile)) { |
| 396 // Silently import preset bookmarks from file. |
| 397 // This is an OEM scenario. |
| 398 ImportFromFile(profile, cmdline); |
| 399 } |
| 400 // ImportBookmarkFromFileIfNeeded() will go away as part of |
| 401 // http://crbug.com/219419, so it is fine to hardcode |true| for now. |
| 402 return true; |
| 403 } |
| 404 |
| 455 } // namespace internal | 405 } // namespace internal |
| 456 } // namespace first_run | 406 } // namespace first_run |
| 457 | 407 |
| 458 namespace first_run { | 408 namespace first_run { |
| 459 | 409 |
| 460 MasterPrefs::MasterPrefs() | 410 MasterPrefs::MasterPrefs() |
| 461 : ping_delay(0), | 411 : ping_delay(0), |
| 462 homepage_defined(false), | 412 homepage_defined(false), |
| 463 do_import_items(0), | 413 do_import_items(0), |
| 464 dont_import_items(0), | 414 dont_import_items(0), |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 bool retval = g_should_do_autofill_personal_data_manager_first_run; | 491 bool retval = g_should_do_autofill_personal_data_manager_first_run; |
| 542 g_should_do_autofill_personal_data_manager_first_run = false; | 492 g_should_do_autofill_personal_data_manager_first_run = false; |
| 543 return retval; | 493 return retval; |
| 544 } | 494 } |
| 545 | 495 |
| 546 void LogFirstRunMetric(FirstRunBubbleMetric metric) { | 496 void LogFirstRunMetric(FirstRunBubbleMetric metric) { |
| 547 UMA_HISTOGRAM_ENUMERATION("FirstRun.SearchEngineBubble", metric, | 497 UMA_HISTOGRAM_ENUMERATION("FirstRun.SearchEngineBubble", metric, |
| 548 NUM_FIRST_RUN_BUBBLE_METRICS); | 498 NUM_FIRST_RUN_BUBBLE_METRICS); |
| 549 } | 499 } |
| 550 | 500 |
| 501 namespace { |
| 502 CommandLine* GetExtraArgumentsInstance() { |
| 503 CR_DEFINE_STATIC_LOCAL(CommandLine, arguments, (CommandLine::NoProgram())); |
| 504 return &arguments; |
| 505 } |
| 506 } // namespace |
| 507 |
| 508 void SetExtraArgumentsForImportProcess(const CommandLine& arguments) { |
| 509 GetExtraArgumentsInstance()->AppendArguments(arguments, false); |
| 510 } |
| 511 |
| 512 const CommandLine& GetExtraArgumentsForImportProcess() { |
| 513 return *GetExtraArgumentsInstance(); |
| 514 } |
| 515 |
| 551 // static | 516 // static |
| 552 void FirstRunBubbleLauncher::ShowFirstRunBubbleSoon() { | 517 void FirstRunBubbleLauncher::ShowFirstRunBubbleSoon() { |
| 553 SetShowFirstRunBubblePref(FIRST_RUN_BUBBLE_SHOW); | 518 SetShowFirstRunBubblePref(FIRST_RUN_BUBBLE_SHOW); |
| 554 // This FirstRunBubbleLauncher instance will manage its own lifetime. | 519 // This FirstRunBubbleLauncher instance will manage its own lifetime. |
| 555 new FirstRunBubbleLauncher(); | 520 new FirstRunBubbleLauncher(); |
| 556 } | 521 } |
| 557 | 522 |
| 558 FirstRunBubbleLauncher::FirstRunBubbleLauncher() { | 523 FirstRunBubbleLauncher::FirstRunBubbleLauncher() { |
| 559 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 524 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 560 content::NotificationService::AllSources()); | 525 content::NotificationService::AllSources()); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 if (!internal::ShowPostInstallEULAIfNeeded(install_prefs.get())) | 627 if (!internal::ShowPostInstallEULAIfNeeded(install_prefs.get())) |
| 663 return EULA_EXIT_NOW; | 628 return EULA_EXIT_NOW; |
| 664 | 629 |
| 665 if (!internal::CopyPrefFile(user_data_dir, master_prefs_path)) | 630 if (!internal::CopyPrefFile(user_data_dir, master_prefs_path)) |
| 666 DLOG(ERROR) << "Failed to copy master_preferences to user data dir."; | 631 DLOG(ERROR) << "Failed to copy master_preferences to user data dir."; |
| 667 | 632 |
| 668 DoDelayedInstallExtensionsIfNeeded(install_prefs.get()); | 633 DoDelayedInstallExtensionsIfNeeded(install_prefs.get()); |
| 669 | 634 |
| 670 internal::SetupMasterPrefsFromInstallPrefs(*install_prefs, out_prefs); | 635 internal::SetupMasterPrefsFromInstallPrefs(*install_prefs, out_prefs); |
| 671 | 636 |
| 637 internal::SetImportPreferencesAndLaunchImport(out_prefs, |
| 638 install_prefs.get()); |
| 639 |
| 672 internal::SetDefaultBrowser(install_prefs.get()); | 640 internal::SetDefaultBrowser(install_prefs.get()); |
| 673 } | 641 } |
| 674 | 642 |
| 675 return DO_FIRST_RUN_TASKS; | 643 return DO_FIRST_RUN_TASKS; |
| 676 } | 644 } |
| 677 | 645 |
| 678 void AutoImport( | 646 void AutoImport( |
| 679 Profile* profile, | 647 Profile* profile, |
| 680 bool homepage_defined, | 648 bool homepage_defined, |
| 681 int import_items, | 649 int import_items, |
| 682 int dont_import_items, | 650 int dont_import_items) { |
| 683 const std::string& import_bookmarks_path) { | |
| 684 #if !defined(USE_AURA) | 651 #if !defined(USE_AURA) |
| 685 // Deletes itself. | 652 // Deletes itself. |
| 686 ImporterHost* importer_host; | 653 ImporterHost* importer_host; |
| 687 // TODO(csilv,mirandac): Out-of-process import has only been qualified on | 654 // TODO(csilv,mirandac): Out-of-process import has only been qualified on |
| 688 // MacOS X and Windows, so we will only use it on those platforms. | 655 // MacOS X, so we will only use it on that platform since it is required. |
| 689 // Linux still uses the in-process import (http://crbug.com/56816). | 656 // Remove this conditional logic once oop import is qualified for |
| 690 #if defined(OS_MACOSX) || defined(OS_WIN) | 657 // Linux/Windows. http://crbug.com/22142 |
| 658 #if defined(OS_MACOSX) |
| 691 importer_host = new ExternalProcessImporterHost; | 659 importer_host = new ExternalProcessImporterHost; |
| 692 #else | 660 #else |
| 693 importer_host = new ImporterHost; | 661 importer_host = new ImporterHost; |
| 694 #endif | 662 #endif |
| 695 | 663 |
| 696 base::FilePath local_state_path; | 664 base::FilePath local_state_path; |
| 697 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); | 665 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); |
| 698 bool local_state_file_exists = file_util::PathExists(local_state_path); | 666 bool local_state_file_exists = file_util::PathExists(local_state_path); |
| 699 | 667 |
| 700 scoped_refptr<ImporterList> importer_list(new ImporterList(NULL)); | 668 scoped_refptr<ImporterList> importer_list(new ImporterList(NULL)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 SetImportItem(user_prefs, | 714 SetImportItem(user_prefs, |
| 747 prefs::kImportBookmarks, | 715 prefs::kImportBookmarks, |
| 748 import_items, | 716 import_items, |
| 749 dont_import_items, | 717 dont_import_items, |
| 750 importer::FAVORITES, | 718 importer::FAVORITES, |
| 751 &items); | 719 &items); |
| 752 | 720 |
| 753 importer::LogImporterUseToMetrics( | 721 importer::LogImporterUseToMetrics( |
| 754 "AutoImport", importer_list->GetSourceProfileAt(0).importer_type); | 722 "AutoImport", importer_list->GetSourceProfileAt(0).importer_type); |
| 755 | 723 |
| 756 ImportSettings(profile, importer_host, importer_list, items); | 724 profile_import_exited_successfully = |
| 757 } | 725 internal::ImportSettings(profile, importer_host, importer_list, items); |
| 758 | 726 DCHECK(profile_import_exited_successfully); |
| 759 if (!import_bookmarks_path.empty()) { | |
| 760 // Deletes itself. | |
| 761 ImporterHost* file_importer_host; | |
| 762 // TODO(gab): Make Linux use OOP import as well (http://crbug.com/56816) and | |
| 763 // get rid of these ugly ifdefs. | |
| 764 #if defined(OS_MACOSX) || defined(OS_WIN) | |
| 765 file_importer_host = new ExternalProcessImporterHost; | |
| 766 #else | |
| 767 file_importer_host = new ImporterHost; | |
| 768 #endif | |
| 769 file_importer_host->set_headless(); | |
| 770 | |
| 771 ImportFromFile(profile, file_importer_host, import_bookmarks_path); | |
| 772 } | 727 } |
| 773 | 728 |
| 774 content::RecordAction(UserMetricsAction("FirstRunDef_Accept")); | 729 content::RecordAction(UserMetricsAction("FirstRunDef_Accept")); |
| 775 | 730 |
| 776 #endif // !defined(USE_AURA) | 731 #endif // !defined(USE_AURA) |
| 777 g_auto_import_state |= AUTO_IMPORT_CALLED; | 732 did_perform_profile_import = true; |
| 778 } | 733 } |
| 779 | 734 |
| 780 void DoPostImportTasks(Profile* profile, bool make_chrome_default) { | 735 void DoPostImportTasks(Profile* profile, bool make_chrome_default) { |
| 781 if (make_chrome_default && | 736 if (make_chrome_default && |
| 782 ShellIntegration::CanSetAsDefaultBrowser() == | 737 ShellIntegration::CanSetAsDefaultBrowser() == |
| 783 ShellIntegration::SET_DEFAULT_UNATTENDED) { | 738 ShellIntegration::SET_DEFAULT_UNATTENDED) { |
| 784 ShellIntegration::SetAsDefaultBrowser(); | 739 ShellIntegration::SetAsDefaultBrowser(); |
| 785 } | 740 } |
| 786 | 741 |
| 787 // Display the first run bubble if there is a default search provider. | 742 // Display the first run bubble if there is a default search provider. |
| 788 TemplateURLService* template_url = | 743 TemplateURLService* template_url = |
| 789 TemplateURLServiceFactory::GetForProfile(profile); | 744 TemplateURLServiceFactory::GetForProfile(profile); |
| 790 if (template_url && template_url->GetDefaultSearchProvider()) | 745 if (template_url && template_url->GetDefaultSearchProvider()) |
| 791 FirstRunBubbleLauncher::ShowFirstRunBubbleSoon(); | 746 FirstRunBubbleLauncher::ShowFirstRunBubbleSoon(); |
| 792 SetShouldShowWelcomePage(); | 747 SetShouldShowWelcomePage(); |
| 793 SetShouldDoPersonalDataManagerFirstRun(); | 748 SetShouldDoPersonalDataManagerFirstRun(); |
| 794 | 749 |
| 795 internal::DoPostImportPlatformSpecificTasks(profile); | 750 internal::DoPostImportPlatformSpecificTasks(profile); |
| 796 } | 751 } |
| 797 | 752 |
| 798 uint16 auto_import_state() { | 753 bool DidPerformProfileImport(bool* exited_successfully) { |
| 799 return g_auto_import_state; | 754 if (exited_successfully) |
| 755 *exited_successfully = profile_import_exited_successfully; |
| 756 return did_perform_profile_import; |
| 800 } | 757 } |
| 801 | 758 |
| 802 } // namespace first_run | 759 } // namespace first_run |
| OLD | NEW |