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

Unified Diff: chrome/browser/sync_file_system/drive_file_sync_service.cc

Issue 14075016: Change some snapshot- or temporary-file related changes to use ScopedFile (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
Index: chrome/browser/sync_file_system/drive_file_sync_service.cc
diff --git a/chrome/browser/sync_file_system/drive_file_sync_service.cc b/chrome/browser/sync_file_system/drive_file_sync_service.cc
index c6ba8b7ece970222020a17794755da2b9f375a9a..62c1c2d9cbd4d2a90fdeee8431c68f2f0397d65e 100644
--- a/chrome/browser/sync_file_system/drive_file_sync_service.cc
+++ b/chrome/browser/sync_file_system/drive_file_sync_service.cc
@@ -31,6 +31,7 @@
#include "chrome/common/extensions/extension.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/common/constants.h"
+#include "webkit/blob/scoped_file.h"
#include "webkit/fileapi/file_system_url.h"
#include "webkit/fileapi/syncable/sync_file_metadata.h"
#include "webkit/fileapi/syncable/sync_file_type.h"
@@ -55,22 +56,17 @@ const int64 kPollingDelaySecondsWithNotification = 4 * 60 * 60; // 4 hr
const double kDelayMultiplier = 1.6;
bool CreateTemporaryFile(const base::FilePath& dir_path,
- base::FilePath* temp_file) {
- return file_util::CreateDirectory(dir_path) &&
- file_util::CreateTemporaryFileInDir(dir_path, temp_file);
-}
-
-void DeleteTemporaryFile(const base::FilePath& file_path) {
- if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)) {
- content::BrowserThread::PostTask(
- content::BrowserThread::FILE, FROM_HERE,
- base::Bind(&DeleteTemporaryFile, file_path));
- return;
- }
-
- if (!file_util::Delete(file_path, true))
- LOG(ERROR) << "Leaked temporary file for Sync FileSystem: "
- << file_path.value();
+ webkit_blob::ScopedFile* temp_file) {
+ base::FilePath temp_file_path;
+ const bool success = file_util::CreateDirectory(dir_path) &&
+ file_util::CreateTemporaryFileInDir(dir_path, &temp_file_path);
+ if (!success)
+ return success;
+ *temp_file = webkit_blob::ScopedFile(
+ temp_file_path,
+ webkit_blob::ScopedFile::DELETE_ON_SCOPE_OUT,
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
tzik 2013/04/25 05:06:07 Since this function should be called on IO-allowed
kinuko 2013/04/25 06:02:08 Done.
+ return success;
}
void EmptyStatusCallback(SyncStatusCode status) {}
@@ -159,7 +155,7 @@ struct DriveFileSyncService::ProcessRemoteChangeParam {
DriveMetadata drive_metadata;
SyncFileMetadata local_metadata;
bool metadata_updated;
- base::FilePath temporary_file_path;
+ webkit_blob::ScopedFile temporary_file;
std::string md5_checksum;
SyncAction sync_action;
bool clear_local_changes;
@@ -1625,13 +1621,10 @@ void DriveFileSyncService::DidResolveConflictToLocalChange(
void DriveFileSyncService::DownloadForRemoteSync(
scoped_ptr<ProcessRemoteChangeParam> param) {
- // TODO(tzik): Use ShareableFileReference here after we get thread-safe
- // version of it. crbug.com/162598
- base::FilePath* temporary_file_path = &param->temporary_file_path;
+ webkit_blob::ScopedFile* temporary_file = &param->temporary_file;
content::BrowserThread::PostTaskAndReplyWithResult(
content::BrowserThread::FILE, FROM_HERE,
- base::Bind(&CreateTemporaryFile,
- temporary_file_dir_, temporary_file_path),
+ base::Bind(&CreateTemporaryFile, temporary_file_dir_, temporary_file),
base::Bind(&DriveFileSyncService::DidGetTemporaryFileForDownload,
AsWeakPtr(), base::Passed(&param)));
}
@@ -1644,8 +1637,9 @@ void DriveFileSyncService::DidGetTemporaryFileForDownload(
return;
}
- const base::FilePath& temporary_file_path = param->temporary_file_path;
+ const base::FilePath& temporary_file_path = param->temporary_file.path();
std::string resource_id = param->remote_change.resource_id;
+ DCHECK(!temporary_file_path.empty());
// We should not use the md5 in metadata for FETCH type to avoid the download
// finishes due to NOT_MODIFIED.
@@ -1678,7 +1672,7 @@ void DriveFileSyncService::DidDownloadFileForRemoteSync(
param->drive_metadata.set_md5_checksum(md5_checksum);
const FileChange& change = param->remote_change.change;
- const base::FilePath& temporary_file_path = param->temporary_file_path;
+ const base::FilePath& temporary_file_path = param->temporary_file.path();
const FileSystemURL& url = param->remote_change.url;
remote_change_processor_->ApplyRemoteChange(
change, temporary_file_path, url,
@@ -1779,8 +1773,6 @@ void DriveFileSyncService::FinalizeRemoteSync(
return;
}
- if (!param->temporary_file_path.empty())
- DeleteTemporaryFile(param->temporary_file_path);
NotifyTaskDone(status, param->token.Pass());
if (status == SYNC_STATUS_OK && param->sync_action != SYNC_ACTION_NONE) {
NotifyObserversFileStatusChanged(param->remote_change.url,

Powered by Google App Engine
This is Rietveld 408576698