| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_manager/private_api_misc.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_misc.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 10 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
| 11 #include "chrome/browser/chromeos/drive/logging.h" | 11 #include "chrome/browser/chromeos/drive/logging.h" |
| 12 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" | 12 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
| 13 #include "chrome/browser/chromeos/settings/cros_settings.h" | 13 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 14 #include "chrome/browser/lifetime/application_lifetime.h" | 14 #include "chrome/browser/lifetime/application_lifetime.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
| 18 #include "content/public/common/page_zoom.h" | 18 #include "content/public/common/page_zoom.h" |
| 19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 20 | 20 |
| 21 namespace file_manager { | 21 namespace extensions { |
| 22 | 22 |
| 23 LogoutUserFunction::LogoutUserFunction() { | 23 LogoutUserFunction::LogoutUserFunction() { |
| 24 } | 24 } |
| 25 | 25 |
| 26 LogoutUserFunction::~LogoutUserFunction() { | 26 LogoutUserFunction::~LogoutUserFunction() { |
| 27 } | 27 } |
| 28 | 28 |
| 29 bool LogoutUserFunction::RunImpl() { | 29 bool LogoutUserFunction::RunImpl() { |
| 30 chrome::AttemptUserExit(); | 30 chrome::AttemptUserExit(); |
| 31 return true; | 31 return true; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 bool ZipSelectionFunction::RunImpl() { | 104 bool ZipSelectionFunction::RunImpl() { |
| 105 if (args_->GetSize() < 3) { | 105 if (args_->GetSize() < 3) { |
| 106 return false; | 106 return false; |
| 107 } | 107 } |
| 108 | 108 |
| 109 // First param is the source directory URL. | 109 // First param is the source directory URL. |
| 110 std::string dir_url; | 110 std::string dir_url; |
| 111 if (!args_->GetString(0, &dir_url) || dir_url.empty()) | 111 if (!args_->GetString(0, &dir_url) || dir_url.empty()) |
| 112 return false; | 112 return false; |
| 113 | 113 |
| 114 base::FilePath src_dir = util::GetLocalPathFromURL( | 114 base::FilePath src_dir = file_manager::util::GetLocalPathFromURL( |
| 115 render_view_host(), profile(), GURL(dir_url)); | 115 render_view_host(), profile(), GURL(dir_url)); |
| 116 if (src_dir.empty()) | 116 if (src_dir.empty()) |
| 117 return false; | 117 return false; |
| 118 | 118 |
| 119 // Second param is the list of selected file URLs. | 119 // Second param is the list of selected file URLs. |
| 120 ListValue* selection_urls = NULL; | 120 ListValue* selection_urls = NULL; |
| 121 args_->GetList(1, &selection_urls); | 121 args_->GetList(1, &selection_urls); |
| 122 if (!selection_urls || !selection_urls->GetSize()) | 122 if (!selection_urls || !selection_urls->GetSize()) |
| 123 return false; | 123 return false; |
| 124 | 124 |
| 125 std::vector<base::FilePath> files; | 125 std::vector<base::FilePath> files; |
| 126 for (size_t i = 0; i < selection_urls->GetSize(); ++i) { | 126 for (size_t i = 0; i < selection_urls->GetSize(); ++i) { |
| 127 std::string file_url; | 127 std::string file_url; |
| 128 selection_urls->GetString(i, &file_url); | 128 selection_urls->GetString(i, &file_url); |
| 129 base::FilePath path = util::GetLocalPathFromURL( | 129 base::FilePath path = file_manager::util::GetLocalPathFromURL( |
| 130 render_view_host(), profile(), GURL(file_url)); | 130 render_view_host(), profile(), GURL(file_url)); |
| 131 if (path.empty()) | 131 if (path.empty()) |
| 132 return false; | 132 return false; |
| 133 files.push_back(path); | 133 files.push_back(path); |
| 134 } | 134 } |
| 135 | 135 |
| 136 // Third param is the name of the output zip file. | 136 // Third param is the name of the output zip file. |
| 137 std::string dest_name; | 137 std::string dest_name; |
| 138 if (!args_->GetString(2, &dest_name) || dest_name.empty()) | 138 if (!args_->GetString(2, &dest_name) || dest_name.empty()) |
| 139 return false; | 139 return false; |
| 140 | 140 |
| 141 // Check if the dir path is under Drive mount point. | 141 // Check if the dir path is under Drive mount point. |
| 142 // TODO(hshi): support create zip file on Drive (crbug.com/158690). | 142 // TODO(hshi): support create zip file on Drive (crbug.com/158690). |
| 143 if (drive::util::IsUnderDriveMountPoint(src_dir)) | 143 if (drive::util::IsUnderDriveMountPoint(src_dir)) |
| 144 return false; | 144 return false; |
| 145 | 145 |
| 146 base::FilePath dest_file = src_dir.Append(dest_name); | 146 base::FilePath dest_file = src_dir.Append(dest_name); |
| 147 std::vector<base::FilePath> src_relative_paths; | 147 std::vector<base::FilePath> src_relative_paths; |
| 148 for (size_t i = 0; i != files.size(); ++i) { | 148 for (size_t i = 0; i != files.size(); ++i) { |
| 149 const base::FilePath& file_path = files[i]; | 149 const base::FilePath& file_path = files[i]; |
| 150 | 150 |
| 151 // Obtain the relative path of |file_path| under |src_dir|. | 151 // Obtain the relative path of |file_path| under |src_dir|. |
| 152 base::FilePath relative_path; | 152 base::FilePath relative_path; |
| 153 if (!src_dir.AppendRelativePath(file_path, &relative_path)) | 153 if (!src_dir.AppendRelativePath(file_path, &relative_path)) |
| 154 return false; | 154 return false; |
| 155 src_relative_paths.push_back(relative_path); | 155 src_relative_paths.push_back(relative_path); |
| 156 } | 156 } |
| 157 | 157 |
| 158 zip_file_creator_ = new ZipFileCreator(this, | 158 zip_file_creator_ = new file_manager::ZipFileCreator(this, |
| 159 src_dir, | 159 src_dir, |
| 160 src_relative_paths, | 160 src_relative_paths, |
| 161 dest_file); | 161 dest_file); |
| 162 | 162 |
| 163 // Keep the refcount until the zipping is complete on utility process. | 163 // Keep the refcount until the zipping is complete on utility process. |
| 164 AddRef(); | 164 AddRef(); |
| 165 | 165 |
| 166 zip_file_creator_->Start(); | 166 zip_file_creator_->Start(); |
| 167 return true; | 167 return true; |
| 168 } | 168 } |
| 169 | 169 |
| 170 void ZipSelectionFunction::OnZipDone(bool success) { | 170 void ZipSelectionFunction::OnZipDone(bool success) { |
| 171 SetResult(new base::FundamentalValue(success)); | 171 SetResult(new base::FundamentalValue(success)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 191 } else if (operation == "reset") { | 191 } else if (operation == "reset") { |
| 192 zoom_type = content::PAGE_ZOOM_RESET; | 192 zoom_type = content::PAGE_ZOOM_RESET; |
| 193 } else { | 193 } else { |
| 194 NOTREACHED(); | 194 NOTREACHED(); |
| 195 return false; | 195 return false; |
| 196 } | 196 } |
| 197 view_host->Zoom(zoom_type); | 197 view_host->Zoom(zoom_type); |
| 198 return true; | 198 return true; |
| 199 } | 199 } |
| 200 | 200 |
| 201 } // namespace file_manager | 201 } // namespace extensions |
| OLD | NEW |