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

Unified Diff: cloud_print/virtual_driver/win/port_monitor/port_monitor.cc

Issue 12218117: Fixed location and name of temporarily files. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
diff --git a/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc b/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
index eab685127a340279a85938f08b33e93644ea5ddd..34884e44349c23e441155319348bfb5376aa6cdf 100644
--- a/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
+++ b/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
@@ -42,6 +42,7 @@ const wchar_t kCloudPrintRegKey[] = L"Software\\Google\\CloudPrint";
const wchar_t kXpsMimeType[] = L"application/vnd.ms-xpsdocument";
+const wchar_t kAppDataDir[] = L"Google\\Cloud Printer";
struct MonitorData {
scoped_ptr<base::AtExitManager> at_exit_manager;
@@ -103,6 +104,29 @@ MONITOR2 g_monitor_2 = {
Monitor2Shutdown
};
+FilePath GetAppDataDir() {
+ FilePath file_path;
+ if (!PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &file_path)) {
+ LOG(ERROR) << "Can't get DIR_LOCAL_APP_DATA_LOW";
+ return FilePath();
+ }
+ return file_path.Append(kAppDataDir);
+}
+
+// Delete files which where not deleted by chrome.
+void DeleteLeakedFiles(const FilePath& dir) {
+ using file_util::FileEnumerator;
+ base::Time delete_before = base::Time::Now() - base::TimeDelta::FromDays(1);
+ FileEnumerator enumerator(dir, false, FileEnumerator::FILES);
+ for (FilePath file_path = enumerator.Next(); !file_path.empty();
+ file_path = enumerator.Next()) {
+ FileEnumerator::FindInfo info;
+ enumerator.GetFindInfo(&info);
+ if (FileEnumerator::GetLastModifiedTime(info) < delete_before)
+ file_util::Delete(file_path, false);
+ }
+}
+
// Attempts to retrieve the title of the specified print job.
// On success returns TRUE and the first title_chars characters of the job title
// are copied into title.
@@ -414,17 +438,15 @@ BOOL WINAPI Monitor2StartDocPort(HANDLE port_handle,
port_data->printer_handle = NULL;
}
FilePath& file_path = port_data->file_path;
- if (!PathService::Get(base::DIR_LOCAL_APP_DATA_LOW, &file_path)) {
- LOG(ERROR) << "Can't get DIR_LOCAL_APP_DATA_LOW";
+ FilePath app_data_dir = GetAppDataDir();
+ if (app_data_dir.empty())
return FALSE;
- }
- file_path = file_path.Append(L"Google\\Cloud Print");
- if (!file_util::CreateDirectory(file_path) ||
- !file_util::CreateTemporaryFileInDir(file_path, &file_path)) {
- LOG(ERROR) << "Can't get create temporary file in " << file_path.value();
+ DeleteLeakedFiles(app_data_dir);
+ if (!file_util::CreateDirectory(app_data_dir) ||
+ !file_util::CreateTemporaryFileInDir(app_data_dir, &file_path)) {
+ LOG(ERROR) << "Can't create temporary file in " << app_data_dir.value();
return FALSE;
}
- file_path = file_path.AddExtension(L"xps");
port_data->file = file_util::OpenFile(file_path, "wb+");
if (port_data->file == NULL) {
LOG(ERROR) << "Error opening file " << file_path.value() << ".";
« 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