| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/upgrade_util.h" | 5 #include "chrome/browser/first_run/upgrade_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 ::CloseHandle(handle); | 52 ::CloseHandle(handle); |
| 53 if (exit_code == installer::RENAME_SUCCESSFUL) | 53 if (exit_code == installer::RENAME_SUCCESSFUL) |
| 54 return true; | 54 return true; |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 return false; | 57 return false; |
| 58 } | 58 } |
| 59 | 59 |
| 60 } // namespace | 60 } // namespace |
| 61 | 61 |
| 62 | |
| 63 namespace upgrade_util { | 62 namespace upgrade_util { |
| 64 | 63 |
| 65 bool RelaunchChromeBrowser(const CommandLine& command_line) { | 64 bool RelaunchChromeBrowser(const CommandLine& command_line) { |
| 66 scoped_ptr<base::Environment> env(base::Environment::Create()); | 65 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 67 env->UnSetVar(chrome::kChromeVersionEnvVar); | 66 env->UnSetVar(chrome::kChromeVersionEnvVar); |
| 68 return base::LaunchApp( | 67 return base::LaunchApp( |
| 69 command_line.command_line_string(), false, false, NULL); | 68 command_line.command_line_string(), false, false, NULL); |
| 70 } | 69 } |
| 71 | 70 |
| 72 bool IsUpdatePendingRestart() { | 71 bool IsUpdatePendingRestart() { |
| 73 FilePath new_chrome_exe; | 72 FilePath new_chrome_exe; |
| 74 if (!GetNewerChromeFile(&new_chrome_exe)) | 73 if (!GetNewerChromeFile(&new_chrome_exe)) |
| 75 return false; | 74 return false; |
| 76 return file_util::PathExists(new_chrome_exe); | 75 return file_util::PathExists(new_chrome_exe); |
| 77 } | 76 } |
| 78 | 77 |
| 79 bool IsBrowserAlreadyRunning() { | |
| 80 static HANDLE handle = NULL; | |
| 81 FilePath exe_path; | |
| 82 PathService::Get(base::FILE_EXE, &exe_path); | |
| 83 std::wstring exe = exe_path.value(); | |
| 84 std::replace(exe.begin(), exe.end(), '\\', '!'); | |
| 85 std::transform(exe.begin(), exe.end(), exe.begin(), tolower); | |
| 86 exe = L"Global\\" + exe; | |
| 87 if (handle != NULL) | |
| 88 CloseHandle(handle); | |
| 89 handle = CreateEvent(NULL, TRUE, TRUE, exe.c_str()); | |
| 90 int error = GetLastError(); | |
| 91 return (error == ERROR_ALREADY_EXISTS || error == ERROR_ACCESS_DENIED); | |
| 92 } | |
| 93 | |
| 94 bool SwapNewChromeExeIfPresent() { | 78 bool SwapNewChromeExeIfPresent() { |
| 95 FilePath new_chrome_exe; | 79 FilePath new_chrome_exe; |
| 96 if (!GetNewerChromeFile(&new_chrome_exe)) | 80 if (!GetNewerChromeFile(&new_chrome_exe)) |
| 97 return false; | 81 return false; |
| 98 if (!file_util::PathExists(new_chrome_exe)) | 82 if (!file_util::PathExists(new_chrome_exe)) |
| 99 return false; | 83 return false; |
| 100 FilePath cur_chrome_exe; | 84 FilePath cur_chrome_exe; |
| 101 if (!PathService::Get(base::FILE_EXE, &cur_chrome_exe)) | 85 if (!PathService::Get(base::FILE_EXE, &cur_chrome_exe)) |
| 102 return false; | 86 return false; |
| 103 | 87 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 131 return false; | 115 return false; |
| 132 // At this point the chrome.exe has been swapped with the new one. | 116 // At this point the chrome.exe has been swapped with the new one. |
| 133 if (!RelaunchChromeBrowser(command_line)) { | 117 if (!RelaunchChromeBrowser(command_line)) { |
| 134 // The re-launch fails. Feel free to panic now. | 118 // The re-launch fails. Feel free to panic now. |
| 135 NOTREACHED(); | 119 NOTREACHED(); |
| 136 } | 120 } |
| 137 return true; | 121 return true; |
| 138 } | 122 } |
| 139 | 123 |
| 140 } // namespace upgrade_util | 124 } // namespace upgrade_util |
| OLD | NEW |