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

Side by Side Diff: cloud_print/virtual_driver/win/port_monitor/port_monitor.cc

Issue 12294008: Fix more remaining FilePath -> base::FilePath. (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
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 "cloud_print/virtual_driver/win/port_monitor/port_monitor.h" 5 #include "cloud_print/virtual_driver/win/port_monitor/port_monitor.h"
6 6
7 #include <lmcons.h> 7 #include <lmcons.h>
8 #include <shellapi.h> 8 #include <shellapi.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 #include <strsafe.h> 10 #include <strsafe.h>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 printer_handle = NULL; 60 printer_handle = NULL;
61 } 61 }
62 if (file) { 62 if (file) {
63 file_util::CloseFile(file); 63 file_util::CloseFile(file);
64 file = NULL; 64 file = NULL;
65 } 65 }
66 } 66 }
67 DWORD job_id; 67 DWORD job_id;
68 HANDLE printer_handle; 68 HANDLE printer_handle;
69 FILE* file; 69 FILE* file;
70 FilePath file_path; 70 base::FilePath file_path;
71 }; 71 };
72 72
73 typedef struct { 73 typedef struct {
74 ACCESS_MASK granted_access; 74 ACCESS_MASK granted_access;
75 } XcvUiData; 75 } XcvUiData;
76 76
77 77
78 MONITORUI g_monitor_ui = { 78 MONITORUI g_monitor_ui = {
79 sizeof(MONITORUI), 79 sizeof(MONITORUI),
80 MonitorUiAddPortUi, 80 MonitorUiAddPortUi,
(...skipping 16 matching lines...) Expand all
97 NULL, // ConfigurePort is not supported. 97 NULL, // ConfigurePort is not supported.
98 NULL, // DeletePort is not supported. 98 NULL, // DeletePort is not supported.
99 NULL, 99 NULL,
100 NULL, // SetPortTimeOuts is not supported. 100 NULL, // SetPortTimeOuts is not supported.
101 Monitor2XcvOpenPort, 101 Monitor2XcvOpenPort,
102 Monitor2XcvDataPort, 102 Monitor2XcvDataPort,
103 Monitor2XcvClosePort, 103 Monitor2XcvClosePort,
104 Monitor2Shutdown 104 Monitor2Shutdown
105 }; 105 };
106 106
107 FilePath GetAppDataDir() { 107 base::FilePath GetAppDataDir() {
108 FilePath file_path; 108 base::FilePath file_path;
109 if (!PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &file_path)) { 109 if (!PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &file_path)) {
110 LOG(ERROR) << "Can't get DIR_LOCAL_APP_DATA_LOW"; 110 LOG(ERROR) << "Can't get DIR_LOCAL_APP_DATA_LOW";
111 return FilePath(); 111 return base::FilePath();
112 } 112 }
113 return file_path.Append(kAppDataDir); 113 return file_path.Append(kAppDataDir);
114 } 114 }
115 115
116 // Delete files which where not deleted by chrome. 116 // Delete files which where not deleted by chrome.
117 void DeleteLeakedFiles(const FilePath& dir) { 117 void DeleteLeakedFiles(const base::FilePath& dir) {
118 using file_util::FileEnumerator; 118 using file_util::FileEnumerator;
119 base::Time delete_before = base::Time::Now() - base::TimeDelta::FromDays(1); 119 base::Time delete_before = base::Time::Now() - base::TimeDelta::FromDays(1);
120 FileEnumerator enumerator(dir, false, FileEnumerator::FILES); 120 FileEnumerator enumerator(dir, false, FileEnumerator::FILES);
121 for (FilePath file_path = enumerator.Next(); !file_path.empty(); 121 for (base::FilePath file_path = enumerator.Next(); !file_path.empty();
122 file_path = enumerator.Next()) { 122 file_path = enumerator.Next()) {
123 FileEnumerator::FindInfo info; 123 FileEnumerator::FindInfo info;
124 enumerator.GetFindInfo(&info); 124 enumerator.GetFindInfo(&info);
125 if (FileEnumerator::GetLastModifiedTime(info) < delete_before) 125 if (FileEnumerator::GetLastModifiedTime(info) < delete_before)
126 file_util::Delete(file_path, false); 126 file_util::Delete(file_path, false);
127 } 127 }
128 } 128 }
129 129
130 // Attempts to retrieve the title of the specified print job. 130 // Attempts to retrieve the title of the specified print job.
131 // On success returns TRUE and the first title_chars characters of the job title 131 // On success returns TRUE and the first title_chars characters of the job title
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 primary_token)) { 186 primary_token)) {
187 LOG(ERROR) << "Unable to get primary thread token."; 187 LOG(ERROR) << "Unable to get primary thread token.";
188 return false; 188 return false;
189 } 189 }
190 return true; 190 return true;
191 } 191 }
192 192
193 // Launches the Cloud Print dialog in Chrome. 193 // Launches the Cloud Print dialog in Chrome.
194 // xps_path references a file to print. 194 // xps_path references a file to print.
195 // job_title is the title to be used for the resulting print job. 195 // job_title is the title to be used for the resulting print job.
196 bool LaunchPrintDialog(const FilePath& xps_path, 196 bool LaunchPrintDialog(const base::FilePath& xps_path,
197 const string16& job_title) { 197 const string16& job_title) {
198 HANDLE token = NULL; 198 HANDLE token = NULL;
199 if (!GetUserToken(&token)) { 199 if (!GetUserToken(&token)) {
200 LOG(ERROR) << "Unable to get user token."; 200 LOG(ERROR) << "Unable to get user token.";
201 return false; 201 return false;
202 } 202 }
203 base::win::ScopedHandle primary_token_scoped(token); 203 base::win::ScopedHandle primary_token_scoped(token);
204 204
205 FilePath chrome_path = GetChromeExePath(); 205 base::FilePath chrome_path = GetChromeExePath();
206 if (chrome_path.empty()) { 206 if (chrome_path.empty()) {
207 LOG(ERROR) << "Unable to get chrome exe path."; 207 LOG(ERROR) << "Unable to get chrome exe path.";
208 return false; 208 return false;
209 } 209 }
210 210
211 CommandLine command_line(chrome_path); 211 CommandLine command_line(chrome_path);
212 212
213 FilePath chrome_profile = GetChromeProfilePath(); 213 base::FilePath chrome_profile = GetChromeProfilePath();
214 if (!chrome_profile.empty()) { 214 if (!chrome_profile.empty()) {
215 command_line.AppendSwitchPath(switches::kCloudPrintUserDataDir, 215 command_line.AppendSwitchPath(switches::kCloudPrintUserDataDir,
216 chrome_profile); 216 chrome_profile);
217 } 217 }
218 218
219 command_line.AppendSwitchPath(switches::kCloudPrintFile, 219 command_line.AppendSwitchPath(switches::kCloudPrintFile,
220 xps_path); 220 xps_path);
221 command_line.AppendSwitchNative(switches::kCloudPrintFileType, 221 command_line.AppendSwitchNative(switches::kCloudPrintFileType,
222 kXpsMimeType); 222 kXpsMimeType);
223 command_line.AppendSwitchNative(switches::kCloudPrintJobTitle, 223 command_line.AppendSwitchNative(switches::kCloudPrintJobTitle,
(...skipping 12 matching lines...) Expand all
236 void LaunchChromeDownloadPage() { 236 void LaunchChromeDownloadPage() {
237 if (kIsUnittest) 237 if (kIsUnittest)
238 return; 238 return;
239 HANDLE token = NULL; 239 HANDLE token = NULL;
240 if (!GetUserToken(&token)) { 240 if (!GetUserToken(&token)) {
241 LOG(ERROR) << "Unable to get user token."; 241 LOG(ERROR) << "Unable to get user token.";
242 return; 242 return;
243 } 243 }
244 base::win::ScopedHandle token_scoped(token); 244 base::win::ScopedHandle token_scoped(token);
245 245
246 FilePath ie_path; 246 base::FilePath ie_path;
247 PathService::Get(base::DIR_PROGRAM_FILESX86, &ie_path); 247 PathService::Get(base::DIR_PROGRAM_FILESX86, &ie_path);
248 ie_path = ie_path.Append(kIePath); 248 ie_path = ie_path.Append(kIePath);
249 CommandLine command_line(ie_path); 249 CommandLine command_line(ie_path);
250 command_line.AppendArg(kChromeInstallUrl); 250 command_line.AppendArg(kChromeInstallUrl);
251 251
252 base::LaunchOptions options; 252 base::LaunchOptions options;
253 options.as_user = token_scoped; 253 options.as_user = token_scoped;
254 base::LaunchProcess(command_line, options, NULL); 254 base::LaunchProcess(command_line, options, NULL);
255 } 255 }
256 256
(...skipping 19 matching lines...) Expand all
276 return false; 276 return false;
277 } 277 }
278 if (session_id == 0) { 278 if (session_id == 0) {
279 return false; 279 return false;
280 } 280 }
281 } 281 }
282 return true; 282 return true;
283 } 283 }
284 } // namespace 284 } // namespace
285 285
286 FilePath ReadPathFromRegistry(HKEY root, const wchar_t* path_name) { 286 base::FilePath ReadPathFromRegistry(HKEY root, const wchar_t* path_name) {
287 base::win::RegKey gcp_key(HKEY_CURRENT_USER, kCloudPrintRegKey, KEY_READ); 287 base::win::RegKey gcp_key(HKEY_CURRENT_USER, kCloudPrintRegKey, KEY_READ);
288 string16 data; 288 string16 data;
289 if (SUCCEEDED(gcp_key.ReadValue(path_name, &data)) && 289 if (SUCCEEDED(gcp_key.ReadValue(path_name, &data)) &&
290 file_util::PathExists(FilePath(data))) { 290 file_util::PathExists(base::FilePath(data))) {
291 return FilePath(data); 291 return base::FilePath(data);
292 } 292 }
293 return FilePath(); 293 return base::FilePath();
294 } 294 }
295 295
296 FilePath ReadPathFromAnyRegistry(const wchar_t* path_name) { 296 base::FilePath ReadPathFromAnyRegistry(const wchar_t* path_name) {
297 FilePath result = ReadPathFromRegistry(HKEY_CURRENT_USER, path_name); 297 base::FilePath result = ReadPathFromRegistry(HKEY_CURRENT_USER, path_name);
298 if (!result.empty()) 298 if (!result.empty())
299 return result; 299 return result;
300 return ReadPathFromRegistry(HKEY_LOCAL_MACHINE, path_name); 300 return ReadPathFromRegistry(HKEY_LOCAL_MACHINE, path_name);
301 } 301 }
302 302
303 FilePath GetChromeExePath() { 303 base::FilePath GetChromeExePath() {
304 FilePath path = ReadPathFromAnyRegistry(kChromeExePathRegValue); 304 base::FilePath path = ReadPathFromAnyRegistry(kChromeExePathRegValue);
305 if (!path.empty()) 305 if (!path.empty())
306 return path; 306 return path;
307 return chrome_launcher_support::GetAnyChromePath(); 307 return chrome_launcher_support::GetAnyChromePath();
308 } 308 }
309 309
310 FilePath GetChromeProfilePath() { 310 base::FilePath GetChromeProfilePath() {
311 FilePath path = ReadPathFromAnyRegistry(kChromeProfilePathRegValue); 311 base::FilePath path = ReadPathFromAnyRegistry(kChromeProfilePathRegValue);
312 if (!path.empty() && file_util::DirectoryExists(path)) 312 if (!path.empty() && file_util::DirectoryExists(path))
313 return path; 313 return path;
314 return FilePath(); 314 return base::FilePath();
315 } 315 }
316 316
317 BOOL WINAPI Monitor2EnumPorts(HANDLE, 317 BOOL WINAPI Monitor2EnumPorts(HANDLE,
318 wchar_t*, 318 wchar_t*,
319 DWORD level, 319 DWORD level,
320 BYTE* ports, 320 BYTE* ports,
321 DWORD ports_size, 321 DWORD ports_size,
322 DWORD* needed_bytes, 322 DWORD* needed_bytes,
323 DWORD* returned) { 323 DWORD* returned) {
324 if (needed_bytes == NULL) { 324 if (needed_bytes == NULL) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 PortData* port_data = reinterpret_cast<PortData*>(port_handle); 430 PortData* port_data = reinterpret_cast<PortData*>(port_handle);
431 port_data->job_id = job_id; 431 port_data->job_id = job_id;
432 if (!OpenPrinter(printer_name, &(port_data->printer_handle), NULL)) { 432 if (!OpenPrinter(printer_name, &(port_data->printer_handle), NULL)) {
433 LOG(WARNING) << "Unable to open printer " << printer_name << "."; 433 LOG(WARNING) << "Unable to open printer " << printer_name << ".";
434 // We can continue without a handle to the printer. 434 // We can continue without a handle to the printer.
435 // It just means we can't get the job title or tell the spooler that 435 // It just means we can't get the job title or tell the spooler that
436 // the print job is complete. 436 // the print job is complete.
437 // This is the normal flow during a unit test. 437 // This is the normal flow during a unit test.
438 port_data->printer_handle = NULL; 438 port_data->printer_handle = NULL;
439 } 439 }
440 FilePath& file_path = port_data->file_path; 440 base::FilePath& file_path = port_data->file_path;
441 FilePath app_data_dir = GetAppDataDir(); 441 base::FilePath app_data_dir = GetAppDataDir();
442 if (app_data_dir.empty()) 442 if (app_data_dir.empty())
443 return FALSE; 443 return FALSE;
444 DeleteLeakedFiles(app_data_dir); 444 DeleteLeakedFiles(app_data_dir);
445 if (!file_util::CreateDirectory(app_data_dir) || 445 if (!file_util::CreateDirectory(app_data_dir) ||
446 !file_util::CreateTemporaryFileInDir(app_data_dir, &file_path)) { 446 !file_util::CreateTemporaryFileInDir(app_data_dir, &file_path)) {
447 LOG(ERROR) << "Can't create temporary file in " << app_data_dir.value(); 447 LOG(ERROR) << "Can't create temporary file in " << app_data_dir.value();
448 return FALSE; 448 return FALSE;
449 } 449 }
450 port_data->file = file_util::OpenFile(file_path, "wb+"); 450 port_data->file = file_util::OpenFile(file_path, "wb+");
451 if (port_data->file == NULL) { 451 if (port_data->file == NULL) {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 if ((xcv_data->granted_access & SERVER_ACCESS_ADMINISTER) == 0) { 579 if ((xcv_data->granted_access & SERVER_ACCESS_ADMINISTER) == 0) {
580 return ERROR_ACCESS_DENIED; 580 return ERROR_ACCESS_DENIED;
581 } 581 }
582 if (output_data == NULL || output_data_bytes == 0) { 582 if (output_data == NULL || output_data_bytes == 0) {
583 return ERROR_INVALID_PARAMETER; 583 return ERROR_INVALID_PARAMETER;
584 } 584 }
585 // We don't handle AddPort or DeletePort since we don't support 585 // We don't handle AddPort or DeletePort since we don't support
586 // dynamic creation of ports. 586 // dynamic creation of ports.
587 if (lstrcmp(L"MonitorUI", data_name) == 0) { 587 if (lstrcmp(L"MonitorUI", data_name) == 0) {
588 DWORD dll_path_len = 0; 588 DWORD dll_path_len = 0;
589 FilePath dll_path(GetPortMonitorDllName()); 589 base::FilePath dll_path(GetPortMonitorDllName());
590 dll_path_len = static_cast<DWORD>(dll_path.value().length()); 590 dll_path_len = static_cast<DWORD>(dll_path.value().length());
591 if (output_data_bytes_needed != NULL) { 591 if (output_data_bytes_needed != NULL) {
592 *output_data_bytes_needed = dll_path_len; 592 *output_data_bytes_needed = dll_path_len;
593 } 593 }
594 if (output_data_bytes < dll_path_len) { 594 if (output_data_bytes < dll_path_len) {
595 return ERROR_INSUFFICIENT_BUFFER; 595 return ERROR_INSUFFICIENT_BUFFER;
596 } else { 596 } else {
597 ret_val = StringCbCopy(reinterpret_cast<wchar_t*>(output_data), 597 ret_val = StringCbCopy(reinterpret_cast<wchar_t*>(output_data),
598 output_data_bytes, 598 output_data_bytes,
599 dll_path.value().c_str()); 599 dll_path.value().c_str());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 SetLastError(ERROR_INVALID_PARAMETER); 645 SetLastError(ERROR_INVALID_PARAMETER);
646 return NULL; 646 return NULL;
647 } 647 }
648 return &cloud_print::g_monitor_2; 648 return &cloud_print::g_monitor_2;
649 } 649 }
650 650
651 MONITORUI* WINAPI InitializePrintMonitorUI(void) { 651 MONITORUI* WINAPI InitializePrintMonitorUI(void) {
652 return &cloud_print::g_monitor_ui; 652 return &cloud_print::g_monitor_ui;
653 } 653 }
654 654
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698