| OLD | NEW |
| 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/extensions/api/file_handlers/app_file_handler_util.h" | 5 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" |
| 6 | 6 |
| 7 #include "apps/browser/file_handler_util.h" | 7 #include "apps/browser/file_handler_util.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/child_process_security_policy.h" | 12 #include "content/public/browser/child_process_security_policy.h" |
| 13 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
| 14 #include "extensions/browser/extension_prefs.h" | 14 #include "extensions/browser/extension_prefs.h" |
| 15 #include "net/base/mime_util.h" | 15 #include "net/base/mime_util.h" |
| 16 #include "webkit/browser/fileapi/isolated_context.h" | 16 #include "webkit/browser/fileapi/isolated_context.h" |
| 17 #include "webkit/common/fileapi/file_system_mount_option.h" | 17 #include "webkit/common/fileapi/file_system_mount_option.h" |
| 18 #include "webkit/common/fileapi/file_system_types.h" | 18 #include "webkit/common/fileapi/file_system_types.h" |
| 19 | 19 |
| 20 #if defined(OS_CHROMEOS) | 20 #if defined(OS_CHROMEOS) |
| 21 #include "chrome/browser/chromeos/drive/file_system_util.h" | 21 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 using apps::file_handler_util::GrantedFileEntry; | 24 using apps::file_handler_util::GrantedFileEntry; |
| 25 | 25 |
| 26 namespace extensions { | 26 namespace extensions { |
| 27 | 27 |
| 28 namespace app_file_handler_util { | 28 namespace app_file_handler_util { |
| 29 | 29 |
| 30 const char kInvalidParameters[] = "Invalid parameters"; | 30 const char kInvalidParameters[] = "Invalid parameters"; |
| 31 const char kSecurityError[] = "Security error"; | 31 const char kSecurityError[] = "Security error"; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // calls the success or failure callback. | 109 // calls the success or failure callback. |
| 110 void TaskDone(); | 110 void TaskDone(); |
| 111 | 111 |
| 112 // Reports an error in completing a work item. This may be called more than | 112 // Reports an error in completing a work item. This may be called more than |
| 113 // once, but only the last message will be retained. | 113 // once, but only the last message will be retained. |
| 114 void Error(const base::FilePath& error_path); | 114 void Error(const base::FilePath& error_path); |
| 115 | 115 |
| 116 void CheckLocalWritableFiles(); | 116 void CheckLocalWritableFiles(); |
| 117 | 117 |
| 118 #if defined(OS_CHROMEOS) | 118 #if defined(OS_CHROMEOS) |
| 119 void CheckRemoteWritableFile(const base::FilePath& remote_path, | 119 void SpecialPathCheckDone(const base::FilePath& path, bool success); |
| 120 drive::FileError error, | |
| 121 const base::FilePath& local_path); | |
| 122 void RemoteCheckDone(const base::FilePath& remote_path, | |
| 123 drive::FileError error); | |
| 124 #endif | 120 #endif |
| 125 | 121 |
| 126 const std::vector<base::FilePath> paths_; | 122 const std::vector<base::FilePath> paths_; |
| 127 Profile* profile_; | 123 Profile* profile_; |
| 128 const bool is_directory_; | 124 const bool is_directory_; |
| 129 int outstanding_tasks_; | 125 int outstanding_tasks_; |
| 130 base::FilePath error_path_; | 126 base::FilePath error_path_; |
| 131 base::Closure on_success_; | 127 base::Closure on_success_; |
| 132 base::Callback<void(const base::FilePath&)> on_failure_; | 128 base::Callback<void(const base::FilePath&)> on_failure_; |
| 133 }; | 129 }; |
| 134 | 130 |
| 135 WritableFileChecker::WritableFileChecker( | 131 WritableFileChecker::WritableFileChecker( |
| 136 const std::vector<base::FilePath>& paths, | 132 const std::vector<base::FilePath>& paths, |
| 137 Profile* profile, | 133 Profile* profile, |
| 138 bool is_directory, | 134 bool is_directory, |
| 139 const base::Closure& on_success, | 135 const base::Closure& on_success, |
| 140 const base::Callback<void(const base::FilePath&)>& on_failure) | 136 const base::Callback<void(const base::FilePath&)>& on_failure) |
| 141 : paths_(paths), | 137 : paths_(paths), |
| 142 profile_(profile), | 138 profile_(profile), |
| 143 is_directory_(is_directory), | 139 is_directory_(is_directory), |
| 144 outstanding_tasks_(1), | 140 outstanding_tasks_(1), |
| 145 on_success_(on_success), | 141 on_success_(on_success), |
| 146 on_failure_(on_failure) {} | 142 on_failure_(on_failure) {} |
| 147 | 143 |
| 148 void WritableFileChecker::Check() { | 144 void WritableFileChecker::Check() { |
| 149 #if defined(OS_CHROMEOS) | 145 #if defined(OS_CHROMEOS) |
| 150 if (drive::util::IsUnderDriveMountPoint(paths_[0])) { | 146 if (file_manager::util::IsUnderSpecialPath(profile_, paths_[0])) { |
| 151 outstanding_tasks_ = paths_.size(); | 147 outstanding_tasks_ = paths_.size(); |
| 152 for (std::vector<base::FilePath>::const_iterator it = paths_.begin(); | 148 for (std::vector<base::FilePath>::const_iterator it = paths_.begin(); |
| 153 it != paths_.end(); | 149 it != paths_.end(); |
| 154 ++it) { | 150 ++it) { |
| 155 DCHECK(drive::util::IsUnderDriveMountPoint(*it)); | 151 DCHECK(file_manager::util::IsUnderSpecialPath(profile_, paths_[0])); |
| 156 if (is_directory_) { | 152 if (is_directory_) { |
| 157 drive::util::CheckDirectoryExists( | 153 file_manager::util::IsSpecialPathDirectory( |
| 158 profile_, | 154 profile_, |
| 159 *it, | 155 *it, |
| 160 base::Bind(&WritableFileChecker::RemoteCheckDone, this, *it)); | 156 base::Bind(&WritableFileChecker::SpecialPathCheckDone, this, *it)); |
| 161 } else { | 157 } else { |
| 162 drive::util::PrepareWritableFileAndRun( | 158 file_manager::util::PrepareSpecialPathWritableFile( |
| 163 profile_, | 159 profile_, |
| 164 *it, | 160 *it, |
| 165 base::Bind(&WritableFileChecker::CheckRemoteWritableFile, this, | 161 base::Bind(&WritableFileChecker::SpecialPathCheckDone, this, *it)); |
| 166 *it)); | |
| 167 } | 162 } |
| 168 } | 163 } |
| 169 return; | 164 return; |
| 170 } | 165 } |
| 171 #endif | 166 #endif |
| 172 content::BrowserThread::PostTask( | 167 content::BrowserThread::PostTask( |
| 173 content::BrowserThread::FILE, | 168 content::BrowserThread::FILE, |
| 174 FROM_HERE, | 169 FROM_HERE, |
| 175 base::Bind(&WritableFileChecker::CheckLocalWritableFiles, this)); | 170 base::Bind(&WritableFileChecker::CheckLocalWritableFiles, this)); |
| 176 } | 171 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 return; | 204 return; |
| 210 } | 205 } |
| 211 } | 206 } |
| 212 content::BrowserThread::PostTask( | 207 content::BrowserThread::PostTask( |
| 213 content::BrowserThread::UI, | 208 content::BrowserThread::UI, |
| 214 FROM_HERE, | 209 FROM_HERE, |
| 215 base::Bind(&WritableFileChecker::TaskDone, this)); | 210 base::Bind(&WritableFileChecker::TaskDone, this)); |
| 216 } | 211 } |
| 217 | 212 |
| 218 #if defined(OS_CHROMEOS) | 213 #if defined(OS_CHROMEOS) |
| 219 void WritableFileChecker::CheckRemoteWritableFile( | 214 void WritableFileChecker::SpecialPathCheckDone(const base::FilePath& path, |
| 220 const base::FilePath& remote_path, | 215 bool success) { |
| 221 drive::FileError error, | 216 if (success) |
| 222 const base::FilePath& /* local_path */) { | 217 TaskDone(); |
| 223 RemoteCheckDone(remote_path, error); | 218 else |
| 224 } | 219 Error(path); |
| 225 | |
| 226 void WritableFileChecker::RemoteCheckDone( | |
| 227 const base::FilePath& remote_path, | |
| 228 drive::FileError error) { | |
| 229 if (error == drive::FILE_ERROR_OK) { | |
| 230 content::BrowserThread::PostTask( | |
| 231 content::BrowserThread::UI, | |
| 232 FROM_HERE, | |
| 233 base::Bind(&WritableFileChecker::TaskDone, this)); | |
| 234 } else { | |
| 235 content::BrowserThread::PostTask( | |
| 236 content::BrowserThread::UI, | |
| 237 FROM_HERE, | |
| 238 base::Bind(&WritableFileChecker::Error, this, remote_path)); | |
| 239 } | |
| 240 } | 220 } |
| 241 #endif | 221 #endif |
| 242 | 222 |
| 243 } // namespace | 223 } // namespace |
| 244 | 224 |
| 245 const FileHandlerInfo* FileHandlerForId(const Extension& app, | 225 const FileHandlerInfo* FileHandlerForId(const Extension& app, |
| 246 const std::string& handler_id) { | 226 const std::string& handler_id) { |
| 247 const FileHandlersInfo* file_handlers = FileHandlers::GetFileHandlers(&app); | 227 const FileHandlersInfo* file_handlers = FileHandlers::GetFileHandlers(&app); |
| 248 if (!file_handlers) | 228 if (!file_handlers) |
| 249 return NULL; | 229 return NULL; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 *error = kInvalidParameters; | 381 *error = kInvalidParameters; |
| 402 return false; | 382 return false; |
| 403 } | 383 } |
| 404 | 384 |
| 405 return true; | 385 return true; |
| 406 } | 386 } |
| 407 | 387 |
| 408 } // namespace app_file_handler_util | 388 } // namespace app_file_handler_util |
| 409 | 389 |
| 410 } // namespace extensions | 390 } // namespace extensions |
| OLD | NEW |