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

Unified Diff: chrome/browser/chromeos/extensions/file_browser_private_api.cc

Issue 11309014: File manager: support for zipping selected files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Define zip::ZipFileList method to internalize details with handling file lists. Created 8 years, 1 month 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/chromeos/extensions/file_browser_private_api.cc
diff --git a/chrome/browser/chromeos/extensions/file_browser_private_api.cc b/chrome/browser/chromeos/extensions/file_browser_private_api.cc
index 5fc573cc1eefb09b46ad9a06a922050c15dbfe73..604a1fb1aee54edd2a4e22ef4b43e26fc5e0e8ea 100644
--- a/chrome/browser/chromeos/extensions/file_browser_private_api.cc
+++ b/chrome/browser/chromeos/extensions/file_browser_private_api.cc
@@ -33,6 +33,7 @@
#include "chrome/browser/chromeos/drive/drive_webapps_registry.h"
#include "chrome/browser/chromeos/extensions/file_handler_util.h"
#include "chrome/browser/chromeos/extensions/file_manager_util.h"
+#include "chrome/browser/chromeos/extensions/zip_file_creator.h"
#include "chrome/browser/chromeos/system/statistics_provider.h"
#include "chrome/browser/extensions/extension_function_dispatcher.h"
#include "chrome/browser/extensions/extension_process_manager.h"
@@ -82,6 +83,7 @@ using content::ChildProcessSecurityPolicy;
using content::SiteInstance;
using content::WebContents;
using extensions::Extension;
+using extensions::ZipFileCreator;
using file_handler_util::FileTaskExecutor;
using google_apis::InstalledApp;
@@ -1923,6 +1925,7 @@ bool FileDialogStringsFunction::RunImpl() {
SET_STRING(IDS_FILE_BROWSER, COPY_BUTTON_LABEL);
SET_STRING(IDS_FILE_BROWSER, CUT_BUTTON_LABEL);
+ SET_STRING(IDS_FILE_BROWSER, ZIP_SELECTION_BUTTON_LABEL);
SET_STRING(IDS_FILE_BROWSER, OPEN_WITH_BUTTON_LABEL);
@@ -1943,6 +1946,12 @@ bool FileDialogStringsFunction::RunImpl() {
SET_STRING(IDS_FILE_BROWSER, MOVE_TARGET_EXISTS_ERROR);
SET_STRING(IDS_FILE_BROWSER, MOVE_FILESYSTEM_ERROR);
SET_STRING(IDS_FILE_BROWSER, MOVE_UNEXPECTED_ERROR);
+ SET_STRING(IDS_FILE_BROWSER, ZIP_FILE_NAME);
+ SET_STRING(IDS_FILE_BROWSER, ZIP_ITEMS_REMAINING);
+ SET_STRING(IDS_FILE_BROWSER, ZIP_CANCELLED);
+ SET_STRING(IDS_FILE_BROWSER, ZIP_TARGET_EXISTS_ERROR);
+ SET_STRING(IDS_FILE_BROWSER, ZIP_FILESYSTEM_ERROR);
+ SET_STRING(IDS_FILE_BROWSER, ZIP_UNEXPECTED_ERROR);
SET_STRING(IDS_FILE_BROWSER, DELETED_MESSAGE_PLURAL);
SET_STRING(IDS_FILE_BROWSER, DELETED_MESSAGE);
@@ -2896,3 +2905,89 @@ bool RequestDirectoryRefreshFunction::RunImpl() {
return true;
}
+
+ZipSelectionFunction::ZipSelectionFunction() {
+}
+
+ZipSelectionFunction::~ZipSelectionFunction() {
+}
+
+bool ZipSelectionFunction::RunImpl() {
+ if (args_->GetSize() < 3) {
+ return false;
+ }
+
+ // First param is the directory URL.
+ std::string dir_url;
+ if (!args_->GetString(0, &dir_url) || dir_url.empty())
+ return false;
+
+ // Second param is the list of selected file URLs.
+ ListValue* selection_urls = NULL;
+ args_->GetList(1, &selection_urls);
+ if (!selection_urls || !selection_urls->GetSize())
+ return false;
+
+ // Third param is the name of the output zip file.
+ std::string dest_name;
+ if (!args_->GetString(2, &dest_name) || dest_name.empty())
+ return false;
+
+ UrlList file_urls;
+ size_t len = selection_urls->GetSize();
+ file_urls.reserve(len + 1);
+ file_urls.push_back(GURL(dir_url));
+ for (size_t i = 0; i < len; ++i) {
+ std::string virtual_path;
tbarzic 2012/11/06 19:41:25 virtual path is a bit confusing given that selecte
hshi1 2012/11/06 20:43:00 Done.
+ selection_urls->GetString(i, &virtual_path);
+ file_urls.push_back(GURL(virtual_path));
+ }
+
+ GetLocalPathsOnFileThreadAndRunCallbackOnUIThread(
+ file_urls,
+ base::Bind(&ZipSelectionFunction::GetLocalPathsResponseOnUIThread,
+ this,
+ dest_name));
+ return true;
+}
+
+void ZipSelectionFunction::GetLocalPathsResponseOnUIThread(
+ const std::string dest_name,
+ const SelectedFileInfoList& files) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (files.size() <= 1) {
+ NOTREACHED();
+ SendResponse(false);
+ return;
+ }
+
+ SelectedFileInfoList::const_iterator iter = files.begin();
+ FilePath dir_path = iter->file_path;
+ FilePath dest_path = dir_path.Append(dest_name);
+ std::vector<FilePath> file_paths;
+ for (++iter; iter != files.end(); ++iter) {
+ file_paths.push_back(iter->file_path);
+ }
+
+ zip_file_creator_ = new ZipFileCreator(this, dir_path, dest_path, file_paths);
+ if (!BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&ZipFileCreator::Start, zip_file_creator_))) {
+ NOTREACHED();
+ SendResponse(false);
+ return;
+ }
+
+ // Keep the refcount until the zipping is complete on utility process.
+ AddRef();
+}
+
+void ZipSelectionFunction::OnZipSuccess() {
+ SendResponse(true);
+ Release();
+}
+
+void ZipSelectionFunction::OnZipFailure() {
+ SendResponse(false);
+ Release();
+}
« no previous file with comments | « chrome/browser/chromeos/extensions/file_browser_private_api.h ('k') | chrome/browser/chromeos/extensions/zip_file_creator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698