Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1060)

Side by Side Diff: chrome/browser/first_run/upgrade_util_win.cc

Issue 6840003: first-run: Refactor Upgrade class into a common upgrade_util API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: upgrade_utils -> upgrade_util Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/first_run/upgrade_util_linux.cc ('k') | chrome/browser/first_run/upgrade_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/environment.h" 12 #include "base/environment.h"
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 ::CloseHandle(handle); 53 ::CloseHandle(handle);
54 if (exit_code == installer::RENAME_SUCCESSFUL) 54 if (exit_code == installer::RENAME_SUCCESSFUL)
55 return true; 55 return true;
56 } 56 }
57 } 57 }
58 return false; 58 return false;
59 } 59 }
60 60
61 } // namespace 61 } // namespace
62 62
63 // static
64 CommandLine* Upgrade::new_command_line_ = NULL;
65 63
66 // static 64 namespace upgrade_util {
67 bool Upgrade::IsBrowserAlreadyRunning() { 65
66 bool RelaunchChromeBrowser(const CommandLine& command_line) {
67 scoped_ptr<base::Environment> env(base::Environment::Create());
68 env->UnSetVar(chrome::kChromeVersionEnvVar);
69 return base::LaunchApp(
70 command_line.command_line_string(), false, false, NULL);
71 }
72
73 bool IsUpdatePendingRestart() {
74 FilePath new_chrome_exe;
75 if (!GetNewerChromeFile(&new_chrome_exe))
76 return false;
77 return file_util::PathExists(new_chrome_exe);
78 }
79
80 bool IsBrowserAlreadyRunning() {
68 static HANDLE handle = NULL; 81 static HANDLE handle = NULL;
69 FilePath exe_path; 82 FilePath exe_path;
70 PathService::Get(base::FILE_EXE, &exe_path); 83 PathService::Get(base::FILE_EXE, &exe_path);
71 std::wstring exe = exe_path.value(); 84 std::wstring exe = exe_path.value();
72 std::replace(exe.begin(), exe.end(), '\\', '!'); 85 std::replace(exe.begin(), exe.end(), '\\', '!');
73 std::transform(exe.begin(), exe.end(), exe.begin(), tolower); 86 std::transform(exe.begin(), exe.end(), exe.begin(), tolower);
74 exe = L"Global\\" + exe; 87 exe = L"Global\\" + exe;
75 if (handle != NULL) 88 if (handle != NULL)
76 CloseHandle(handle); 89 CloseHandle(handle);
77 handle = CreateEvent(NULL, TRUE, TRUE, exe.c_str()); 90 handle = CreateEvent(NULL, TRUE, TRUE, exe.c_str());
78 int error = GetLastError(); 91 int error = GetLastError();
79 return (error == ERROR_ALREADY_EXISTS || error == ERROR_ACCESS_DENIED); 92 return (error == ERROR_ALREADY_EXISTS || error == ERROR_ACCESS_DENIED);
80 } 93 }
81 94
82 // static 95 bool SwapNewChromeExeIfPresent() {
83 bool Upgrade::SwapNewChromeExeIfPresent() {
84 FilePath new_chrome_exe; 96 FilePath new_chrome_exe;
85 if (!GetNewerChromeFile(&new_chrome_exe)) 97 if (!GetNewerChromeFile(&new_chrome_exe))
86 return false; 98 return false;
87 if (!file_util::PathExists(new_chrome_exe)) 99 if (!file_util::PathExists(new_chrome_exe))
88 return false; 100 return false;
89 FilePath cur_chrome_exe; 101 FilePath cur_chrome_exe;
90 if (!PathService::Get(base::FILE_EXE, &cur_chrome_exe)) 102 if (!PathService::Get(base::FILE_EXE, &cur_chrome_exe))
91 return false; 103 return false;
92 104
93 // First try to rename exe by launching rename command ourselves. 105 // First try to rename exe by launching rename command ourselves.
(...skipping 14 matching lines...) Expand all
108 ::CloseHandle(handle); 120 ::CloseHandle(handle);
109 if (exit_code == installer::RENAME_SUCCESSFUL) 121 if (exit_code == installer::RENAME_SUCCESSFUL)
110 return true; 122 return true;
111 } 123 }
112 } 124 }
113 125
114 // Rename didn't work so try to rename by calling Google Update 126 // Rename didn't work so try to rename by calling Google Update
115 return InvokeGoogleUpdateForRename(); 127 return InvokeGoogleUpdateForRename();
116 } 128 }
117 129
118 // static 130 bool DoUpgradeTasks(const CommandLine& command_line) {
119 bool Upgrade::DoUpgradeTasks(const CommandLine& command_line) { 131 if (!SwapNewChromeExeIfPresent())
120 if (!Upgrade::SwapNewChromeExeIfPresent())
121 return false; 132 return false;
122 // At this point the chrome.exe has been swapped with the new one. 133 // At this point the chrome.exe has been swapped with the new one.
123 if (!Upgrade::RelaunchChromeBrowser(command_line)) { 134 if (!RelaunchChromeBrowser(command_line)) {
124 // The re-launch fails. Feel free to panic now. 135 // The re-launch fails. Feel free to panic now.
125 NOTREACHED(); 136 NOTREACHED();
126 } 137 }
127 return true; 138 return true;
128 } 139 }
129 140
130 // static 141 TryResult ShowTryChromeDialog(size_t version,
131 Upgrade::TryResult Upgrade::ShowTryChromeDialog( 142 ProcessSingleton* process_singleton) {
132 size_t version,
133 ProcessSingleton* process_singleton) {
134 if (version > 10000) { 143 if (version > 10000) {
135 // This is a test value. We want to make sure we exercise 144 // This is a test value. We want to make sure we exercise
136 // returning this early. See EarlyReturnTest test harness. 145 // returning this early. See EarlyReturnTest test harness.
137 return Upgrade::NOT_NOW; 146 return NOT_NOW;
138 } 147 }
139 TryChromeDialogView dialog(version); 148 TryChromeDialogView dialog(version);
140 return dialog.ShowModal(process_singleton); 149 return dialog.ShowModal(process_singleton);
141 } 150 }
142 151
143 // static 152 } // namespace upgrade_util
144 bool Upgrade::RelaunchChromeBrowser(const CommandLine& command_line) {
145 scoped_ptr<base::Environment> env(base::Environment::Create());
146 env->UnSetVar(chrome::kChromeVersionEnvVar);
147 return base::LaunchApp(
148 command_line.command_line_string(), false, false, NULL);
149 }
150
151 // static
152 bool Upgrade::IsUpdatePendingRestart() {
153 FilePath new_chrome_exe;
154 if (!GetNewerChromeFile(&new_chrome_exe))
155 return false;
156 return file_util::PathExists(new_chrome_exe);
157 }
OLDNEW
« no previous file with comments | « chrome/browser/first_run/upgrade_util_linux.cc ('k') | chrome/browser/first_run/upgrade_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698