| 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/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/first_run/first_run_internal.h" | 11 #include "chrome/browser/first_run/first_run_internal.h" |
| 12 #include "chrome/browser/importer/importer_host.h" | |
| 13 #include "chrome/browser/importer/importer_list.h" | |
| 14 #include "chrome/browser/importer/importer_progress_dialog.h" | |
| 15 #include "chrome/browser/importer/importer_progress_observer.h" | |
| 16 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 17 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
| 18 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/installer/util/google_update_settings.h" | 16 #include "chrome/installer/util/google_update_settings.h" |
| 21 #include "chrome/installer/util/master_preferences.h" | 17 #include "chrome/installer/util/master_preferences.h" |
| 22 #include "chrome/installer/util/master_preferences_constants.h" | 18 #include "chrome/installer/util/master_preferences_constants.h" |
| 23 | 19 |
| 24 namespace { | |
| 25 | |
| 26 // This class acts as an observer for the ImporterProgressObserver::ImportEnded | |
| 27 // callback. When the import process is started, certain errors may cause | |
| 28 // ImportEnded() to be called synchronously, but the typical case is that | |
| 29 // ImportEnded() is called asynchronously. Thus we have to handle both cases. | |
| 30 class ImportEndedObserver : public importer::ImporterProgressObserver { | |
| 31 public: | |
| 32 ImportEndedObserver() : ended_(false), | |
| 33 should_quit_message_loop_(false) {} | |
| 34 virtual ~ImportEndedObserver() {} | |
| 35 | |
| 36 // importer::ImporterProgressObserver: | |
| 37 virtual void ImportStarted() OVERRIDE {} | |
| 38 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} | |
| 39 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} | |
| 40 virtual void ImportEnded() OVERRIDE { | |
| 41 ended_ = true; | |
| 42 if (should_quit_message_loop_) | |
| 43 MessageLoop::current()->Quit(); | |
| 44 } | |
| 45 | |
| 46 void set_should_quit_message_loop() { | |
| 47 should_quit_message_loop_ = true; | |
| 48 } | |
| 49 | |
| 50 bool ended() { | |
| 51 return ended_; | |
| 52 } | |
| 53 | |
| 54 private: | |
| 55 // Set if the import has ended. | |
| 56 bool ended_; | |
| 57 | |
| 58 // Set by the client (via set_should_quit_message_loop) if, when the import | |
| 59 // ends, this class should quit the message loop. | |
| 60 bool should_quit_message_loop_; | |
| 61 }; | |
| 62 | |
| 63 } // namespace | |
| 64 | |
| 65 namespace first_run { | 20 namespace first_run { |
| 66 namespace internal { | 21 namespace internal { |
| 67 | 22 |
| 68 void DoPostImportPlatformSpecificTasks() { | 23 void DoPostImportPlatformSpecificTasks() { |
| 69 #if !defined(OS_CHROMEOS) | 24 #if !defined(OS_CHROMEOS) |
| 70 // If stats reporting was turned on by the first run dialog then toggle | 25 // If stats reporting was turned on by the first run dialog then toggle |
| 71 // the pref (on Windows, the download is tagged with enable/disable stats so | 26 // the pref (on Windows, the download is tagged with enable/disable stats so |
| 72 // this is POSIX-specific). | 27 // this is POSIX-specific). |
| 73 if (GoogleUpdateSettings::GetCollectStatsConsent()) { | 28 if (GoogleUpdateSettings::GetCollectStatsConsent()) { |
| 74 g_browser_process->local_state()->SetBoolean( | 29 g_browser_process->local_state()->SetBoolean( |
| 75 prefs::kMetricsReportingEnabled, true); | 30 prefs::kMetricsReportingEnabled, true); |
| 76 } | 31 } |
| 77 #endif | 32 #endif |
| 78 } | 33 } |
| 79 | 34 |
| 80 bool GetFirstRunSentinelFilePath(base::FilePath* path) { | 35 bool GetFirstRunSentinelFilePath(base::FilePath* path) { |
| 81 base::FilePath first_run_sentinel; | 36 base::FilePath first_run_sentinel; |
| 82 | 37 |
| 83 if (!PathService::Get(chrome::DIR_USER_DATA, &first_run_sentinel)) | 38 if (!PathService::Get(chrome::DIR_USER_DATA, &first_run_sentinel)) |
| 84 return false; | 39 return false; |
| 85 | 40 |
| 86 *path = first_run_sentinel.Append(chrome::kFirstRunSentinel); | 41 *path = first_run_sentinel.Append(chrome::kFirstRunSentinel); |
| 87 return true; | 42 return true; |
| 88 } | 43 } |
| 89 | 44 |
| 90 bool ImportSettings(Profile* profile, | |
| 91 scoped_refptr<ImporterHost> importer_host, | |
| 92 scoped_refptr<ImporterList> importer_list, | |
| 93 int items_to_import) { | |
| 94 const importer::SourceProfile& source_profile = | |
| 95 importer_list->GetSourceProfileAt(0); | |
| 96 | |
| 97 // Ensure that importers aren't requested to import items that they do not | |
| 98 // support. If there is no overlap, skip. | |
| 99 items_to_import &= source_profile.services_supported; | |
| 100 if (items_to_import == 0) | |
| 101 return true; | |
| 102 | |
| 103 scoped_ptr<ImportEndedObserver> observer(new ImportEndedObserver); | |
| 104 importer_host->SetObserver(observer.get()); | |
| 105 importer_host->StartImportSettings(source_profile, | |
| 106 profile, | |
| 107 items_to_import, | |
| 108 new ProfileWriter(profile), | |
| 109 true); | |
| 110 // If the import process has not errored out, block on it. | |
| 111 if (!observer->ended()) { | |
| 112 observer->set_should_quit_message_loop(); | |
| 113 MessageLoop::current()->Run(); | |
| 114 } | |
| 115 | |
| 116 // Unfortunately there's no success/fail signal in ImporterHost. | |
| 117 return true; | |
| 118 } | |
| 119 | |
| 120 void SetImportPreferencesAndLaunchImport( | |
| 121 MasterPrefs* out_prefs, | |
| 122 installer::MasterPreferences* install_prefs) { | |
| 123 std::string import_bookmarks_path; | |
| 124 install_prefs->GetString( | |
| 125 installer::master_preferences::kDistroImportBookmarksFromFilePref, | |
| 126 &import_bookmarks_path); | |
| 127 if (!import_bookmarks_path.empty()) { | |
| 128 // There are bookmarks to import from a file. | |
| 129 base::FilePath path = base::FilePath::FromWStringHack(UTF8ToWide( | |
| 130 import_bookmarks_path)); | |
| 131 if (!ImportBookmarks(path)) { | |
| 132 LOG(WARNING) << "silent bookmark import failed"; | |
| 133 } | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 bool ShowPostInstallEULAIfNeeded(installer::MasterPreferences* install_prefs) { | 45 bool ShowPostInstallEULAIfNeeded(installer::MasterPreferences* install_prefs) { |
| 138 // The EULA is only handled on Windows. | 46 // The EULA is only handled on Windows. |
| 139 return true; | 47 return true; |
| 140 } | 48 } |
| 141 | 49 |
| 142 } // namespace internal | 50 } // namespace internal |
| 143 } // namespace first_run | 51 } // namespace first_run |
| 144 | 52 |
| 145 namespace first_run { | 53 namespace first_run { |
| 146 | 54 |
| 147 // TODO(port): Import switches need to be ported to both Mac and Linux. Not all | 55 // TODO(port): Import switches need to be ported to both Mac and Linux. Not all |
| 148 // import switches here are implemented for Linux. None are implemented for Mac | 56 // import switches here are implemented for Linux. None are implemented for Mac |
| 149 // (as this function will not be called on Mac). | 57 // (as this function will not be called on Mac). |
| 150 int ImportNow(Profile* profile, const CommandLine& cmdline) { | 58 int ImportNow(Profile* profile, const CommandLine& cmdline) { |
| 151 return internal::ImportBookmarkFromFileIfNeeded(profile, cmdline); | 59 return internal::ImportBookmarkFromFileIfNeeded(profile, cmdline); |
| 152 } | 60 } |
| 153 | 61 |
| 62 void LaunchInitialImport(MasterPrefs* out_prefs) { |
| 63 if (!out_prefs->import_bookmarks_path.empty()) { |
| 64 // There are bookmarks to import from a file. |
| 65 base::FilePath path = base::FilePath::FromWStringHack(UTF8ToWide( |
| 66 out_prefs->import_bookmarks_path)); |
| 67 if (!internal::ImportBookmarks(path)) { |
| 68 LOG(WARNING) << "silent bookmark import failed"; |
| 69 } |
| 70 } |
| 71 } |
| 72 |
| 154 } // namespace first_run | 73 } // namespace first_run |
| OLD | NEW |