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

Unified Diff: chrome/browser/extensions/api/developer_private/developer_private_api.cc

Issue 16402016: Copy folder recursively for syncfsToLocalfs export. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: comments Created 7 years, 6 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 | « chrome/browser/extensions/api/developer_private/developer_private_api.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/developer_private/developer_private_api.cc
diff --git a/chrome/browser/extensions/api/developer_private/developer_private_api.cc b/chrome/browser/extensions/api/developer_private/developer_private_api.cc
index 278d1d82a942d4807db6795bb4cbef40279bbe02..2f630d209ce1e2203a1300e73f82a1ec1a329dd4 100644
--- a/chrome/browser/extensions/api/developer_private/developer_private_api.cc
+++ b/chrome/browser/extensions/api/developer_private/developer_private_api.cc
@@ -836,28 +836,33 @@ void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
return;
}
+ pendingCopyOperationsCount_ = 1;
+
content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
ReadSyncFileSystemDirectory,
- this, project_path));
+ this, project_path, project_path.BaseName()));
}
void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
- ReadSyncFileSystemDirectory(const base::FilePath& project_path) {
+ ReadSyncFileSystemDirectory(const base::FilePath& project_path,
+ const base::FilePath& destination_path) {
std::string origin_url(
Extension::GetBaseURLFromExtensionId(extension_id()).spec());
fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL(
GURL(origin_url),
- project_path.BaseName()));
+ destination_path));
context_->operation_runner()->ReadDirectory(
url, base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
- ReadSyncFileSystemDirectoryCb, this, project_path));
+ ReadSyncFileSystemDirectoryCb,
+ this, project_path, destination_path));
}
void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
ReadSyncFileSystemDirectoryCb(
const base::FilePath& project_path,
+ const base::FilePath& destination_path,
base::PlatformFileError status,
const fileapi::FileSystemOperation::FileEntryList& file_list,
bool has_more) {
@@ -867,24 +872,27 @@ void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
return;
}
- // Create an empty project folder if there are no files.
- if (!file_list.size()) {
- content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
- base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
- CreateFolderAndSendResponse,
- this,
- project_path));
- return;
- }
-
- pendingCallbacksCount_ = file_list.size();
+ // We add 1 to the pending copy operations for both files and directories. We
+ // release the directory copy operation once all the files under the directory
+ // are added for copying. We do that to ensure that pendingCopyOperationsCount
+ // does not become zero before all copy operations are finished.
+ // In case the directory happens to be executing the last copy operation it
+ // will call SendResponse to send the response to the API. The pending copy
+ // operations of files are released by the CopyFile function
miket_OOO 2013/06/25 16:44:23 period at end of sentence.
+ pendingCopyOperationsCount_ += file_list.size();
for (size_t i = 0; i < file_list.size(); ++i) {
+ if (file_list[i].is_directory) {
+ ReadSyncFileSystemDirectory(project_path.Append(file_list[i].name),
+ destination_path.Append(file_list[i].name));
+ continue;
+ }
+
std::string origin_url(
Extension::GetBaseURLFromExtensionId(extension_id()).spec());
fileapi::FileSystemURL url(sync_file_system::CreateSyncableFileSystemURL(
GURL(origin_url),
- project_path.BaseName().Append(file_list[i].name)));
+ destination_path.Append(file_list[i].name)));
base::FilePath target_path = project_path;
target_path = target_path.Append(file_list[i].name);
@@ -895,19 +903,19 @@ void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
SnapshotFileCallback,
this,
target_path));
+
}
-}
-void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
- CreateFolderAndSendResponse(const base::FilePath& project_path) {
- if (!(success_ = file_util::CreateDirectory(project_path))) {
- SetError("Error in copying files from sync filesystem.");
+ // Directory copy operation released here.
+ pendingCopyOperationsCount_--;
+
+ if (!pendingCopyOperationsCount_) {
+ content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
+ SendResponse,
+ this,
+ success_));
}
- content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
- base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
- SendResponse,
- this,
- success_));
}
void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::SnapshotFileCallback(
@@ -940,10 +948,10 @@ void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::CopyFile(
if (success_)
file_util::CopyFile(src_path, target_path);
- CHECK(pendingCallbacksCount_ > 0);
- pendingCallbacksCount_--;
+ CHECK(pendingCopyOperationsCount_ > 0);
+ pendingCopyOperationsCount_--;
- if (!pendingCallbacksCount_) {
+ if (!pendingCopyOperationsCount_) {
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
base::Bind(&DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
SendResponse,
@@ -954,7 +962,7 @@ void DeveloperPrivateExportSyncfsFolderToLocalfsFunction::CopyFile(
DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
DeveloperPrivateExportSyncfsFolderToLocalfsFunction()
- : pendingCallbacksCount_(0), success_(true) {}
+ : pendingCopyOperationsCount_(0), success_(true) {}
DeveloperPrivateExportSyncfsFolderToLocalfsFunction::
~DeveloperPrivateExportSyncfsFolderToLocalfsFunction() {}
« no previous file with comments | « chrome/browser/extensions/api/developer_private/developer_private_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698