| 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 "base/message_loop.h" | |
| 8 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 9 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 10 #include "base/utf_string_conversions.h" | |
| 11 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/first_run/first_run_internal.h" | 10 #include "chrome/browser/first_run/first_run_internal.h" |
| 13 #include "chrome/browser/importer/importer_host.h" | |
| 14 #include "chrome/browser/importer/importer_list.h" | |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
| 17 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
| 18 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/installer/util/google_update_settings.h" | 15 #include "chrome/installer/util/google_update_settings.h" |
| 20 #include "chrome/installer/util/master_preferences.h" | 16 #include "chrome/installer/util/master_preferences.h" |
| 21 #include "chrome/installer/util/master_preferences_constants.h" | |
| 22 | 17 |
| 23 namespace first_run { | 18 namespace first_run { |
| 24 namespace internal { | 19 namespace internal { |
| 25 | 20 |
| 26 void DoPostImportPlatformSpecificTasks() { | 21 void DoPostImportPlatformSpecificTasks() { |
| 27 #if !defined(OS_CHROMEOS) | 22 #if !defined(OS_CHROMEOS) |
| 28 // If stats reporting was turned on by the first run dialog then toggle | 23 // If stats reporting was turned on by the first run dialog then toggle |
| 29 // the pref (on Windows, the download is tagged with enable/disable stats so | 24 // the pref (on Windows, the download is tagged with enable/disable stats so |
| 30 // this is POSIX-specific). | 25 // this is POSIX-specific). |
| 31 if (GoogleUpdateSettings::GetCollectStatsConsent()) { | 26 if (GoogleUpdateSettings::GetCollectStatsConsent()) { |
| 32 g_browser_process->local_state()->SetBoolean( | 27 g_browser_process->local_state()->SetBoolean( |
| 33 prefs::kMetricsReportingEnabled, true); | 28 prefs::kMetricsReportingEnabled, true); |
| 34 } | 29 } |
| 35 #endif | 30 #endif |
| 36 } | 31 } |
| 37 | 32 |
| 38 bool GetFirstRunSentinelFilePath(base::FilePath* path) { | 33 bool GetFirstRunSentinelFilePath(base::FilePath* path) { |
| 39 base::FilePath first_run_sentinel; | 34 base::FilePath first_run_sentinel; |
| 40 | 35 |
| 41 if (!PathService::Get(chrome::DIR_USER_DATA, &first_run_sentinel)) | 36 if (!PathService::Get(chrome::DIR_USER_DATA, &first_run_sentinel)) |
| 42 return false; | 37 return false; |
| 43 | 38 |
| 44 *path = first_run_sentinel.Append(chrome::kFirstRunSentinel); | 39 *path = first_run_sentinel.Append(chrome::kFirstRunSentinel); |
| 45 return true; | 40 return true; |
| 46 } | 41 } |
| 47 | 42 |
| 48 bool ImportSettings(Profile* profile, | |
| 49 scoped_refptr<ImporterHost> importer_host, | |
| 50 scoped_refptr<ImporterList> importer_list, | |
| 51 int items_to_import) { | |
| 52 const importer::SourceProfile& source_profile = | |
| 53 importer_list->GetSourceProfileAt(0); | |
| 54 | |
| 55 // Ensure that importers aren't requested to import items that they do not | |
| 56 // support. If there is no overlap, skip. | |
| 57 items_to_import &= source_profile.services_supported; | |
| 58 if (items_to_import == 0) | |
| 59 return true; | |
| 60 | |
| 61 ImportEndedObserver observer; | |
| 62 importer_host->SetObserver(&observer); | |
| 63 importer_host->StartImportSettings(source_profile, | |
| 64 profile, | |
| 65 items_to_import, | |
| 66 new ProfileWriter(profile)); | |
| 67 // If the import process has not errored out, block on it. | |
| 68 if (!observer.ended()) { | |
| 69 observer.set_should_quit_message_loop(); | |
| 70 MessageLoop::current()->Run(); | |
| 71 } | |
| 72 | |
| 73 // Unfortunately there's no success/fail signal in ImporterHost. | |
| 74 return true; | |
| 75 } | |
| 76 | |
| 77 void SetImportPreferencesAndLaunchImport( | |
| 78 MasterPrefs* out_prefs, | |
| 79 installer::MasterPreferences* install_prefs) { | |
| 80 std::string import_bookmarks_path; | |
| 81 install_prefs->GetString( | |
| 82 installer::master_preferences::kDistroImportBookmarksFromFilePref, | |
| 83 &import_bookmarks_path); | |
| 84 if (!import_bookmarks_path.empty()) { | |
| 85 // There are bookmarks to import from a file. | |
| 86 base::FilePath path = base::FilePath::FromWStringHack(UTF8ToWide( | |
| 87 import_bookmarks_path)); | |
| 88 if (!ImportBookmarks(path)) { | |
| 89 LOG(WARNING) << "silent bookmark import failed"; | |
| 90 } | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 bool ShowPostInstallEULAIfNeeded(installer::MasterPreferences* install_prefs) { | 43 bool ShowPostInstallEULAIfNeeded(installer::MasterPreferences* install_prefs) { |
| 95 // The EULA is only handled on Windows. | 44 // The EULA is only handled on Windows. |
| 96 return true; | 45 return true; |
| 97 } | 46 } |
| 98 | 47 |
| 99 } // namespace internal | 48 } // namespace internal |
| 100 } // namespace first_run | 49 } // namespace first_run |
| 101 | |
| 102 namespace first_run { | |
| 103 | |
| 104 // TODO(port): Import switches need to be ported to both Mac and Linux. Not all | |
| 105 // import switches here are implemented for Linux. None are implemented for Mac | |
| 106 // (as this function will not be called on Mac). | |
| 107 int ImportNow(Profile* profile, const CommandLine& cmdline) { | |
| 108 return internal::ImportBookmarkFromFileIfNeeded(profile, cmdline); | |
| 109 } | |
| 110 | |
| 111 } // namespace first_run | |
| OLD | NEW |