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

Side by Side Diff: chrome/test/mini_installer/chrome_helper.py

Issue 565963002: [Installer Test] Update chrome_helper.GetProcessIDAndPathPairs() to use psutil. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleaning up imports and error handling. Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 """Common helper module for working with Chrome's processes and windows.""" 5 """Common helper module for working with Chrome's processes and windows."""
6 6
7 import ctypes 7 import psutil
8 import pywintypes
9 import re 8 import re
10 import win32con
11 import win32gui 9 import win32gui
12 import win32process 10 import win32process
13 11
14 12
15 def GetProcessIDAndPathPairs(): 13 def GetProcessIDAndPathPairs():
16 """Returns a list of 2-tuples of (process id, process path). 14 """Returns a list of 2-tuples of (process id, process path).
17
18 This is needed because psutil is not available on Windows slave machines (see:
19 http://crbug.com/257696).
20 TODO(sukolsak): Use psutil.process_iter() once it becomes available.
21 """ 15 """
22 process_id_and_path_pairs = [] 16 process_id_and_path_pairs = []
23 for process_id in win32process.EnumProcesses(): 17 for process in psutil.process_iter():
24 process_handle = ctypes.windll.kernel32.OpenProcess(
25 win32con.PROCESS_QUERY_INFORMATION | win32con.PROCESS_VM_READ, False,
26 process_id)
27 if not process_handle:
28 continue
29 try: 18 try:
30 process_path = win32process.GetModuleFileNameEx(process_handle, 0) 19 process_id_and_path_pairs.append((process.pid, process.exe))
31 process_id_and_path_pairs.append((process_id, process_path)) 20 except psutil.Error:
32 except pywintypes.error:
33 # It's normal that some processes are not accessible. 21 # It's normal that some processes are not accessible.
34 pass 22 pass
35 return process_id_and_path_pairs 23 return process_id_and_path_pairs
36 24
37 25
38 def GetProcessIDs(process_path): 26 def GetProcessIDs(process_path):
39 """Returns a list of IDs of processes whose path is |process_path|. 27 """Returns a list of IDs of processes whose path is |process_path|.
40 28
41 Args: 29 Args:
42 process_path: The path to the process. 30 process_path: The path to the process.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 process_ids: A list of process IDs. 66 process_ids: A list of process IDs.
79 class_pattern: The regular expression pattern of the window class name. 67 class_pattern: The regular expression pattern of the window class name.
80 68
81 Returns: 69 Returns:
82 A boolean indicating whether such window exists. 70 A boolean indicating whether such window exists.
83 """ 71 """
84 for hwnd in GetWindowHandles(process_ids): 72 for hwnd in GetWindowHandles(process_ids):
85 if re.match(class_pattern, win32gui.GetClassName(hwnd)): 73 if re.match(class_pattern, win32gui.GetClassName(hwnd)):
86 return True 74 return True
87 return False 75 return False
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698