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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" 5 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h"
6 6
7 #include <sys/statvfs.h> 7 #include <sys/statvfs.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <utime.h> 10 #include <utime.h>
(...skipping 15 matching lines...) Expand all
26 #include "base/values.h" 26 #include "base/values.h"
27 #include "chrome/browser/chromeos/cros/cros_library.h" 27 #include "chrome/browser/chromeos/cros/cros_library.h"
28 #include "chrome/browser/chromeos/cros/network_library.h" 28 #include "chrome/browser/chromeos/cros/network_library.h"
29 #include "chrome/browser/chromeos/drive/drive.pb.h" 29 #include "chrome/browser/chromeos/drive/drive.pb.h"
30 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" 30 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h"
31 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" 31 #include "chrome/browser/chromeos/drive/drive_file_system_util.h"
32 #include "chrome/browser/chromeos/drive/drive_system_service.h" 32 #include "chrome/browser/chromeos/drive/drive_system_service.h"
33 #include "chrome/browser/chromeos/drive/drive_webapps_registry.h" 33 #include "chrome/browser/chromeos/drive/drive_webapps_registry.h"
34 #include "chrome/browser/chromeos/extensions/file_handler_util.h" 34 #include "chrome/browser/chromeos/extensions/file_handler_util.h"
35 #include "chrome/browser/chromeos/extensions/file_manager_util.h" 35 #include "chrome/browser/chromeos/extensions/file_manager_util.h"
36 #include "chrome/browser/chromeos/extensions/zip_file_creator.h"
36 #include "chrome/browser/chromeos/system/statistics_provider.h" 37 #include "chrome/browser/chromeos/system/statistics_provider.h"
37 #include "chrome/browser/extensions/extension_function_dispatcher.h" 38 #include "chrome/browser/extensions/extension_function_dispatcher.h"
38 #include "chrome/browser/extensions/extension_process_manager.h" 39 #include "chrome/browser/extensions/extension_process_manager.h"
39 #include "chrome/browser/extensions/extension_service.h" 40 #include "chrome/browser/extensions/extension_service.h"
40 #include "chrome/browser/extensions/extension_tab_util.h" 41 #include "chrome/browser/extensions/extension_tab_util.h"
41 #include "chrome/browser/extensions/process_map.h" 42 #include "chrome/browser/extensions/process_map.h"
42 #include "chrome/browser/google_apis/drive_service_interface.h" 43 #include "chrome/browser/google_apis/drive_service_interface.h"
43 #include "chrome/browser/google_apis/gdata_util.h" 44 #include "chrome/browser/google_apis/gdata_util.h"
44 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 45 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
45 #include "chrome/browser/google_apis/operation_registry.h" 46 #include "chrome/browser/google_apis/operation_registry.h"
(...skipping 29 matching lines...) Expand all
75 #include "webkit/fileapi/file_system_util.h" 76 #include "webkit/fileapi/file_system_util.h"
76 #include "webkit/glue/web_intent_service_data.h" 77 #include "webkit/glue/web_intent_service_data.h"
77 78
78 using chromeos::disks::DiskMountManager; 79 using chromeos::disks::DiskMountManager;
79 using content::BrowserContext; 80 using content::BrowserContext;
80 using content::BrowserThread; 81 using content::BrowserThread;
81 using content::ChildProcessSecurityPolicy; 82 using content::ChildProcessSecurityPolicy;
82 using content::SiteInstance; 83 using content::SiteInstance;
83 using content::WebContents; 84 using content::WebContents;
84 using extensions::Extension; 85 using extensions::Extension;
86 using extensions::ZipFileCreator;
85 using file_handler_util::FileTaskExecutor; 87 using file_handler_util::FileTaskExecutor;
86 using google_apis::InstalledApp; 88 using google_apis::InstalledApp;
87 89
88 namespace { 90 namespace {
89 91
90 // Default icon path for drive docs. 92 // Default icon path for drive docs.
91 const char kDefaultIcon[] = "images/filetype_generic.png"; 93 const char kDefaultIcon[] = "images/filetype_generic.png";
92 const int kPreferredIconSize = 16; 94 const int kPreferredIconSize = 16;
93 95
94 // Error messages. 96 // Error messages.
(...skipping 1821 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 SET_STRING(IDS_FILE_BROWSER, RENAME_PROMPT); 1918 SET_STRING(IDS_FILE_BROWSER, RENAME_PROMPT);
1917 SET_STRING(IDS_FILE_BROWSER, RENAME_BUTTON_LABEL); 1919 SET_STRING(IDS_FILE_BROWSER, RENAME_BUTTON_LABEL);
1918 1920
1919 SET_STRING(IDS_FILE_BROWSER, ERROR_DELETING); 1921 SET_STRING(IDS_FILE_BROWSER, ERROR_DELETING);
1920 SET_STRING(IDS_FILE_BROWSER, DELETE_BUTTON_LABEL); 1922 SET_STRING(IDS_FILE_BROWSER, DELETE_BUTTON_LABEL);
1921 1923
1922 SET_STRING(IDS_FILE_BROWSER, PASTE_BUTTON_LABEL); 1924 SET_STRING(IDS_FILE_BROWSER, PASTE_BUTTON_LABEL);
1923 1925
1924 SET_STRING(IDS_FILE_BROWSER, COPY_BUTTON_LABEL); 1926 SET_STRING(IDS_FILE_BROWSER, COPY_BUTTON_LABEL);
1925 SET_STRING(IDS_FILE_BROWSER, CUT_BUTTON_LABEL); 1927 SET_STRING(IDS_FILE_BROWSER, CUT_BUTTON_LABEL);
1928 SET_STRING(IDS_FILE_BROWSER, ZIP_SELECTION_BUTTON_LABEL);
1926 1929
1927 SET_STRING(IDS_FILE_BROWSER, OPEN_WITH_BUTTON_LABEL); 1930 SET_STRING(IDS_FILE_BROWSER, OPEN_WITH_BUTTON_LABEL);
1928 1931
1929 SET_STRING(IDS_FILE_BROWSER, TRANSFER_ITEMS_REMAINING); 1932 SET_STRING(IDS_FILE_BROWSER, TRANSFER_ITEMS_REMAINING);
1930 SET_STRING(IDS_FILE_BROWSER, TRANSFER_CANCELLED); 1933 SET_STRING(IDS_FILE_BROWSER, TRANSFER_CANCELLED);
1931 SET_STRING(IDS_FILE_BROWSER, TRANSFER_TARGET_EXISTS_ERROR); 1934 SET_STRING(IDS_FILE_BROWSER, TRANSFER_TARGET_EXISTS_ERROR);
1932 SET_STRING(IDS_FILE_BROWSER, TRANSFER_FILESYSTEM_ERROR); 1935 SET_STRING(IDS_FILE_BROWSER, TRANSFER_FILESYSTEM_ERROR);
1933 SET_STRING(IDS_FILE_BROWSER, TRANSFER_UNEXPECTED_ERROR); 1936 SET_STRING(IDS_FILE_BROWSER, TRANSFER_UNEXPECTED_ERROR);
1934 SET_STRING(IDS_FILE_BROWSER, COPY_FILE_NAME); 1937 SET_STRING(IDS_FILE_BROWSER, COPY_FILE_NAME);
1935 SET_STRING(IDS_FILE_BROWSER, COPY_ITEMS_REMAINING); 1938 SET_STRING(IDS_FILE_BROWSER, COPY_ITEMS_REMAINING);
1936 SET_STRING(IDS_FILE_BROWSER, COPY_CANCELLED); 1939 SET_STRING(IDS_FILE_BROWSER, COPY_CANCELLED);
1937 SET_STRING(IDS_FILE_BROWSER, COPY_TARGET_EXISTS_ERROR); 1940 SET_STRING(IDS_FILE_BROWSER, COPY_TARGET_EXISTS_ERROR);
1938 SET_STRING(IDS_FILE_BROWSER, COPY_FILESYSTEM_ERROR); 1941 SET_STRING(IDS_FILE_BROWSER, COPY_FILESYSTEM_ERROR);
1939 SET_STRING(IDS_FILE_BROWSER, COPY_UNEXPECTED_ERROR); 1942 SET_STRING(IDS_FILE_BROWSER, COPY_UNEXPECTED_ERROR);
1940 SET_STRING(IDS_FILE_BROWSER, MOVE_FILE_NAME); 1943 SET_STRING(IDS_FILE_BROWSER, MOVE_FILE_NAME);
1941 SET_STRING(IDS_FILE_BROWSER, MOVE_ITEMS_REMAINING); 1944 SET_STRING(IDS_FILE_BROWSER, MOVE_ITEMS_REMAINING);
1942 SET_STRING(IDS_FILE_BROWSER, MOVE_CANCELLED); 1945 SET_STRING(IDS_FILE_BROWSER, MOVE_CANCELLED);
1943 SET_STRING(IDS_FILE_BROWSER, MOVE_TARGET_EXISTS_ERROR); 1946 SET_STRING(IDS_FILE_BROWSER, MOVE_TARGET_EXISTS_ERROR);
1944 SET_STRING(IDS_FILE_BROWSER, MOVE_FILESYSTEM_ERROR); 1947 SET_STRING(IDS_FILE_BROWSER, MOVE_FILESYSTEM_ERROR);
1945 SET_STRING(IDS_FILE_BROWSER, MOVE_UNEXPECTED_ERROR); 1948 SET_STRING(IDS_FILE_BROWSER, MOVE_UNEXPECTED_ERROR);
1949 SET_STRING(IDS_FILE_BROWSER, ZIP_FILE_NAME);
1950 SET_STRING(IDS_FILE_BROWSER, ZIP_ITEMS_REMAINING);
1951 SET_STRING(IDS_FILE_BROWSER, ZIP_CANCELLED);
1952 SET_STRING(IDS_FILE_BROWSER, ZIP_TARGET_EXISTS_ERROR);
1953 SET_STRING(IDS_FILE_BROWSER, ZIP_FILESYSTEM_ERROR);
1954 SET_STRING(IDS_FILE_BROWSER, ZIP_UNEXPECTED_ERROR);
1946 1955
1947 SET_STRING(IDS_FILE_BROWSER, DELETED_MESSAGE_PLURAL); 1956 SET_STRING(IDS_FILE_BROWSER, DELETED_MESSAGE_PLURAL);
1948 SET_STRING(IDS_FILE_BROWSER, DELETED_MESSAGE); 1957 SET_STRING(IDS_FILE_BROWSER, DELETED_MESSAGE);
1949 SET_STRING(IDS_FILE_BROWSER, UNDO_DELETE); 1958 SET_STRING(IDS_FILE_BROWSER, UNDO_DELETE);
1950 1959
1951 SET_STRING(IDS_FILE_BROWSER, CANCEL_LABEL); 1960 SET_STRING(IDS_FILE_BROWSER, CANCEL_LABEL);
1952 SET_STRING(IDS_FILE_BROWSER, OPEN_LABEL); 1961 SET_STRING(IDS_FILE_BROWSER, OPEN_LABEL);
1953 SET_STRING(IDS_FILE_BROWSER, SAVE_LABEL); 1962 SET_STRING(IDS_FILE_BROWSER, SAVE_LABEL);
1954 SET_STRING(IDS_FILE_BROWSER, OK_LABEL); 1963 SET_STRING(IDS_FILE_BROWSER, OK_LABEL);
1955 1964
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
2889 drive::DriveSystemServiceFactory::GetForProfile(profile_); 2898 drive::DriveSystemServiceFactory::GetForProfile(profile_);
2890 // |system_service| is NULL if Drive is disabled. 2899 // |system_service| is NULL if Drive is disabled.
2891 if (!system_service || !system_service->file_system()) 2900 if (!system_service || !system_service->file_system())
2892 return false; 2901 return false;
2893 2902
2894 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); 2903 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string));
2895 system_service->file_system()->RequestDirectoryRefresh(directory_path); 2904 system_service->file_system()->RequestDirectoryRefresh(directory_path);
2896 2905
2897 return true; 2906 return true;
2898 } 2907 }
2908
2909 ZipSelectionFunction::ZipSelectionFunction() {
2910 }
2911
2912 ZipSelectionFunction::~ZipSelectionFunction() {
2913 }
2914
2915 bool ZipSelectionFunction::RunImpl() {
2916 if (args_->GetSize() < 3) {
2917 return false;
2918 }
2919
2920 // First param is the directory URL.
2921 std::string dir_url;
2922 if (!args_->GetString(0, &dir_url) || dir_url.empty())
2923 return false;
2924
2925 // Second param is the list of selected file URLs.
2926 ListValue* selection_urls = NULL;
2927 args_->GetList(1, &selection_urls);
2928 if (!selection_urls || !selection_urls->GetSize())
2929 return false;
2930
2931 // Third param is the name of the output zip file.
2932 std::string dest_name;
2933 if (!args_->GetString(2, &dest_name) || dest_name.empty())
2934 return false;
2935
2936 UrlList file_urls;
2937 size_t len = selection_urls->GetSize();
2938 file_urls.reserve(len + 1);
2939 file_urls.push_back(GURL(dir_url));
2940 for (size_t i = 0; i < len; ++i) {
2941 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.
2942 selection_urls->GetString(i, &virtual_path);
2943 file_urls.push_back(GURL(virtual_path));
2944 }
2945
2946 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread(
2947 file_urls,
2948 base::Bind(&ZipSelectionFunction::GetLocalPathsResponseOnUIThread,
2949 this,
2950 dest_name));
2951 return true;
2952 }
2953
2954 void ZipSelectionFunction::GetLocalPathsResponseOnUIThread(
2955 const std::string dest_name,
2956 const SelectedFileInfoList& files) {
2957 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2958 if (files.size() <= 1) {
2959 NOTREACHED();
2960 SendResponse(false);
2961 return;
2962 }
2963
2964 SelectedFileInfoList::const_iterator iter = files.begin();
2965 FilePath dir_path = iter->file_path;
2966 FilePath dest_path = dir_path.Append(dest_name);
2967 std::vector<FilePath> file_paths;
2968 for (++iter; iter != files.end(); ++iter) {
2969 file_paths.push_back(iter->file_path);
2970 }
2971
2972 zip_file_creator_ = new ZipFileCreator(this, dir_path, dest_path, file_paths);
2973 if (!BrowserThread::PostTask(
2974 BrowserThread::FILE, FROM_HERE,
2975 base::Bind(&ZipFileCreator::Start, zip_file_creator_))) {
2976 NOTREACHED();
2977 SendResponse(false);
2978 return;
2979 }
2980
2981 // Keep the refcount until the zipping is complete on utility process.
2982 AddRef();
2983 }
2984
2985 void ZipSelectionFunction::OnZipSuccess() {
2986 SendResponse(true);
2987 Release();
2988 }
2989
2990 void ZipSelectionFunction::OnZipFailure() {
2991 SendResponse(false);
2992 Release();
2993 }
OLDNEW
« 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