OLD | NEW |
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 // This file declares util functions for setup project. | 5 // This file declares util functions for setup project. |
6 | 6 |
7 #include "chrome/installer/setup/setup_util.h" | 7 #include "chrome/installer/setup/setup_util.h" |
8 | 8 |
9 #include <windows.h> | 9 #include <windows.h> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/process_util.h" | 15 #include "base/process_util.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/version.h" | 17 #include "base/version.h" |
| 18 #include "base/win/windows_version.h" |
18 #include "chrome/installer/util/copy_tree_work_item.h" | 19 #include "chrome/installer/util/copy_tree_work_item.h" |
19 #include "chrome/installer/util/installation_state.h" | 20 #include "chrome/installer/util/installation_state.h" |
20 #include "chrome/installer/util/installer_state.h" | 21 #include "chrome/installer/util/installer_state.h" |
21 #include "chrome/installer/util/master_preferences.h" | 22 #include "chrome/installer/util/master_preferences.h" |
22 #include "chrome/installer/util/util_constants.h" | 23 #include "chrome/installer/util/util_constants.h" |
23 #include "chrome/installer/util/work_item.h" | 24 #include "chrome/installer/util/work_item.h" |
24 #include "courgette/courgette.h" | 25 #include "courgette/courgette.h" |
25 #include "third_party/bspatch/mbspatch.h" | 26 #include "third_party/bspatch/mbspatch.h" |
26 | 27 |
27 namespace installer { | 28 namespace installer { |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 is_affected = is_uninstall || !product->HasOption(kOptionReadyMode); | 307 is_affected = is_uninstall || !product->HasOption(kOptionReadyMode); |
307 } else { | 308 } else { |
308 is_affected = true; | 309 is_affected = true; |
309 } | 310 } |
310 } | 311 } |
311 | 312 |
312 // Decide among {(1),(2),(3),(4)}. | 313 // Decide among {(1),(2),(3),(4)}. |
313 return is_affected ? !is_uninstall : is_present; | 314 return is_affected ? !is_uninstall : is_present; |
314 } | 315 } |
315 | 316 |
| 317 bool AdjustProcessPriority() { |
| 318 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 319 DWORD priority_class = ::GetPriorityClass(::GetCurrentProcess()); |
| 320 if (priority_class == 0) { |
| 321 PLOG(WARNING) << "Failed to get the process's priority class."; |
| 322 } else if (priority_class == BELOW_NORMAL_PRIORITY_CLASS || |
| 323 priority_class == IDLE_PRIORITY_CLASS) { |
| 324 BOOL result = ::SetPriorityClass(::GetCurrentProcess(), |
| 325 PROCESS_MODE_BACKGROUND_BEGIN); |
| 326 PLOG_IF(WARNING, !result) << "Failed to enter background mode."; |
| 327 return !!result; |
| 328 } |
| 329 } |
| 330 return false; |
| 331 } |
| 332 |
316 ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name) | 333 ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name) |
317 : is_enabled_(false) { | 334 : is_enabled_(false) { |
318 if (!::OpenProcessToken(::GetCurrentProcess(), | 335 if (!::OpenProcessToken(::GetCurrentProcess(), |
319 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, | 336 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, |
320 token_.Receive())) { | 337 token_.Receive())) { |
321 return; | 338 return; |
322 } | 339 } |
323 | 340 |
324 LUID privilege_luid; | 341 LUID privilege_luid; |
325 if (!::LookupPrivilegeValue(NULL, privilege_name, &privilege_luid)) { | 342 if (!::LookupPrivilegeValue(NULL, privilege_name, &privilege_luid)) { |
(...skipping 19 matching lines...) Expand all Loading... |
345 } | 362 } |
346 | 363 |
347 ScopedTokenPrivilege::~ScopedTokenPrivilege() { | 364 ScopedTokenPrivilege::~ScopedTokenPrivilege() { |
348 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { | 365 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { |
349 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, | 366 ::AdjustTokenPrivileges(token_, FALSE, &previous_privileges_, |
350 sizeof(TOKEN_PRIVILEGES), NULL, NULL); | 367 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
351 } | 368 } |
352 } | 369 } |
353 | 370 |
354 } // namespace installer | 371 } // namespace installer |
OLD | NEW |