Chromium Code Reviews| 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/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.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/time.h" | 18 #include "base/time.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
| 23 #include "chrome/browser/extensions/updater/extension_updater.h" | 23 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 24 #include "chrome/browser/first_run/first_run_dialog.h" | 24 #include "chrome/browser/first_run/first_run_dialog.h" |
| 25 #include "chrome/browser/first_run/first_run_import_observer.h" | |
| 26 #include "chrome/browser/first_run/first_run_internal.h" | 25 #include "chrome/browser/first_run/first_run_internal.h" |
| 27 #include "chrome/browser/google/google_util.h" | 26 #include "chrome/browser/google/google_util.h" |
| 28 #include "chrome/browser/importer/external_process_importer_host.h" | 27 #include "chrome/browser/importer/external_process_importer_host.h" |
| 29 #include "chrome/browser/importer/importer_host.h" | 28 #include "chrome/browser/importer/importer_host.h" |
| 30 #include "chrome/browser/importer/importer_list.h" | 29 #include "chrome/browser/importer/importer_list.h" |
| 31 #include "chrome/browser/importer/importer_progress_dialog.h" | |
| 32 #include "chrome/browser/importer/importer_progress_observer.h" | 30 #include "chrome/browser/importer/importer_progress_observer.h" |
| 33 #include "chrome/browser/process_singleton.h" | 31 #include "chrome/browser/process_singleton.h" |
| 34 #include "chrome/browser/profiles/profile_manager.h" | 32 #include "chrome/browser/profiles/profile_manager.h" |
| 35 #include "chrome/browser/search_engines/template_url_service.h" | 33 #include "chrome/browser/search_engines/template_url_service.h" |
| 36 #include "chrome/browser/search_engines/template_url_service_factory.h" | 34 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 37 #include "chrome/browser/shell_integration.h" | 35 #include "chrome/browser/shell_integration.h" |
| 38 #include "chrome/browser/signin/signin_manager.h" | 36 #include "chrome/browser/signin/signin_manager.h" |
| 39 #include "chrome/browser/signin/signin_manager_factory.h" | 37 #include "chrome/browser/signin/signin_manager_factory.h" |
| 40 #include "chrome/browser/signin/signin_tracker.h" | 38 #include "chrome/browser/signin/signin_tracker.h" |
| 41 #include "chrome/browser/ui/browser.h" | 39 #include "chrome/browser/ui/browser.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 if (user_prefs->GetBoolean(pref_path)) | 192 if (user_prefs->GetBoolean(pref_path)) |
| 195 items |= import_type; | 193 items |= import_type; |
| 196 } else { // no policy (recommended or managed) is set | 194 } else { // no policy (recommended or managed) is set |
| 197 if (should_import) | 195 if (should_import) |
| 198 items |= import_type; | 196 items |= import_type; |
| 199 } | 197 } |
| 200 | 198 |
| 201 user_prefs->ClearPref(pref_path); | 199 user_prefs->ClearPref(pref_path); |
| 202 } | 200 } |
| 203 | 201 |
| 204 // Imports bookmarks from an html file. The path to the file is provided in | 202 // Imports bookmarks from an html file. The path to the file is provided in |
|
cpu_(ooo_6.6-7.5)
2013/04/17 21:35:20
is comment of line 202 correct?
gab
2013/04/18 14:51:56
For now yes, this is currently provided on the com
| |
| 205 // the command line. | 203 // the command line. |
| 206 int ImportFromFile(Profile* profile, const CommandLine& cmdline) { | 204 void ImportFromFile(Profile* profile, const CommandLine& cmdline) { |
| 207 base::FilePath file_path = | 205 base::FilePath file_path = |
| 208 cmdline.GetSwitchValuePath(switches::kImportFromFile); | 206 cmdline.GetSwitchValuePath(switches::kImportFromFile); |
| 209 if (file_path.empty()) { | 207 if (file_path.empty()) { |
| 210 NOTREACHED(); | 208 NOTREACHED(); |
| 211 return false; | 209 return; |
| 212 } | 210 } |
| 213 scoped_refptr<ImporterHost> importer_host(new ImporterHost); | 211 scoped_refptr<ImporterHost> importer_host(new ImporterHost); |
| 214 importer_host->set_headless(); | 212 importer_host->set_headless(); |
| 215 | 213 |
| 216 importer::SourceProfile source_profile; | 214 importer::SourceProfile source_profile; |
| 217 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; | 215 source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE; |
| 218 source_profile.source_path = file_path; | 216 source_profile.source_path = file_path; |
| 219 | 217 |
| 220 FirstRunImportObserver importer_observer; | 218 scoped_ptr<first_run::internal::ImportEndedObserver> observer( |
| 221 importer::ShowImportProgressDialog(importer::FAVORITES, | 219 new first_run::internal::ImportEndedObserver); |
| 222 importer_host, | 220 importer_host->SetObserver(observer.get()); |
| 223 &importer_observer, | 221 importer_host->StartImportSettings( |
| 224 source_profile, | 222 source_profile, profile, importer::FAVORITES, new ProfileWriter(profile), |
| 225 profile, | 223 true); |
| 226 true); | 224 // If the import process has not errored out, block on it. |
| 227 | 225 if (!observer->ended()) { |
| 228 importer_observer.RunLoop(); | 226 observer->set_should_quit_message_loop(); |
| 229 return importer_observer.import_result(); | 227 MessageLoop::current()->Run(); |
| 228 } | |
|
cpu_(ooo_6.6-7.5)
2013/04/17 21:35:20
it seems the observer can be allocated in the stac
gab
2013/04/18 14:51:56
Definitely, also changed the call site this was co
| |
| 230 } | 229 } |
| 231 | 230 |
| 232 GURL UrlFromString(const std::string& in) { | 231 GURL UrlFromString(const std::string& in) { |
| 233 return GURL(in); | 232 return GURL(in); |
| 234 } | 233 } |
| 235 | 234 |
| 236 void ConvertStringVectorToGURLVector( | 235 void ConvertStringVectorToGURLVector( |
| 237 const std::vector<std::string>& src, | 236 const std::vector<std::string>& src, |
| 238 std::vector<GURL>* ret) { | 237 std::vector<GURL>* ret) { |
| 239 ret->resize(src.size()); | 238 ret->resize(src.size()); |
| 240 std::transform(src.begin(), src.end(), ret->begin(), &UrlFromString); | 239 std::transform(src.begin(), src.end(), ret->begin(), &UrlFromString); |
| 241 } | 240 } |
| 242 | 241 |
| 243 } // namespace | 242 } // namespace |
| 244 | 243 |
| 245 namespace first_run { | 244 namespace first_run { |
| 246 namespace internal { | 245 namespace internal { |
| 247 | 246 |
| 248 FirstRunState first_run_ = FIRST_RUN_UNKNOWN; | 247 FirstRunState first_run_ = FIRST_RUN_UNKNOWN; |
| 249 | 248 |
| 250 static base::LazyInstance<base::FilePath> master_prefs_path_for_testing | 249 static base::LazyInstance<base::FilePath> master_prefs_path_for_testing |
| 251 = LAZY_INSTANCE_INITIALIZER; | 250 = LAZY_INSTANCE_INITIALIZER; |
| 252 | 251 |
| 252 // TODO(gab): This will go back inline above when it is moved to first_run.cc | |
| 253 // (see TODO above), but needs to be separate for now to satisfy clang error: | |
| 254 // "[chromium-style] virtual methods with non-empty bodies shouldn't be declared | |
| 255 // inline". | |
| 256 void ImportEndedObserver::ImportEnded() { | |
| 257 ended_ = true; | |
| 258 if (should_quit_message_loop_) | |
| 259 MessageLoop::current()->Quit(); | |
| 260 } | |
| 261 | |
| 253 installer::MasterPreferences* | 262 installer::MasterPreferences* |
| 254 LoadMasterPrefs(base::FilePath* master_prefs_path) { | 263 LoadMasterPrefs(base::FilePath* master_prefs_path) { |
| 255 if (!master_prefs_path_for_testing.Get().empty()) | 264 if (!master_prefs_path_for_testing.Get().empty()) |
| 256 *master_prefs_path = master_prefs_path_for_testing.Get(); | 265 *master_prefs_path = master_prefs_path_for_testing.Get(); |
| 257 else | 266 else |
| 258 *master_prefs_path = base::FilePath(MasterPrefsPath()); | 267 *master_prefs_path = base::FilePath(MasterPrefsPath()); |
| 259 if (master_prefs_path->empty()) | 268 if (master_prefs_path->empty()) |
| 260 return NULL; | 269 return NULL; |
| 261 installer::MasterPreferences* install_prefs = | 270 installer::MasterPreferences* install_prefs = |
| 262 new installer::MasterPreferences(*master_prefs_path); | 271 new installer::MasterPreferences(*master_prefs_path); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 #if !defined(OS_LINUX) && !defined(OS_BSD) | 397 #if !defined(OS_LINUX) && !defined(OS_BSD) |
| 389 bool IsOrganicFirstRun() { | 398 bool IsOrganicFirstRun() { |
| 390 std::string brand; | 399 std::string brand; |
| 391 google_util::GetBrand(&brand); | 400 google_util::GetBrand(&brand); |
| 392 return google_util::IsOrganicFirstRun(brand); | 401 return google_util::IsOrganicFirstRun(brand); |
| 393 } | 402 } |
| 394 #endif | 403 #endif |
| 395 | 404 |
| 396 int ImportBookmarkFromFileIfNeeded(Profile* profile, | 405 int ImportBookmarkFromFileIfNeeded(Profile* profile, |
| 397 const CommandLine& cmdline) { | 406 const CommandLine& cmdline) { |
| 398 int return_code = true; | |
| 399 if (cmdline.HasSwitch(switches::kImportFromFile)) { | 407 if (cmdline.HasSwitch(switches::kImportFromFile)) { |
| 400 // Silently import preset bookmarks from file. | 408 // Silently import preset bookmarks from file. |
| 401 // This is an OEM scenario. | 409 // This is an OEM scenario. |
| 402 return_code = ImportFromFile(profile, cmdline); | 410 ImportFromFile(profile, cmdline); |
| 403 } | 411 } |
| 404 return return_code; | 412 // ImportBookmarkFromFileIfNeeded() will go away as part of |
| 413 // http://crbug.com/219419, so it is fine to hardcode |true| for now. | |
| 414 return true; | |
| 405 } | 415 } |
| 406 | 416 |
| 407 } // namespace internal | 417 } // namespace internal |
| 408 } // namespace first_run | 418 } // namespace first_run |
| 409 | 419 |
| 410 namespace first_run { | 420 namespace first_run { |
| 411 | 421 |
| 412 MasterPrefs::MasterPrefs() | 422 MasterPrefs::MasterPrefs() |
| 413 : ping_delay(0), | 423 : ping_delay(0), |
| 414 homepage_defined(false), | 424 homepage_defined(false), |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 internal::DoPostImportPlatformSpecificTasks(); | 808 internal::DoPostImportPlatformSpecificTasks(); |
| 799 } | 809 } |
| 800 | 810 |
| 801 bool DidPerformProfileImport(bool* exited_successfully) { | 811 bool DidPerformProfileImport(bool* exited_successfully) { |
| 802 if (exited_successfully) | 812 if (exited_successfully) |
| 803 *exited_successfully = profile_import_exited_successfully; | 813 *exited_successfully = profile_import_exited_successfully; |
| 804 return did_perform_profile_import; | 814 return did_perform_profile_import; |
| 805 } | 815 } |
| 806 | 816 |
| 807 } // namespace first_run | 817 } // namespace first_run |
| OLD | NEW |