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

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: Fix compiler warning: declare base::FileDescriptor a struct, not a class. The struct is put after t… 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 da0cbeb51952054328e755bf465c92f5dcbb4550..a35c9300ea59a8dd8c97d8923dd9265c583d426d 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;
@@ -1925,6 +1927,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);
@@ -1945,6 +1948,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);
@@ -2898,3 +2907,100 @@ bool RequestDirectoryRefreshFunction::RunImpl() {
return true;
}
+
+ZipSelectionFunction::ZipSelectionFunction() {
+}
+
+ZipSelectionFunction::~ZipSelectionFunction() {
+}
+
+bool ZipSelectionFunction::RunImpl() {
+ if (args_->GetSize() < 3) {
+ return false;
+ }
+
+ // First param is the source 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 file_url;
+ selection_urls->GetString(i, &file_url);
+ file_urls.push_back(GURL(file_url));
+ }
+
+ 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 src_dir = iter->file_path;
+
+ // Check if the dir path is under Drive cache directory.
+ // TODO(hshi): support create zip file on Drive (crbug.com/158690).
+ drive::DriveSystemService* system_service =
+ drive::DriveSystemServiceFactory::GetForProfile(profile_);
+ drive::DriveCache* cache = system_service ? system_service->cache() : NULL;
+ if (cache && cache->IsUnderDriveCacheDirectory(src_dir)) {
+ SendResponse(false);
+ return;
+ }
+
+ FilePath dest_file = src_dir.Append(dest_name);
+ std::vector<FilePath> src_relative_paths;
+ for (++iter; iter != files.end(); ++iter) {
+ const FilePath& file_path = iter->file_path;
+
+ // Obtain the relative path of |file_path| under |src_dir|.
+ FilePath relative_path;
+ if (!src_dir.AppendRelativePath(file_path, &relative_path)) {
+ // All files must be under |src_dir| or there is a bug in extension code.
+ SendResponse(false);
+ return;
+ }
+ src_relative_paths.push_back(relative_path);
+ }
+
+ zip_file_creator_ = new ZipFileCreator(this, src_dir, src_relative_paths,
+ dest_file);
+ zip_file_creator_->Start();
+
+ // Keep the refcount until the zipping is complete on utility process.
+ AddRef();
+}
+
+void ZipSelectionFunction::OnZipDone(bool success) {
+ SetResult(new base::FundamentalValue(success));
+ SendResponse(true);
+ 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