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

Side by Side Diff: win8/delegate_execute/chrome_util.cc

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | « win8/delegate_execute/chrome_util.h ('k') | win8/delegate_execute/command_execute_impl.h » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "win8/delegate_execute/chrome_util.h" 5 #include "win8/delegate_execute/chrome_util.h"
6 6
7 #include <atlbase.h> 7 #include <atlbase.h>
8 #include <shlobj.h> 8 #include <shlobj.h>
9 #include <windows.h> 9 #include <windows.h>
10 10
(...skipping 18 matching lines...) Expand all
29 #if defined(GOOGLE_CHROME_BUILD) 29 #if defined(GOOGLE_CHROME_BUILD)
30 const wchar_t kAppUserModelId[] = L"Chrome"; 30 const wchar_t kAppUserModelId[] = L"Chrome";
31 #else // GOOGLE_CHROME_BUILD 31 #else // GOOGLE_CHROME_BUILD
32 const wchar_t kAppUserModelId[] = L"Chromium"; 32 const wchar_t kAppUserModelId[] = L"Chromium";
33 #endif // GOOGLE_CHROME_BUILD 33 #endif // GOOGLE_CHROME_BUILD
34 34
35 #if defined(GOOGLE_CHROME_BUILD) 35 #if defined(GOOGLE_CHROME_BUILD)
36 36
37 // TODO(grt): These constants live in installer_util. Consider moving them 37 // TODO(grt): These constants live in installer_util. Consider moving them
38 // into common_constants to allow for reuse. 38 // into common_constants to allow for reuse.
39 const FilePath::CharType kNewChromeExe[] = FILE_PATH_LITERAL("new_chrome.exe"); 39 const base::FilePath::CharType kNewChromeExe[] =
40 FILE_PATH_LITERAL("new_chrome.exe");
40 const wchar_t kRenameCommandValue[] = L"cmd"; 41 const wchar_t kRenameCommandValue[] = L"cmd";
41 const wchar_t kChromeAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; 42 const wchar_t kChromeAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
42 const wchar_t kRegPathChromeClient[] = 43 const wchar_t kRegPathChromeClient[] =
43 L"Software\\Google\\Update\\Clients\\" 44 L"Software\\Google\\Update\\Clients\\"
44 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; 45 L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
45 const int kExitCodeRenameSuccessful = 23; 46 const int kExitCodeRenameSuccessful = 23;
46 47
47 // Returns the name of the global event used to detect if |chrome_exe| is in 48 // Returns the name of the global event used to detect if |chrome_exe| is in
48 // use by a browser process. 49 // use by a browser process.
49 // TODO(grt): Move this somewhere central so it can be used by both this 50 // TODO(grt): Move this somewhere central so it can be used by both this
50 // IsBrowserRunning (below) and IsBrowserAlreadyRunning (browser_util_win.cc). 51 // IsBrowserRunning (below) and IsBrowserAlreadyRunning (browser_util_win.cc).
51 string16 GetEventName(const FilePath& chrome_exe) { 52 string16 GetEventName(const base::FilePath& chrome_exe) {
52 static wchar_t const kEventPrefix[] = L"Global\\"; 53 static wchar_t const kEventPrefix[] = L"Global\\";
53 const size_t prefix_len = arraysize(kEventPrefix) - 1; 54 const size_t prefix_len = arraysize(kEventPrefix) - 1;
54 string16 name; 55 string16 name;
55 name.reserve(prefix_len + chrome_exe.value().size()); 56 name.reserve(prefix_len + chrome_exe.value().size());
56 name.assign(kEventPrefix, prefix_len); 57 name.assign(kEventPrefix, prefix_len);
57 name.append(chrome_exe.value()); 58 name.append(chrome_exe.value());
58 std::replace(name.begin() + prefix_len, name.end(), '\\', '!'); 59 std::replace(name.begin() + prefix_len, name.end(), '\\', '!');
59 std::transform(name.begin() + prefix_len, name.end(), 60 std::transform(name.begin() + prefix_len, name.end(),
60 name.begin() + prefix_len, tolower); 61 name.begin() + prefix_len, tolower);
61 return name; 62 return name;
62 } 63 }
63 64
64 // Returns true if |chrome_exe| is in use by a browser process. In this case, 65 // Returns true if |chrome_exe| is in use by a browser process. In this case,
65 // "in use" means past ChromeBrowserMainParts::PreMainMessageLoopRunImpl. 66 // "in use" means past ChromeBrowserMainParts::PreMainMessageLoopRunImpl.
66 bool IsBrowserRunning(const FilePath& chrome_exe) { 67 bool IsBrowserRunning(const base::FilePath& chrome_exe) {
67 base::win::ScopedHandle handle(::OpenEvent( 68 base::win::ScopedHandle handle(::OpenEvent(
68 SYNCHRONIZE, FALSE, GetEventName(chrome_exe).c_str())); 69 SYNCHRONIZE, FALSE, GetEventName(chrome_exe).c_str()));
69 if (handle.IsValid()) 70 if (handle.IsValid())
70 return true; 71 return true;
71 DWORD last_error = ::GetLastError(); 72 DWORD last_error = ::GetLastError();
72 if (last_error != ERROR_FILE_NOT_FOUND) { 73 if (last_error != ERROR_FILE_NOT_FOUND) {
73 AtlTrace("%hs. Failed to open browser event; error %u.\n", __FUNCTION__, 74 AtlTrace("%hs. Failed to open browser event; error %u.\n", __FUNCTION__,
74 last_error); 75 last_error);
75 } 76 }
76 return false; 77 return false;
77 } 78 }
78 79
79 // Returns true if the file new_chrome.exe exists in the same directory as 80 // Returns true if the file new_chrome.exe exists in the same directory as
80 // |chrome_exe|. 81 // |chrome_exe|.
81 bool NewChromeExeExists(const FilePath& chrome_exe) { 82 bool NewChromeExeExists(const base::FilePath& chrome_exe) {
82 FilePath new_chrome_exe(chrome_exe.DirName().Append(kNewChromeExe)); 83 base::FilePath new_chrome_exe(chrome_exe.DirName().Append(kNewChromeExe));
83 return file_util::PathExists(new_chrome_exe); 84 return file_util::PathExists(new_chrome_exe);
84 } 85 }
85 86
86 bool GetUpdateCommand(bool is_per_user, string16* update_command) { 87 bool GetUpdateCommand(bool is_per_user, string16* update_command) {
87 const HKEY root = is_per_user ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; 88 const HKEY root = is_per_user ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
88 base::win::RegKey key(root, kRegPathChromeClient, KEY_QUERY_VALUE); 89 base::win::RegKey key(root, kRegPathChromeClient, KEY_QUERY_VALUE);
89 90
90 return key.ReadValue(kRenameCommandValue, update_command) == ERROR_SUCCESS; 91 return key.ReadValue(kRenameCommandValue, update_command) == ERROR_SUCCESS;
91 } 92 }
92 93
93 #endif // GOOGLE_CHROME_BUILD 94 #endif // GOOGLE_CHROME_BUILD
94 95
95 // TODO(grt): This code also lives in installer_util. Refactor for reuse. 96 // TODO(grt): This code also lives in installer_util. Refactor for reuse.
96 bool IsPerUserInstall(const FilePath& chrome_exe) { 97 bool IsPerUserInstall(const base::FilePath& chrome_exe) {
97 wchar_t program_files_path[MAX_PATH] = {0}; 98 wchar_t program_files_path[MAX_PATH] = {0};
98 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, 99 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL,
99 SHGFP_TYPE_CURRENT, program_files_path))) { 100 SHGFP_TYPE_CURRENT, program_files_path))) {
100 return !StartsWith(chrome_exe.value().c_str(), program_files_path, false); 101 return !StartsWith(chrome_exe.value().c_str(), program_files_path, false);
101 } else { 102 } else {
102 NOTREACHED(); 103 NOTREACHED();
103 } 104 }
104 return true; 105 return true;
105 } 106 }
106 107
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 suffix->reserve(base32_md5.length() + 1); 182 suffix->reserve(base32_md5.length() + 1);
182 suffix->assign(1, L'.'); 183 suffix->assign(1, L'.');
183 suffix->append(base32_md5); 184 suffix->append(base32_md5);
184 return true; 185 return true;
185 } 186 }
186 187
187 } // namespace 188 } // namespace
188 189
189 namespace delegate_execute { 190 namespace delegate_execute {
190 191
191 void UpdateChromeIfNeeded(const FilePath& chrome_exe) { 192 void UpdateChromeIfNeeded(const base::FilePath& chrome_exe) {
192 #if defined(GOOGLE_CHROME_BUILD) 193 #if defined(GOOGLE_CHROME_BUILD)
193 // Nothing to do if a browser is already running or if there's no 194 // Nothing to do if a browser is already running or if there's no
194 // new_chrome.exe. 195 // new_chrome.exe.
195 if (IsBrowserRunning(chrome_exe) || !NewChromeExeExists(chrome_exe)) 196 if (IsBrowserRunning(chrome_exe) || !NewChromeExeExists(chrome_exe))
196 return; 197 return;
197 198
198 base::ProcessHandle process_handle = base::kNullProcessHandle; 199 base::ProcessHandle process_handle = base::kNullProcessHandle;
199 200
200 if (IsPerUserInstall(chrome_exe)) { 201 if (IsPerUserInstall(chrome_exe)) {
201 // Read the update command from the registry. 202 // Read the update command from the registry.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 AtlTrace("%hs. Failed to finalize update with exit code %d.\n", 247 AtlTrace("%hs. Failed to finalize update with exit code %d.\n",
247 __FUNCTION__, exit_code); 248 __FUNCTION__, exit_code);
248 } else { 249 } else {
249 AtlTrace("%hs. Finalized pending update.\n", __FUNCTION__); 250 AtlTrace("%hs. Finalized pending update.\n", __FUNCTION__);
250 } 251 }
251 } 252 }
252 #endif 253 #endif
253 } 254 }
254 255
255 // TODO(gab): This code also lives in shell_util. Refactor for reuse. 256 // TODO(gab): This code also lives in shell_util. Refactor for reuse.
256 string16 GetAppId(const FilePath& chrome_exe) { 257 string16 GetAppId(const base::FilePath& chrome_exe) {
257 string16 app_id(kAppUserModelId); 258 string16 app_id(kAppUserModelId);
258 string16 suffix; 259 string16 suffix;
259 if (IsPerUserInstall(chrome_exe) && 260 if (IsPerUserInstall(chrome_exe) &&
260 !GetUserSpecificRegistrySuffix(&suffix)) { 261 !GetUserSpecificRegistrySuffix(&suffix)) {
261 AtlTrace("%hs. GetUserSpecificRegistrySuffix failed.\n", 262 AtlTrace("%hs. GetUserSpecificRegistrySuffix failed.\n",
262 __FUNCTION__); 263 __FUNCTION__);
263 } 264 }
264 return app_id.append(suffix); 265 return app_id.append(suffix);
265 } 266 }
266 267
267 } // delegate_execute 268 } // delegate_execute
OLDNEW
« no previous file with comments | « win8/delegate_execute/chrome_util.h ('k') | win8/delegate_execute/command_execute_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698