diff options
author | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-13 00:12:25 +0000 |
---|---|---|
committer | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-13 00:12:25 +0000 |
commit | 918fc512b73b5b29be02a1e99c7a95265e68f993 (patch) | |
tree | 4e23d7124f92884b46260cacc8d6188aa6ccdcdc /cloud_print | |
parent | df6c07663f36782bc0af9523aee345a0c9b02027 (diff) | |
download | chromium_src-918fc512b73b5b29be02a1e99c7a95265e68f993.zip chromium_src-918fc512b73b5b29be02a1e99c7a95265e68f993.tar.gz chromium_src-918fc512b73b5b29be02a1e99c7a95265e68f993.tar.bz2 |
Fixed location and name of temporarily files.
Don't append XPS extension. Use empty file created by CreateTemporaryFileInDir.
Use AppData subdir same as ProgramFiles subdir.
Delete leaked files.
BUG=172554
Review URL: https://chromiumcodereview.appspot.com/12218117
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182068 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cloud_print')
-rw-r--r-- | cloud_print/virtual_driver/win/port_monitor/port_monitor.cc | 38 |
1 files changed, 30 insertions, 8 deletions
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 eab6851..34884e4 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() << "."; |