| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/app_switches.h" | 7 #include "app/app_switches.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
| 13 #include "base/string_piece.h" | 13 #include "base/string_piece.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/gtk/first_run_dialog.h" | 17 #include "chrome/browser/gtk/first_run_dialog.h" |
| 18 #include "chrome/browser/shell_integration.h" | 18 #include "chrome/browser/shell_integration.h" |
| 19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/common/result_codes.h" | 21 #include "chrome/common/result_codes.h" |
| 22 #include "chrome/installer/util/google_update_settings.h" | 22 #include "chrome/installer/util/google_update_settings.h" |
| 23 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
| 24 | 24 |
| 25 namespace { | |
| 26 | |
| 27 // This class acts as an observer for the ImporterHost::Observer::ImportEnded | |
| 28 // callback. When the import process is started, certain errors may cause | |
| 29 // ImportEnded() to be called synchronously, but the typical case is that | |
| 30 // ImportEnded() is called asynchronously. Thus we have to handle both cases. | |
| 31 class ImportEndedObserver : public ImporterHost::Observer { | |
| 32 public: | |
| 33 ImportEndedObserver() | |
| 34 : ended_(false), | |
| 35 quit_message_loop_(false) { | |
| 36 } | |
| 37 virtual ~ImportEndedObserver() {} | |
| 38 | |
| 39 virtual void ImportItemStarted(importer::ImportItem item) {} | |
| 40 virtual void ImportItemEnded(importer::ImportItem item) {} | |
| 41 virtual void ImportStarted() {} | |
| 42 virtual void ImportEnded() { | |
| 43 ended_ = true; | |
| 44 if (quit_message_loop_) | |
| 45 MessageLoop::current()->Quit(); | |
| 46 } | |
| 47 | |
| 48 void set_quit_message_loop() { | |
| 49 quit_message_loop_ = true; | |
| 50 } | |
| 51 | |
| 52 bool ended() { | |
| 53 return ended_; | |
| 54 } | |
| 55 | |
| 56 private: | |
| 57 bool ended_; | |
| 58 bool quit_message_loop_; | |
| 59 }; | |
| 60 | |
| 61 } // namespace | |
| 62 | |
| 63 // TODO(port): This is just a piece of the silent import functionality from | 25 // TODO(port): This is just a piece of the silent import functionality from |
| 64 // ImportSettings for Windows. It would be nice to get the rest of it ported. | 26 // ImportSettings for Windows. It would be nice to get the rest of it ported. |
| 65 bool FirstRun::ImportBookmarks(const FilePath& import_bookmarks_path) { | 27 bool FirstRun::ImportBookmarks(const FilePath& import_bookmarks_path) { |
| 66 const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); | 28 const CommandLine& cmdline = *CommandLine::ForCurrentProcess(); |
| 67 CommandLine import_cmd(cmdline.GetProgram()); | 29 CommandLine import_cmd(cmdline.GetProgram()); |
| 68 | 30 |
| 69 // Propagate user data directory switch. | 31 // Propagate user data directory switch. |
| 70 if (cmdline.HasSwitch(switches::kUserDataDir)) { | 32 if (cmdline.HasSwitch(switches::kUserDataDir)) { |
| 71 import_cmd.AppendSwitchPath(switches::kUserDataDir, | 33 import_cmd.AppendSwitchPath(switches::kUserDataDir, |
| 72 cmdline.GetSwitchValuePath(switches::kUserDataDir)); | 34 cmdline.GetSwitchValuePath(switches::kUserDataDir)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 base::PlatformFileInfo exe_file_info; | 76 base::PlatformFileInfo exe_file_info; |
| 115 if (!file_util::GetFileInfo(exe_file_path, &exe_file_info)) { | 77 if (!file_util::GetFileInfo(exe_file_path, &exe_file_info)) { |
| 116 LOG(WARNING) << "Failed to get FileInfo object for FILE_EXE - " | 78 LOG(WARNING) << "Failed to get FileInfo object for FILE_EXE - " |
| 117 << exe_file_path.value(); | 79 << exe_file_path.value(); |
| 118 return saved_last_modified_time_of_exe_; | 80 return saved_last_modified_time_of_exe_; |
| 119 } | 81 } |
| 120 return exe_file_info.last_modified.ToDoubleT(); | 82 return exe_file_info.last_modified.ToDoubleT(); |
| 121 } | 83 } |
| 122 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) | 84 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 123 | 85 |
| 124 // At least for now, we do profile import in-process on Linux. | |
| 125 // static | |
| 126 bool FirstRun::ImportSettings(Profile* profile, | |
| 127 scoped_refptr<ImporterHost> importer_host, | |
| 128 int items_to_import) { | |
| 129 // Import data. | |
| 130 const ProfileInfo& source_profile = importer_host->GetSourceProfileInfoAt(0); | |
| 131 scoped_ptr<ImportEndedObserver> observer(new ImportEndedObserver); | |
| 132 importer_host->SetObserver(observer.get()); | |
| 133 importer_host->StartImportSettings(source_profile, | |
| 134 profile, | |
| 135 items_to_import, | |
| 136 new ProfileWriter(profile), | |
| 137 true); | |
| 138 // If the import process has not errored out, block on it. | |
| 139 if (!observer->ended()) { | |
| 140 observer->set_quit_message_loop(); | |
| 141 MessageLoop::current()->Run(); | |
| 142 } | |
| 143 // Unfortunately there's no success/fail signal in ImporterHost. | |
| 144 return true; | |
| 145 } | |
| 146 | |
| 147 // static | 86 // static |
| 148 void FirstRun::ShowFirstRunDialog(Profile* profile, | 87 void FirstRun::ShowFirstRunDialog(Profile* profile, |
| 149 bool randomize_search_engine_experiment) { | 88 bool randomize_search_engine_experiment) { |
| 150 FirstRunDialog::Show(profile, randomize_search_engine_experiment); | 89 FirstRunDialog::Show(profile, randomize_search_engine_experiment); |
| 151 } | 90 } |
| 152 | 91 |
| 153 // static | 92 // static |
| 154 bool FirstRun::IsOrganic() { | 93 bool FirstRun::IsOrganic() { |
| 155 // We treat all installs as organic. | 94 // We treat all installs as organic. |
| 156 return true; | 95 return true; |
| 157 } | 96 } |
| 158 | 97 |
| 159 // static | 98 // static |
| 160 void FirstRun::PlatformSetup() { | 99 void FirstRun::PlatformSetup() { |
| 161 // Things that Windows does here (creating a desktop icon, for example) are | 100 // Things that Windows does here (creating a desktop icon, for example) are |
| 162 // handled at install time on Linux. | 101 // handled at install time on Linux. |
| 163 } | 102 } |
| OLD | NEW |