diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-30 01:23:32 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-30 01:23:32 +0000 |
commit | 1979689363e58c9917d751d5134287d8616528e5 (patch) | |
tree | 6342d081e86670f1a05b07933888278d6e355759 | |
parent | 27d3571b99a7e69bedb8ac0282b981325906edc2 (diff) | |
download | chromium_src-1979689363e58c9917d751d5134287d8616528e5.zip chromium_src-1979689363e58c9917d751d5134287d8616528e5.tar.gz chromium_src-1979689363e58c9917d751d5134287d8616528e5.tar.bz2 |
Revert r46023: "Detect new instance of the browser when running in the background in persistent"
Broke the build.
Review URL: http://codereview.chromium.org/1718024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46025 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/chrome_exe_main.cc | 1 | ||||
-rw-r--r-- | chrome/app/chrome_exe_main_gtk.cc | 9 | ||||
-rw-r--r-- | chrome/app/client_util.cc | 15 | ||||
-rw-r--r-- | chrome/app/client_util.h | 4 | ||||
-rw-r--r-- | chrome/browser/browser_main.cc | 23 | ||||
-rw-r--r-- | chrome/browser/browser_process.h | 6 | ||||
-rw-r--r-- | chrome/browser/browser_process_impl.cc | 43 | ||||
-rw-r--r-- | chrome/browser/browser_process_impl.h | 8 | ||||
-rw-r--r-- | chrome/browser/first_run.h | 39 | ||||
-rw-r--r-- | chrome/browser/first_run_gtk.cc | 46 | ||||
-rw-r--r-- | chrome/browser/first_run_win.cc | 15 | ||||
-rw-r--r-- | chrome/installer/util/google_update_constants.cc | 2 | ||||
-rw-r--r-- | chrome/installer/util/google_update_constants.h | 4 | ||||
-rw-r--r-- | chrome/test/testing_browser_process.h | 4 |
14 files changed, 42 insertions, 177 deletions
diff --git a/chrome/app/chrome_exe_main.cc b/chrome/app/chrome_exe_main.cc index ed4c263..fdd2cac 100644 --- a/chrome/app/chrome_exe_main.cc +++ b/chrome/app/chrome_exe_main.cc @@ -44,7 +44,6 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) { // Load and launch the chrome dll. *Everything* happens inside. MainDllLoader* loader = MakeMainDllLoader(); int rc = loader->Launch(instance, &sandbox_info); - loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); delete loader; return rc; diff --git a/chrome/app/chrome_exe_main_gtk.cc b/chrome/app/chrome_exe_main_gtk.cc index 8b612c7..0ed9e15 100644 --- a/chrome/app/chrome_exe_main_gtk.cc +++ b/chrome/app/chrome_exe_main_gtk.cc @@ -4,7 +4,6 @@ #include "base/at_exit.h" #include "base/process_util.h" -#include "chrome/browser/first_run.h" // The entry point for all invocations of Chromium, browser and renderer. On // windows, this does nothing but load chrome.dll and invoke its entry point in @@ -45,11 +44,5 @@ int main(int argc, const char** argv) { // keep it. // base::AtExitManager exit_manager; - int return_code = ChromeMain(argc, argv); - - // Launch a new instance if we're shutting down because we detected an - // upgrade in the persistent mode. - Upgrade::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); - - return return_code; + return ChromeMain(argc, argv); } diff --git a/chrome/app/client_util.cc b/chrome/app/client_util.cc index c822ec8..074b6c8 100644 --- a/chrome/app/client_util.cc +++ b/chrome/app/client_util.cc @@ -18,8 +18,6 @@ namespace { // The entry point signature of chrome.dll. typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*, wchar_t*); -typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)(); - // Not generic, we only handle strings up to 128 chars. bool ReadRegistryStr(HKEY key, const wchar_t* name, std::wstring* value) { BYTE out[128 * sizeof(wchar_t)]; @@ -198,19 +196,6 @@ int MainDllLoader::Launch(HINSTANCE instance, return OnBeforeExit(rc); } -void MainDllLoader::RelaunchChromeBrowserWithNewCommandLineIfNeeded() { - RelaunchChromeBrowserWithNewCommandLineIfNeededFunc relaunch_function = - reinterpret_cast<RelaunchChromeBrowserWithNewCommandLineIfNeededFunc>( - ::GetProcAddress(dll_, - "RelaunchChromeBrowserWithNewCommandLineIfNeeded")); - if (!relaunch_function) { - LOG(ERROR) << "Could not find exported function " - << "RelaunchChromeBrowserWithNewCommandLineIfNeeded"; - } else { - relaunch_function(); - } -} - //============================================================================= class ChromeDllLoader : public MainDllLoader { diff --git a/chrome/app/client_util.h b/chrome/app/client_util.h index 8b6c154f..a391be0 100644 --- a/chrome/app/client_util.h +++ b/chrome/app/client_util.h @@ -30,10 +30,6 @@ class MainDllLoader { // upon termination. int Launch(HINSTANCE instance, sandbox::SandboxInterfaceInfo* sbox_info); - // Launches a new instance of the browser if the current instance in - // persistent mode an upgrade is detected. - void RelaunchChromeBrowserWithNewCommandLineIfNeeded(); - // Derived classes must return the relative registry path that holds the // most current version of chrome.dll. virtual std::wstring GetRegistryPath() = 0; diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 179201d..790502f 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -618,19 +618,6 @@ OSStatus KeychainCallback(SecKeychainEvent keychain_event, } // namespace -#if defined(OS_WIN) -#define DLLEXPORT __declspec(dllexport) - -// We use extern C for the prototype DLLEXPORT to avoid C++ name mangling. -extern "C" { -DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded(); -} - -DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() { - Upgrade::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); -} -#endif - // Main routine for running as the Browser process. int BrowserMain(const MainFunctionParams& parameters) { const CommandLine& parsed_command_line = parameters.command_line_; @@ -1190,7 +1177,7 @@ int BrowserMain(const MainFunctionParams& parameters) { // the main message loop. if (browser_init.Start(parsed_command_line, std::wstring(), profile, &result_code)) { -#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) +#if defined(OS_WIN) // Initialize autoupdate timer. Timer callback costs basically nothing // when browser is not in persistent mode, so it's OK to let it ride on // the main thread. This needs to be done here because we don't want @@ -1198,14 +1185,6 @@ int BrowserMain(const MainFunctionParams& parameters) { g_browser_process->StartAutoupdateTimer(); #endif -#if defined(OS_LINUX) && !defined(OS_CHROMEOS) - // On Linux, the running exe will be updated if an upgrade becomes - // available while the browser is running. We need to save the last - // modified time of the exe, so we can compare to determine if there is - // an upgrade while the browser is kept alive by a persistent extension. - Upgrade::SaveLastModifiedTimeOfExe(); -#endif - // Record now as the last succesful chrome start. GoogleUpdateSettings::SetLastRunTime(); // Call Recycle() here as late as possible, before going into the loop diff --git a/chrome/browser/browser_process.h b/chrome/browser/browser_process.h index 91614b6..e6f6eb3 100644 --- a/chrome/browser/browser_process.h +++ b/chrome/browser/browser_process.h @@ -139,7 +139,8 @@ class BrowserProcess { // disk. virtual void CheckForInspectorFiles() = 0; -#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) +#if defined(OS_WIN) + // This will start a timer that, if Chrome is in persistent mode, will check // whether an update is available, and if that's the case, restart the // browser. Note that restart code will strip some of the command line keys @@ -148,7 +149,8 @@ class BrowserProcess { // background mode. For the full list of "blacklisted" keys, refer to // |kSwitchesToRemoveOnAutorestart| array in browser_process_impl.cc. virtual void StartAutoupdateTimer() = 0; -#endif + +#endif // OS_WIN // Return true iff we found the inspector files on disk. It's possible to // call this function before we have a definite answer from the disk. In that diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index 05ea69f..ac623a5 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -4,8 +4,6 @@ #include "chrome/browser/browser_process_impl.h" -#include <map> - #include "app/clipboard/clipboard.h" #include "app/l10n_util.h" #include "base/command_line.h" @@ -65,12 +63,6 @@ #include "chrome/common/render_messages.h" #endif -#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) -// How often to check if the persistent instance of Chrome needs to restart -// to install an update. -static const int kUpdateCheckIntervalHours = 6; -#endif - BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line) : created_resource_dispatcher_host_(false), created_metrics_service_(false), @@ -456,14 +448,14 @@ void BrowserProcessImpl::CheckForInspectorFiles() { NewRunnableMethod(this, &BrowserProcessImpl::DoInspectorFilesCheck)); } -#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) +#if defined(OS_WIN) void BrowserProcessImpl::StartAutoupdateTimer() { autoupdate_timer_.Start( - TimeDelta::FromHours(kUpdateCheckIntervalHours), + TimeDelta::FromHours(google_update::kUpdateCheckInvervalHours), this, &BrowserProcessImpl::OnAutoupdateTimer); } -#endif +#endif // OS_WIN #if defined(IPC_MESSAGE_LOG_ENABLED) @@ -516,8 +508,8 @@ void BrowserProcessImpl::DoInspectorFilesCheck() { have_inspector_files_ = result; } -// Mac is currently not supported. -#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) +#if defined(OS_WIN) // Linux doesn't do rename on restart, and Mac is currently + // not supported. bool BrowserProcessImpl::CanAutorestartForUpdate() const { // Check if browser is in the background and if it needs to be restarted to @@ -539,13 +531,13 @@ const char* const kSwitchesToRemoveOnAutorestart[] = { void BrowserProcessImpl::RestartPersistentInstance() { CommandLine* old_cl = CommandLine::ForCurrentProcess(); - scoped_ptr<CommandLine> new_cl(new CommandLine(old_cl->GetProgram())); + CommandLine new_cl(old_cl->GetProgram()); std::map<std::string, CommandLine::StringType> switches = old_cl->GetSwitches(); // Remove the keys that we shouldn't pass through during restart. - for (size_t i = 0; i < arraysize(kSwitchesToRemoveOnAutorestart); i++) { + for (int i = 0; i < arraysize(kSwitchesToRemoveOnAutorestart); i++) { switches.erase(kSwitchesToRemoveOnAutorestart[i]); } @@ -555,29 +547,28 @@ void BrowserProcessImpl::RestartPersistentInstance() { switches.begin(); i != switches.end(); ++i) { CommandLine::StringType switch_value = i->second; if (switch_value.length() > 0) { - new_cl->AppendSwitchWithValue(i->first, i->second); + new_cl.AppendSwitchWithValue(i->first, i->second); } else { - new_cl->AppendSwitch(i->first); + new_cl.AppendSwitch(i->first); } } // TODO(atwilson): Uncomment the following two lines to add the "persistence" // switch when the corresponding CL is committed. - // if (!new_cl->HasSwitch(switches::kLongLivedExtensions)) - // new_cl->AppendSwitch(switches::kLongLivedExtensions); - - DLOG(WARNING) << "Shutting down current instance of the browser."; - BrowserList::CloseAllBrowsersAndExit(); + // if (!new_cl.HasSwitch(switches::kLongLivedExtensions)) + // new_cl.AppendSwitch(switches::kLongLivedExtensions); - // Transfer ownership to Upgrade. - Upgrade::SetNewCommandLine(new_cl.release()); + if (Upgrade::RelaunchChromeBrowser(new_cl)) { + BrowserList::CloseAllBrowsersAndExit(); + } else { + DLOG(ERROR) << "Could not restart browser for autoupdate."; + } } void BrowserProcessImpl::OnAutoupdateTimer() { if (CanAutorestartForUpdate()) { - DLOG(WARNING) << "Detected update. Restarting browser."; RestartPersistentInstance(); } } -#endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) +#endif diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h index d476b58..93e6ab3 100644 --- a/chrome/browser/browser_process_impl.h +++ b/chrome/browser/browser_process_impl.h @@ -195,9 +195,9 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe { virtual void CheckForInspectorFiles(); -#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) +#if defined(OS_WIN) void StartAutoupdateTimer(); -#endif +#endif // OS_WIN virtual bool have_inspector_files() const { return have_inspector_files_; @@ -314,7 +314,7 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe { // Our best estimate about the existence of the inspector directory. bool have_inspector_files_; -#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) +#if defined(OS_WIN) base::RepeatingTimer<BrowserProcessImpl> autoupdate_timer_; // Gets called by autoupdate timer to see if browser needs restart and can be @@ -322,7 +322,7 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe { void OnAutoupdateTimer(); bool CanAutorestartForUpdate() const; void RestartPersistentInstance(); -#endif // defined(OS_WIN) || defined(OS_LINUX) +#endif // OS_WIN DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl); }; diff --git a/chrome/browser/first_run.h b/chrome/browser/first_run.h index 0ac3da5..a3310ed 100644 --- a/chrome/browser/first_run.h +++ b/chrome/browser/first_run.h @@ -137,13 +137,12 @@ class FirstRun { DISALLOW_IMPLICIT_CONSTRUCTORS(FirstRun); }; -#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) +#if defined(OS_WIN) // This class contains the actions that need to be performed when an upgrade // is required. This involves mainly swapping the chrome exe and relaunching // the new browser. class Upgrade { public: -#if defined(OS_WIN) // Possible results of ShowTryChromeDialog(). enum TryResult { TD_TRY_CHROME, // Launch chrome right now. @@ -169,48 +168,22 @@ class Upgrade { // is no new_chrome.exe or the swap fails the return is false; static bool SwapNewChromeExeIfPresent(); - // Combines the two methods, RelaunchChromeBrowser and - // SwapNewChromeExeIfPresent, to perform the rename and relaunch of + // Combines the two methods above to perform the rename and relaunch of // the browser. Note that relaunch does NOT exit the existing browser process. // If this is called before message loop is executed, simply exit the main // function. If browser is already running, you will need to exit it. static bool DoUpgradeTasks(const CommandLine& command_line); + // Checks if chrome_new.exe is present in the current instance's install. + static bool IsUpdatePendingRestart(); + // Shows a modal dialog asking the user to give chrome another try. See // above for the possible outcomes of the function. This is an experimental, // non-localized dialog. // |version| can be 0, 1 or 2 and selects what strings to present. static TryResult ShowTryChromeDialog(size_t version); -#endif // OS_WIN - -#if defined(OS_LINUX) && !defined(OS_CHROMEOS) - static void SaveLastModifiedTimeOfExe(); -#endif - - static void SetNewCommandLine(CommandLine* new_command_line) { - // Takes ownership of the pointer. - new_command_line_ = new_command_line; - } - - // Launches a new instance of the browser if the current instance in - // persistent mode an upgrade is detected. - static void RelaunchChromeBrowserWithNewCommandLineIfNeeded(); - - // Windows: - // Checks if chrome_new.exe is present in the current instance's install. - // Linux: - // Checks if the last modified time of chrome is newer than that of the - // current running instance. - static bool IsUpdatePendingRestart(); - -#if defined(OS_LINUX) && !defined(OS_CHROMEOS) - private: - static double GetLastModifiedTimeOfExe(); - static double saved_last_modified_time_of_exe_; -#endif - static CommandLine* new_command_line_; }; -#endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) +#endif // A subclass of BrowserProcessImpl that does not have a GoogleURLTracker or // IntranetRedirectDetector so we don't do any URL fetches (as we have no IO diff --git a/chrome/browser/first_run_gtk.cc b/chrome/browser/first_run_gtk.cc index 0755a7f..a424d60 100644 --- a/chrome/browser/first_run_gtk.cc +++ b/chrome/browser/first_run_gtk.cc @@ -20,8 +20,6 @@ #include "chrome/installer/util/util_constants.h" #include "googleurl/src/gurl.h" -CommandLine* Upgrade::new_command_line_ = NULL; - bool OpenFirstRunDialog(Profile* profile, bool homepage_defined, int import_items, int dont_import_items, @@ -141,47 +139,3 @@ bool FirstRun::ImportBookmarks(const std::wstring& import_bookmarks_path) { // for the process to return. return base::LaunchApp(import_cmd, true, false, NULL); } - -#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) -double Upgrade::saved_last_modified_time_of_exe_ = 0; - -// static -bool Upgrade::IsUpdatePendingRestart() { - return saved_last_modified_time_of_exe_ != - Upgrade::GetLastModifiedTimeOfExe(); -} - -// static -void Upgrade::SaveLastModifiedTimeOfExe() { - saved_last_modified_time_of_exe_ = Upgrade::GetLastModifiedTimeOfExe(); -} - -// static -void Upgrade::RelaunchChromeBrowserWithNewCommandLineIfNeeded() { - if (new_command_line_) { - if (!base::LaunchApp(*new_command_line_, false, false, NULL)) { - DLOG(ERROR) << "Launching a new instance of the browser failed."; - } else { - DLOG(WARNING) << "Launched a new instance of the browser."; - } - delete new_command_line_; - new_command_line_ = NULL; - } -} - -// static -double Upgrade::GetLastModifiedTimeOfExe() { - FilePath exe_file_path; - if (!PathService::Get(base::FILE_EXE, &exe_file_path)) { - LOG(WARNING) << "Failed to get FilePath object for FILE_EXE."; - return saved_last_modified_time_of_exe_; - } - file_util::FileInfo exe_file_info; - if (!file_util::GetFileInfo(exe_file_path, &exe_file_info)) { - LOG(WARNING) << "Failed to get FileInfo object for FILE_EXE - " - << exe_file_path.value(); - return saved_last_modified_time_of_exe_; - } - return exe_file_info.last_modified.ToDoubleT(); -} -#endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) diff --git a/chrome/browser/first_run_win.cc b/chrome/browser/first_run_win.cc index 86a79e5..cc34dc1 100644 --- a/chrome/browser/first_run_win.cc +++ b/chrome/browser/first_run_win.cc @@ -205,8 +205,6 @@ class FirsRunDelayedTasks : public NotificationObserver { } // namespace -CommandLine* Upgrade::new_command_line_ = NULL; - bool FirstRun::CreateChromeDesktopShortcut() { std::wstring chrome_exe; if (!PathService::Get(base::FILE_EXE, &chrome_exe)) @@ -412,18 +410,6 @@ bool Upgrade::RelaunchChromeBrowser(const CommandLine& command_line) { false, false, NULL); } -void Upgrade::RelaunchChromeBrowserWithNewCommandLineIfNeeded() { - if (new_command_line_) { - if (RelaunchChromeBrowser(*new_command_line_)) { - DLOG(ERROR) << "Launching a new instance of the browser failed."; - } else { - DLOG(WARNING) << "Launched a new instance of the browser."; - } - delete new_command_line_; - new_command_line_ = NULL; - } -} - bool Upgrade::SwapNewChromeExeIfPresent() { std::wstring new_chrome_exe; if (!GetNewerChromeFile(&new_chrome_exe)) @@ -1034,3 +1020,4 @@ Upgrade::TryResult Upgrade::ShowTryChromeDialog(size_t version) { TryChromeDialog td; return td.ShowModal(); } + diff --git a/chrome/installer/util/google_update_constants.cc b/chrome/installer/util/google_update_constants.cc index 2c77a0e..a904a74 100644 --- a/chrome/installer/util/google_update_constants.cc +++ b/chrome/installer/util/google_update_constants.cc @@ -33,4 +33,6 @@ const wchar_t kRegEULAAceptedField[] = L"eulaaccepted"; const wchar_t kEnvProductVersionKey[] = L"CHROME_VERSION"; const wchar_t kRegLastRunTimeField[] = L"lastrun"; +const int kUpdateCheckInvervalHours = 6; + } // namespace google_update diff --git a/chrome/installer/util/google_update_constants.h b/chrome/installer/util/google_update_constants.h index e21a198..79100a6 100644 --- a/chrome/installer/util/google_update_constants.h +++ b/chrome/installer/util/google_update_constants.h @@ -46,6 +46,10 @@ extern const wchar_t kEnvProductVersionKey[]; // last time that chrome ran in the Time internal format. extern const wchar_t kRegLastRunTimeField[]; +// How often to check if the persistent instance of Chrome needs to restart +// to install an update. +extern const int kUpdateCheckInvervalHours; + } // namespace google_update #endif // CHROME_INSTALLER_UTIL_GOOGLE_UPDATE_CONSTANTS_H_ diff --git a/chrome/test/testing_browser_process.h b/chrome/test/testing_browser_process.h index e704330..b95b3a8 100644 --- a/chrome/test/testing_browser_process.h +++ b/chrome/test/testing_browser_process.h @@ -149,9 +149,9 @@ class TestingBrowserProcess : public BrowserProcess { virtual void CheckForInspectorFiles() {} -#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) +#if defined(OS_WIN) virtual void StartAutoupdateTimer() {} -#endif +#endif // OS_WIN virtual bool have_inspector_files() const { return true; } #if defined(IPC_MESSAGE_LOG_ENABLED) |