| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_FIRST_RUN_UPGRADE_H_ | |
| 6 #define CHROME_BROWSER_FIRST_RUN_UPGRADE_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "build/build_config.h" | |
| 11 | |
| 12 class CommandLine; | |
| 13 | |
| 14 #if defined(OS_WIN) | |
| 15 class ProcessSingleton; | |
| 16 #endif | |
| 17 | |
| 18 // This class contains the actions that need to be performed when an upgrade | |
| 19 // is required. This involves mainly swapping the chrome exe and relaunching | |
| 20 // the new browser. | |
| 21 class Upgrade { | |
| 22 public: | |
| 23 #if defined(OS_WIN) | |
| 24 // Possible results of ShowTryChromeDialog(). | |
| 25 enum TryResult { | |
| 26 TRY_CHROME, // Launch chrome right now. | |
| 27 NOT_NOW, // Don't launch chrome. Exit now. | |
| 28 UNINSTALL_CHROME, // Initiate chrome uninstall and exit. | |
| 29 DIALOG_ERROR, // An error occurred creating the dialog. | |
| 30 COUNT | |
| 31 }; | |
| 32 | |
| 33 // Check if current chrome.exe is already running as a browser process by | |
| 34 // trying to create a Global event with name same as full path of chrome.exe. | |
| 35 // This method caches the handle to this event so on subsequent calls also | |
| 36 // it can first close the handle and check for any other process holding the | |
| 37 // handle to the event. | |
| 38 static bool IsBrowserAlreadyRunning(); | |
| 39 | |
| 40 // If the new_chrome.exe exists (placed by the installer then is swapped | |
| 41 // to chrome.exe and the old chrome is renamed to old_chrome.exe. If there | |
| 42 // is no new_chrome.exe or the swap fails the return is false; | |
| 43 static bool SwapNewChromeExeIfPresent(); | |
| 44 | |
| 45 // Combines the two methods, RelaunchChromeBrowser and | |
| 46 // SwapNewChromeExeIfPresent, to perform the rename and relaunch of | |
| 47 // the browser. Note that relaunch does NOT exit the existing browser process. | |
| 48 // If this is called before message loop is executed, simply exit the main | |
| 49 // function. If browser is already running, you will need to exit it. | |
| 50 static bool DoUpgradeTasks(const CommandLine& command_line); | |
| 51 | |
| 52 // Shows a modal dialog asking the user to give chrome another try. See | |
| 53 // above for the possible outcomes of the function. This is an experimental, | |
| 54 // non-localized dialog. | |
| 55 // |version| can be 0, 1 or 2 and selects what strings to present. | |
| 56 // |process_singleton| needs to be valid and it will be locked while | |
| 57 // the dialog is shown. | |
| 58 static TryResult ShowTryChromeDialog(size_t version, | |
| 59 ProcessSingleton* process_singleton); | |
| 60 #endif // OS_WIN | |
| 61 | |
| 62 // Launches chrome again simulating a 'user' launch. If chrome could not | |
| 63 // be launched the return is false. | |
| 64 static bool RelaunchChromeBrowser(const CommandLine& command_line); | |
| 65 | |
| 66 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 67 static void SaveLastModifiedTimeOfExe(); | |
| 68 #endif | |
| 69 | |
| 70 static void SetNewCommandLine(CommandLine* new_command_line) { | |
| 71 // Takes ownership of the pointer. | |
| 72 new_command_line_ = new_command_line; | |
| 73 } | |
| 74 | |
| 75 // Launches a new instance of the browser if the current instance in | |
| 76 // persistent mode an upgrade is detected. | |
| 77 static void RelaunchChromeBrowserWithNewCommandLineIfNeeded(); | |
| 78 | |
| 79 // Windows: | |
| 80 // Checks if chrome_new.exe is present in the current instance's install. | |
| 81 // Linux: | |
| 82 // Checks if the last modified time of chrome is newer than that of the | |
| 83 // current running instance. | |
| 84 static bool IsUpdatePendingRestart(); | |
| 85 | |
| 86 private: | |
| 87 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 88 static double GetLastModifiedTimeOfExe(); | |
| 89 static double saved_last_modified_time_of_exe_; | |
| 90 #endif | |
| 91 static CommandLine* new_command_line_; | |
| 92 | |
| 93 DISALLOW_IMPLICIT_CONSTRUCTORS(Upgrade); | |
| 94 }; | |
| 95 | |
| 96 #endif // CHROME_BROWSER_FIRST_RUN_UPGRADE_H_ | |
| OLD | NEW |