| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/file_system_provider/provided_file_system.h" | 5 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 13 #include "chrome/browser/chromeos/file_system_provider/notification_manager.h" | 14 #include "chrome/browser/chromeos/file_system_provider/notification_manager.h" |
| 14 #include "chrome/browser/chromeos/file_system_provider/operations/abort.h" | 15 #include "chrome/browser/chromeos/file_system_provider/operations/abort.h" |
| 15 #include "chrome/browser/chromeos/file_system_provider/operations/add_watcher.h" | 16 #include "chrome/browser/chromeos/file_system_provider/operations/add_watcher.h" |
| 16 #include "chrome/browser/chromeos/file_system_provider/operations/close_file.h" | 17 #include "chrome/browser/chromeos/file_system_provider/operations/close_file.h" |
| 17 #include "chrome/browser/chromeos/file_system_provider/operations/configure.h" | 18 #include "chrome/browser/chromeos/file_system_provider/operations/configure.h" |
| 18 #include "chrome/browser/chromeos/file_system_provider/operations/copy_entry.h" | 19 #include "chrome/browser/chromeos/file_system_provider/operations/copy_entry.h" |
| 19 #include "chrome/browser/chromeos/file_system_provider/operations/create_directo
ry.h" | 20 #include "chrome/browser/chromeos/file_system_provider/operations/create_directo
ry.h" |
| 20 #include "chrome/browser/chromeos/file_system_provider/operations/create_file.h" | 21 #include "chrome/browser/chromeos/file_system_provider/operations/create_file.h" |
| 21 #include "chrome/browser/chromeos/file_system_provider/operations/delete_entry.h
" | 22 #include "chrome/browser/chromeos/file_system_provider/operations/delete_entry.h
" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 const size_t token; | 98 const size_t token; |
| 98 const GURL origin; | 99 const GURL origin; |
| 99 const base::FilePath entry_path; | 100 const base::FilePath entry_path; |
| 100 const bool recursive; | 101 const bool recursive; |
| 101 const bool persistent; | 102 const bool persistent; |
| 102 const storage::AsyncFileUtil::StatusCallback callback; | 103 const storage::AsyncFileUtil::StatusCallback callback; |
| 103 const storage::WatcherManager::NotificationCallback notification_callback; | 104 const storage::WatcherManager::NotificationCallback notification_callback; |
| 104 }; | 105 }; |
| 105 | 106 |
| 106 struct ProvidedFileSystem::NotifyInQueueArgs { | 107 struct ProvidedFileSystem::NotifyInQueueArgs { |
| 107 NotifyInQueueArgs(size_t token, | 108 NotifyInQueueArgs( |
| 108 const base::FilePath& entry_path, | 109 size_t token, |
| 109 bool recursive, | 110 const base::FilePath& entry_path, |
| 110 storage::WatcherManager::ChangeType change_type, | 111 bool recursive, |
| 111 scoped_ptr<ProvidedFileSystemObserver::Changes> changes, | 112 storage::WatcherManager::ChangeType change_type, |
| 112 const std::string& tag, | 113 std::unique_ptr<ProvidedFileSystemObserver::Changes> changes, |
| 113 const storage::AsyncFileUtil::StatusCallback& callback) | 114 const std::string& tag, |
| 115 const storage::AsyncFileUtil::StatusCallback& callback) |
| 114 : token(token), | 116 : token(token), |
| 115 entry_path(entry_path), | 117 entry_path(entry_path), |
| 116 recursive(recursive), | 118 recursive(recursive), |
| 117 change_type(change_type), | 119 change_type(change_type), |
| 118 changes(std::move(changes)), | 120 changes(std::move(changes)), |
| 119 tag(tag), | 121 tag(tag), |
| 120 callback(callback) {} | 122 callback(callback) {} |
| 121 ~NotifyInQueueArgs() {} | 123 ~NotifyInQueueArgs() {} |
| 122 | 124 |
| 123 const size_t token; | 125 const size_t token; |
| 124 const base::FilePath entry_path; | 126 const base::FilePath entry_path; |
| 125 const bool recursive; | 127 const bool recursive; |
| 126 const storage::WatcherManager::ChangeType change_type; | 128 const storage::WatcherManager::ChangeType change_type; |
| 127 const scoped_ptr<ProvidedFileSystemObserver::Changes> changes; | 129 const std::unique_ptr<ProvidedFileSystemObserver::Changes> changes; |
| 128 const std::string tag; | 130 const std::string tag; |
| 129 const storage::AsyncFileUtil::StatusCallback callback; | 131 const storage::AsyncFileUtil::StatusCallback callback; |
| 130 | 132 |
| 131 private: | 133 private: |
| 132 DISALLOW_COPY_AND_ASSIGN(NotifyInQueueArgs); | 134 DISALLOW_COPY_AND_ASSIGN(NotifyInQueueArgs); |
| 133 }; | 135 }; |
| 134 | 136 |
| 135 ProvidedFileSystem::ProvidedFileSystem( | 137 ProvidedFileSystem::ProvidedFileSystem( |
| 136 Profile* profile, | 138 Profile* profile, |
| 137 const ProvidedFileSystemInfo& file_system_info) | 139 const ProvidedFileSystemInfo& file_system_info) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 153 Abort(request_ids[i]); | 155 Abort(request_ids[i]); |
| 154 } | 156 } |
| 155 } | 157 } |
| 156 | 158 |
| 157 void ProvidedFileSystem::SetEventRouterForTesting( | 159 void ProvidedFileSystem::SetEventRouterForTesting( |
| 158 extensions::EventRouter* event_router) { | 160 extensions::EventRouter* event_router) { |
| 159 event_router_ = event_router; | 161 event_router_ = event_router; |
| 160 } | 162 } |
| 161 | 163 |
| 162 void ProvidedFileSystem::SetNotificationManagerForTesting( | 164 void ProvidedFileSystem::SetNotificationManagerForTesting( |
| 163 scoped_ptr<NotificationManagerInterface> notification_manager) { | 165 std::unique_ptr<NotificationManagerInterface> notification_manager) { |
| 164 notification_manager_ = std::move(notification_manager); | 166 notification_manager_ = std::move(notification_manager); |
| 165 request_manager_.reset(new RequestManager( | 167 request_manager_.reset(new RequestManager( |
| 166 profile_, file_system_info_.extension_id(), notification_manager_.get())); | 168 profile_, file_system_info_.extension_id(), notification_manager_.get())); |
| 167 } | 169 } |
| 168 | 170 |
| 169 AbortCallback ProvidedFileSystem::RequestUnmount( | 171 AbortCallback ProvidedFileSystem::RequestUnmount( |
| 170 const storage::AsyncFileUtil::StatusCallback& callback) { | 172 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 171 const int request_id = request_manager_->CreateRequest( | 173 const int request_id = request_manager_->CreateRequest( |
| 172 REQUEST_UNMOUNT, | 174 REQUEST_UNMOUNT, |
| 173 scoped_ptr<RequestManager::HandlerInterface>( | 175 std::unique_ptr<RequestManager::HandlerInterface>( |
| 174 new operations::Unmount(event_router_, file_system_info_, callback))); | 176 new operations::Unmount(event_router_, file_system_info_, callback))); |
| 175 if (!request_id) { | 177 if (!request_id) { |
| 176 callback.Run(base::File::FILE_ERROR_SECURITY); | 178 callback.Run(base::File::FILE_ERROR_SECURITY); |
| 177 return AbortCallback(); | 179 return AbortCallback(); |
| 178 } | 180 } |
| 179 | 181 |
| 180 return base::Bind( | 182 return base::Bind( |
| 181 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 183 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); |
| 182 } | 184 } |
| 183 | 185 |
| 184 AbortCallback ProvidedFileSystem::GetMetadata( | 186 AbortCallback ProvidedFileSystem::GetMetadata( |
| 185 const base::FilePath& entry_path, | 187 const base::FilePath& entry_path, |
| 186 MetadataFieldMask fields, | 188 MetadataFieldMask fields, |
| 187 const GetMetadataCallback& callback) { | 189 const GetMetadataCallback& callback) { |
| 188 const int request_id = request_manager_->CreateRequest( | 190 const int request_id = request_manager_->CreateRequest( |
| 189 GET_METADATA, | 191 GET_METADATA, |
| 190 scoped_ptr<RequestManager::HandlerInterface>(new operations::GetMetadata( | 192 std::unique_ptr<RequestManager::HandlerInterface>( |
| 191 event_router_, file_system_info_, entry_path, fields, callback))); | 193 new operations::GetMetadata(event_router_, file_system_info_, |
| 194 entry_path, fields, callback))); |
| 192 if (!request_id) { | 195 if (!request_id) { |
| 193 callback.Run(make_scoped_ptr<EntryMetadata>(NULL), | 196 callback.Run(base::WrapUnique<EntryMetadata>(NULL), |
| 194 base::File::FILE_ERROR_SECURITY); | 197 base::File::FILE_ERROR_SECURITY); |
| 195 return AbortCallback(); | 198 return AbortCallback(); |
| 196 } | 199 } |
| 197 | 200 |
| 198 return base::Bind( | 201 return base::Bind( |
| 199 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 202 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); |
| 200 } | 203 } |
| 201 | 204 |
| 202 AbortCallback ProvidedFileSystem::GetActions( | 205 AbortCallback ProvidedFileSystem::GetActions( |
| 203 const std::vector<base::FilePath>& entry_paths, | 206 const std::vector<base::FilePath>& entry_paths, |
| 204 const GetActionsCallback& callback) { | 207 const GetActionsCallback& callback) { |
| 205 const int request_id = request_manager_->CreateRequest( | 208 const int request_id = request_manager_->CreateRequest( |
| 206 GET_ACTIONS, | 209 GET_ACTIONS, |
| 207 scoped_ptr<RequestManager::HandlerInterface>(new operations::GetActions( | 210 std::unique_ptr<RequestManager::HandlerInterface>( |
| 208 event_router_, file_system_info_, entry_paths, callback))); | 211 new operations::GetActions(event_router_, file_system_info_, |
| 212 entry_paths, callback))); |
| 209 if (!request_id) { | 213 if (!request_id) { |
| 210 callback.Run(Actions(), base::File::FILE_ERROR_SECURITY); | 214 callback.Run(Actions(), base::File::FILE_ERROR_SECURITY); |
| 211 return AbortCallback(); | 215 return AbortCallback(); |
| 212 } | 216 } |
| 213 | 217 |
| 214 return base::Bind(&ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), | 218 return base::Bind(&ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), |
| 215 request_id); | 219 request_id); |
| 216 } | 220 } |
| 217 | 221 |
| 218 AbortCallback ProvidedFileSystem::ExecuteAction( | 222 AbortCallback ProvidedFileSystem::ExecuteAction( |
| 219 const std::vector<base::FilePath>& entry_paths, | 223 const std::vector<base::FilePath>& entry_paths, |
| 220 const std::string& action_id, | 224 const std::string& action_id, |
| 221 const storage::AsyncFileUtil::StatusCallback& callback) { | 225 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 222 const int request_id = request_manager_->CreateRequest( | 226 const int request_id = request_manager_->CreateRequest( |
| 223 EXECUTE_ACTION, | 227 EXECUTE_ACTION, |
| 224 scoped_ptr<RequestManager::HandlerInterface>( | 228 std::unique_ptr<RequestManager::HandlerInterface>( |
| 225 new operations::ExecuteAction(event_router_, file_system_info_, | 229 new operations::ExecuteAction(event_router_, file_system_info_, |
| 226 entry_paths, action_id, callback))); | 230 entry_paths, action_id, callback))); |
| 227 if (!request_id) { | 231 if (!request_id) { |
| 228 callback.Run(base::File::FILE_ERROR_SECURITY); | 232 callback.Run(base::File::FILE_ERROR_SECURITY); |
| 229 return AbortCallback(); | 233 return AbortCallback(); |
| 230 } | 234 } |
| 231 | 235 |
| 232 return base::Bind(&ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), | 236 return base::Bind(&ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), |
| 233 request_id); | 237 request_id); |
| 234 } | 238 } |
| 235 | 239 |
| 236 AbortCallback ProvidedFileSystem::ReadDirectory( | 240 AbortCallback ProvidedFileSystem::ReadDirectory( |
| 237 const base::FilePath& directory_path, | 241 const base::FilePath& directory_path, |
| 238 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) { | 242 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) { |
| 239 const int request_id = request_manager_->CreateRequest( | 243 const int request_id = request_manager_->CreateRequest( |
| 240 READ_DIRECTORY, | 244 READ_DIRECTORY, |
| 241 scoped_ptr<RequestManager::HandlerInterface>( | 245 std::unique_ptr<RequestManager::HandlerInterface>( |
| 242 new operations::ReadDirectory( | 246 new operations::ReadDirectory(event_router_, file_system_info_, |
| 243 event_router_, file_system_info_, directory_path, callback))); | 247 directory_path, callback))); |
| 244 if (!request_id) { | 248 if (!request_id) { |
| 245 callback.Run(base::File::FILE_ERROR_SECURITY, | 249 callback.Run(base::File::FILE_ERROR_SECURITY, |
| 246 storage::AsyncFileUtil::EntryList(), | 250 storage::AsyncFileUtil::EntryList(), |
| 247 false /* has_more */); | 251 false /* has_more */); |
| 248 return AbortCallback(); | 252 return AbortCallback(); |
| 249 } | 253 } |
| 250 | 254 |
| 251 return base::Bind( | 255 return base::Bind( |
| 252 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 256 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); |
| 253 } | 257 } |
| 254 | 258 |
| 255 AbortCallback ProvidedFileSystem::ReadFile( | 259 AbortCallback ProvidedFileSystem::ReadFile( |
| 256 int file_handle, | 260 int file_handle, |
| 257 net::IOBuffer* buffer, | 261 net::IOBuffer* buffer, |
| 258 int64_t offset, | 262 int64_t offset, |
| 259 int length, | 263 int length, |
| 260 const ReadChunkReceivedCallback& callback) { | 264 const ReadChunkReceivedCallback& callback) { |
| 261 TRACE_EVENT1( | 265 TRACE_EVENT1( |
| 262 "file_system_provider", "ProvidedFileSystem::ReadFile", "length", length); | 266 "file_system_provider", "ProvidedFileSystem::ReadFile", "length", length); |
| 263 const int request_id = request_manager_->CreateRequest( | 267 const int request_id = request_manager_->CreateRequest( |
| 264 READ_FILE, | 268 READ_FILE, base::WrapUnique<RequestManager::HandlerInterface>( |
| 265 make_scoped_ptr<RequestManager::HandlerInterface>( | 269 new operations::ReadFile(event_router_, file_system_info_, |
| 266 new operations::ReadFile(event_router_, | 270 file_handle, buffer, offset, |
| 267 file_system_info_, | 271 length, callback))); |
| 268 file_handle, | |
| 269 buffer, | |
| 270 offset, | |
| 271 length, | |
| 272 callback))); | |
| 273 if (!request_id) { | 272 if (!request_id) { |
| 274 callback.Run(0 /* chunk_length */, | 273 callback.Run(0 /* chunk_length */, |
| 275 false /* has_more */, | 274 false /* has_more */, |
| 276 base::File::FILE_ERROR_SECURITY); | 275 base::File::FILE_ERROR_SECURITY); |
| 277 return AbortCallback(); | 276 return AbortCallback(); |
| 278 } | 277 } |
| 279 | 278 |
| 280 return base::Bind( | 279 return base::Bind( |
| 281 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 280 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); |
| 282 } | 281 } |
| 283 | 282 |
| 284 AbortCallback ProvidedFileSystem::OpenFile(const base::FilePath& file_path, | 283 AbortCallback ProvidedFileSystem::OpenFile(const base::FilePath& file_path, |
| 285 OpenFileMode mode, | 284 OpenFileMode mode, |
| 286 const OpenFileCallback& callback) { | 285 const OpenFileCallback& callback) { |
| 287 const int request_id = request_manager_->CreateRequest( | 286 const int request_id = request_manager_->CreateRequest( |
| 288 OPEN_FILE, | 287 OPEN_FILE, std::unique_ptr<RequestManager::HandlerInterface>( |
| 289 scoped_ptr<RequestManager::HandlerInterface>(new operations::OpenFile( | 288 new operations::OpenFile( |
| 290 event_router_, file_system_info_, file_path, mode, | 289 event_router_, file_system_info_, file_path, mode, |
| 291 base::Bind(&ProvidedFileSystem::OnOpenFileCompleted, | 290 base::Bind(&ProvidedFileSystem::OnOpenFileCompleted, |
| 292 weak_ptr_factory_.GetWeakPtr(), file_path, mode, | 291 weak_ptr_factory_.GetWeakPtr(), file_path, |
| 293 callback)))); | 292 mode, callback)))); |
| 294 if (!request_id) { | 293 if (!request_id) { |
| 295 callback.Run(0 /* file_handle */, base::File::FILE_ERROR_SECURITY); | 294 callback.Run(0 /* file_handle */, base::File::FILE_ERROR_SECURITY); |
| 296 return AbortCallback(); | 295 return AbortCallback(); |
| 297 } | 296 } |
| 298 | 297 |
| 299 return base::Bind(&ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), | 298 return base::Bind(&ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), |
| 300 request_id); | 299 request_id); |
| 301 } | 300 } |
| 302 | 301 |
| 303 AbortCallback ProvidedFileSystem::CloseFile( | 302 AbortCallback ProvidedFileSystem::CloseFile( |
| 304 int file_handle, | 303 int file_handle, |
| 305 const storage::AsyncFileUtil::StatusCallback& callback) { | 304 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 306 const int request_id = request_manager_->CreateRequest( | 305 const int request_id = request_manager_->CreateRequest( |
| 307 CLOSE_FILE, | 306 CLOSE_FILE, std::unique_ptr<RequestManager::HandlerInterface>( |
| 308 scoped_ptr<RequestManager::HandlerInterface>(new operations::CloseFile( | 307 new operations::CloseFile( |
| 309 event_router_, file_system_info_, file_handle, | 308 event_router_, file_system_info_, file_handle, |
| 310 base::Bind(&ProvidedFileSystem::OnCloseFileCompleted, | 309 base::Bind(&ProvidedFileSystem::OnCloseFileCompleted, |
| 311 weak_ptr_factory_.GetWeakPtr(), file_handle, callback)))); | 310 weak_ptr_factory_.GetWeakPtr(), |
| 311 file_handle, callback)))); |
| 312 if (!request_id) { | 312 if (!request_id) { |
| 313 callback.Run(base::File::FILE_ERROR_SECURITY); | 313 callback.Run(base::File::FILE_ERROR_SECURITY); |
| 314 return AbortCallback(); | 314 return AbortCallback(); |
| 315 } | 315 } |
| 316 | 316 |
| 317 return base::Bind( | 317 return base::Bind( |
| 318 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 318 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); |
| 319 } | 319 } |
| 320 | 320 |
| 321 AbortCallback ProvidedFileSystem::CreateDirectory( | 321 AbortCallback ProvidedFileSystem::CreateDirectory( |
| 322 const base::FilePath& directory_path, | 322 const base::FilePath& directory_path, |
| 323 bool recursive, | 323 bool recursive, |
| 324 const storage::AsyncFileUtil::StatusCallback& callback) { | 324 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 325 const int request_id = request_manager_->CreateRequest( | 325 const int request_id = request_manager_->CreateRequest( |
| 326 CREATE_DIRECTORY, | 326 CREATE_DIRECTORY, std::unique_ptr<RequestManager::HandlerInterface>( |
| 327 scoped_ptr<RequestManager::HandlerInterface>( | 327 new operations::CreateDirectory( |
| 328 new operations::CreateDirectory(event_router_, | 328 event_router_, file_system_info_, |
| 329 file_system_info_, | 329 directory_path, recursive, callback))); |
| 330 directory_path, | |
| 331 recursive, | |
| 332 callback))); | |
| 333 if (!request_id) { | 330 if (!request_id) { |
| 334 callback.Run(base::File::FILE_ERROR_SECURITY); | 331 callback.Run(base::File::FILE_ERROR_SECURITY); |
| 335 return AbortCallback(); | 332 return AbortCallback(); |
| 336 } | 333 } |
| 337 | 334 |
| 338 return base::Bind( | 335 return base::Bind( |
| 339 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 336 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); |
| 340 } | 337 } |
| 341 | 338 |
| 342 AbortCallback ProvidedFileSystem::DeleteEntry( | 339 AbortCallback ProvidedFileSystem::DeleteEntry( |
| 343 const base::FilePath& entry_path, | 340 const base::FilePath& entry_path, |
| 344 bool recursive, | 341 bool recursive, |
| 345 const storage::AsyncFileUtil::StatusCallback& callback) { | 342 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 346 const int request_id = request_manager_->CreateRequest( | 343 const int request_id = request_manager_->CreateRequest( |
| 347 DELETE_ENTRY, | 344 DELETE_ENTRY, |
| 348 scoped_ptr<RequestManager::HandlerInterface>(new operations::DeleteEntry( | 345 std::unique_ptr<RequestManager::HandlerInterface>( |
| 349 event_router_, file_system_info_, entry_path, recursive, callback))); | 346 new operations::DeleteEntry(event_router_, file_system_info_, |
| 347 entry_path, recursive, callback))); |
| 350 if (!request_id) { | 348 if (!request_id) { |
| 351 callback.Run(base::File::FILE_ERROR_SECURITY); | 349 callback.Run(base::File::FILE_ERROR_SECURITY); |
| 352 return AbortCallback(); | 350 return AbortCallback(); |
| 353 } | 351 } |
| 354 | 352 |
| 355 return base::Bind( | 353 return base::Bind( |
| 356 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 354 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); |
| 357 } | 355 } |
| 358 | 356 |
| 359 AbortCallback ProvidedFileSystem::CreateFile( | 357 AbortCallback ProvidedFileSystem::CreateFile( |
| 360 const base::FilePath& file_path, | 358 const base::FilePath& file_path, |
| 361 const storage::AsyncFileUtil::StatusCallback& callback) { | 359 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 362 const int request_id = request_manager_->CreateRequest( | 360 const int request_id = request_manager_->CreateRequest( |
| 363 CREATE_FILE, | 361 CREATE_FILE, |
| 364 scoped_ptr<RequestManager::HandlerInterface>(new operations::CreateFile( | 362 std::unique_ptr<RequestManager::HandlerInterface>( |
| 365 event_router_, file_system_info_, file_path, callback))); | 363 new operations::CreateFile(event_router_, file_system_info_, |
| 364 file_path, callback))); |
| 366 if (!request_id) { | 365 if (!request_id) { |
| 367 callback.Run(base::File::FILE_ERROR_SECURITY); | 366 callback.Run(base::File::FILE_ERROR_SECURITY); |
| 368 return AbortCallback(); | 367 return AbortCallback(); |
| 369 } | 368 } |
| 370 | 369 |
| 371 return base::Bind( | 370 return base::Bind( |
| 372 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 371 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); |
| 373 } | 372 } |
| 374 | 373 |
| 375 AbortCallback ProvidedFileSystem::CopyEntry( | 374 AbortCallback ProvidedFileSystem::CopyEntry( |
| 376 const base::FilePath& source_path, | 375 const base::FilePath& source_path, |
| 377 const base::FilePath& target_path, | 376 const base::FilePath& target_path, |
| 378 const storage::AsyncFileUtil::StatusCallback& callback) { | 377 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 379 const int request_id = request_manager_->CreateRequest( | 378 const int request_id = request_manager_->CreateRequest( |
| 380 COPY_ENTRY, | 379 COPY_ENTRY, |
| 381 scoped_ptr<RequestManager::HandlerInterface>( | 380 std::unique_ptr<RequestManager::HandlerInterface>( |
| 382 new operations::CopyEntry(event_router_, | 381 new operations::CopyEntry(event_router_, file_system_info_, |
| 383 file_system_info_, | 382 source_path, target_path, callback))); |
| 384 source_path, | |
| 385 target_path, | |
| 386 callback))); | |
| 387 if (!request_id) { | 383 if (!request_id) { |
| 388 callback.Run(base::File::FILE_ERROR_SECURITY); | 384 callback.Run(base::File::FILE_ERROR_SECURITY); |
| 389 return AbortCallback(); | 385 return AbortCallback(); |
| 390 } | 386 } |
| 391 | 387 |
| 392 return base::Bind( | 388 return base::Bind( |
| 393 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 389 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); |
| 394 } | 390 } |
| 395 | 391 |
| 396 AbortCallback ProvidedFileSystem::WriteFile( | 392 AbortCallback ProvidedFileSystem::WriteFile( |
| 397 int file_handle, | 393 int file_handle, |
| 398 net::IOBuffer* buffer, | 394 net::IOBuffer* buffer, |
| 399 int64_t offset, | 395 int64_t offset, |
| 400 int length, | 396 int length, |
| 401 const storage::AsyncFileUtil::StatusCallback& callback) { | 397 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 402 TRACE_EVENT1("file_system_provider", | 398 TRACE_EVENT1("file_system_provider", |
| 403 "ProvidedFileSystem::WriteFile", | 399 "ProvidedFileSystem::WriteFile", |
| 404 "length", | 400 "length", |
| 405 length); | 401 length); |
| 406 const int request_id = request_manager_->CreateRequest( | 402 const int request_id = request_manager_->CreateRequest( |
| 407 WRITE_FILE, | 403 WRITE_FILE, |
| 408 make_scoped_ptr<RequestManager::HandlerInterface>( | 404 base::WrapUnique<RequestManager::HandlerInterface>( |
| 409 new operations::WriteFile(event_router_, | 405 new operations::WriteFile(event_router_, file_system_info_, |
| 410 file_system_info_, | 406 file_handle, make_scoped_refptr(buffer), |
| 411 file_handle, | 407 offset, length, callback))); |
| 412 make_scoped_refptr(buffer), | |
| 413 offset, | |
| 414 length, | |
| 415 callback))); | |
| 416 if (!request_id) { | 408 if (!request_id) { |
| 417 callback.Run(base::File::FILE_ERROR_SECURITY); | 409 callback.Run(base::File::FILE_ERROR_SECURITY); |
| 418 return AbortCallback(); | 410 return AbortCallback(); |
| 419 } | 411 } |
| 420 | 412 |
| 421 return base::Bind( | 413 return base::Bind( |
| 422 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 414 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); |
| 423 } | 415 } |
| 424 | 416 |
| 425 AbortCallback ProvidedFileSystem::MoveEntry( | 417 AbortCallback ProvidedFileSystem::MoveEntry( |
| 426 const base::FilePath& source_path, | 418 const base::FilePath& source_path, |
| 427 const base::FilePath& target_path, | 419 const base::FilePath& target_path, |
| 428 const storage::AsyncFileUtil::StatusCallback& callback) { | 420 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 429 const int request_id = request_manager_->CreateRequest( | 421 const int request_id = request_manager_->CreateRequest( |
| 430 MOVE_ENTRY, | 422 MOVE_ENTRY, |
| 431 scoped_ptr<RequestManager::HandlerInterface>( | 423 std::unique_ptr<RequestManager::HandlerInterface>( |
| 432 new operations::MoveEntry(event_router_, | 424 new operations::MoveEntry(event_router_, file_system_info_, |
| 433 file_system_info_, | 425 source_path, target_path, callback))); |
| 434 source_path, | |
| 435 target_path, | |
| 436 callback))); | |
| 437 if (!request_id) { | 426 if (!request_id) { |
| 438 callback.Run(base::File::FILE_ERROR_SECURITY); | 427 callback.Run(base::File::FILE_ERROR_SECURITY); |
| 439 return AbortCallback(); | 428 return AbortCallback(); |
| 440 } | 429 } |
| 441 | 430 |
| 442 return base::Bind( | 431 return base::Bind( |
| 443 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 432 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); |
| 444 } | 433 } |
| 445 | 434 |
| 446 AbortCallback ProvidedFileSystem::Truncate( | 435 AbortCallback ProvidedFileSystem::Truncate( |
| 447 const base::FilePath& file_path, | 436 const base::FilePath& file_path, |
| 448 int64_t length, | 437 int64_t length, |
| 449 const storage::AsyncFileUtil::StatusCallback& callback) { | 438 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 450 const int request_id = request_manager_->CreateRequest( | 439 const int request_id = request_manager_->CreateRequest( |
| 451 TRUNCATE, | 440 TRUNCATE, std::unique_ptr<RequestManager::HandlerInterface>( |
| 452 scoped_ptr<RequestManager::HandlerInterface>(new operations::Truncate( | 441 new operations::Truncate(event_router_, file_system_info_, |
| 453 event_router_, file_system_info_, file_path, length, callback))); | 442 file_path, length, callback))); |
| 454 if (!request_id) { | 443 if (!request_id) { |
| 455 callback.Run(base::File::FILE_ERROR_SECURITY); | 444 callback.Run(base::File::FILE_ERROR_SECURITY); |
| 456 return AbortCallback(); | 445 return AbortCallback(); |
| 457 } | 446 } |
| 458 | 447 |
| 459 return base::Bind( | 448 return base::Bind( |
| 460 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); | 449 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); |
| 461 } | 450 } |
| 462 | 451 |
| 463 AbortCallback ProvidedFileSystem::AddWatcher( | 452 AbortCallback ProvidedFileSystem::AddWatcher( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 | 502 |
| 514 void ProvidedFileSystem::RemoveObserver(ProvidedFileSystemObserver* observer) { | 503 void ProvidedFileSystem::RemoveObserver(ProvidedFileSystemObserver* observer) { |
| 515 DCHECK(observer); | 504 DCHECK(observer); |
| 516 observers_.RemoveObserver(observer); | 505 observers_.RemoveObserver(observer); |
| 517 } | 506 } |
| 518 | 507 |
| 519 void ProvidedFileSystem::Notify( | 508 void ProvidedFileSystem::Notify( |
| 520 const base::FilePath& entry_path, | 509 const base::FilePath& entry_path, |
| 521 bool recursive, | 510 bool recursive, |
| 522 storage::WatcherManager::ChangeType change_type, | 511 storage::WatcherManager::ChangeType change_type, |
| 523 scoped_ptr<ProvidedFileSystemObserver::Changes> changes, | 512 std::unique_ptr<ProvidedFileSystemObserver::Changes> changes, |
| 524 const std::string& tag, | 513 const std::string& tag, |
| 525 const storage::AsyncFileUtil::StatusCallback& callback) { | 514 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 526 const size_t token = watcher_queue_.NewToken(); | 515 const size_t token = watcher_queue_.NewToken(); |
| 527 watcher_queue_.Enqueue( | 516 watcher_queue_.Enqueue( |
| 528 token, base::Bind(&ProvidedFileSystem::NotifyInQueue, | 517 token, base::Bind(&ProvidedFileSystem::NotifyInQueue, |
| 529 base::Unretained(this), // Outlived by the queue. | 518 base::Unretained(this), // Outlived by the queue. |
| 530 base::Passed(make_scoped_ptr(new NotifyInQueueArgs( | 519 base::Passed(base::WrapUnique(new NotifyInQueueArgs( |
| 531 token, entry_path, recursive, change_type, | 520 token, entry_path, recursive, change_type, |
| 532 std::move(changes), tag, callback))))); | 521 std::move(changes), tag, callback))))); |
| 533 } | 522 } |
| 534 | 523 |
| 535 void ProvidedFileSystem::Configure( | 524 void ProvidedFileSystem::Configure( |
| 536 const storage::AsyncFileUtil::StatusCallback& callback) { | 525 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 537 const int request_id = request_manager_->CreateRequest( | 526 const int request_id = request_manager_->CreateRequest( |
| 538 CONFIGURE, | 527 CONFIGURE, std::unique_ptr<RequestManager::HandlerInterface>( |
| 539 scoped_ptr<RequestManager::HandlerInterface>(new operations::Configure( | 528 new operations::Configure(event_router_, file_system_info_, |
| 540 event_router_, file_system_info_, callback))); | 529 callback))); |
| 541 if (!request_id) | 530 if (!request_id) |
| 542 callback.Run(base::File::FILE_ERROR_SECURITY); | 531 callback.Run(base::File::FILE_ERROR_SECURITY); |
| 543 } | 532 } |
| 544 | 533 |
| 545 void ProvidedFileSystem::Abort(int operation_request_id) { | 534 void ProvidedFileSystem::Abort(int operation_request_id) { |
| 546 if (!request_manager_->CreateRequest( | 535 if (!request_manager_->CreateRequest( |
| 547 ABORT, | 536 ABORT, std::unique_ptr<RequestManager::HandlerInterface>( |
| 548 scoped_ptr<RequestManager::HandlerInterface>(new operations::Abort( | 537 new operations::Abort( |
| 549 event_router_, file_system_info_, operation_request_id, | 538 event_router_, file_system_info_, operation_request_id, |
| 550 base::Bind(&ProvidedFileSystem::OnAbortCompleted, | 539 base::Bind(&ProvidedFileSystem::OnAbortCompleted, |
| 551 weak_ptr_factory_.GetWeakPtr(), | 540 weak_ptr_factory_.GetWeakPtr(), |
| 552 operation_request_id))))) { | 541 operation_request_id))))) { |
| 553 // If the aborting event is not handled, then the operation should simply | 542 // If the aborting event is not handled, then the operation should simply |
| 554 // be not aborted. Instead we'll wait until it completes. | 543 // be not aborted. Instead we'll wait until it completes. |
| 555 LOG(ERROR) << "Failed to create an abort request."; | 544 LOG(ERROR) << "Failed to create an abort request."; |
| 556 } | 545 } |
| 557 } | 546 } |
| 558 | 547 |
| 559 void ProvidedFileSystem::OnAbortCompleted(int operation_request_id, | 548 void ProvidedFileSystem::OnAbortCompleted(int operation_request_id, |
| 560 base::File::Error result) { | 549 base::File::Error result) { |
| 561 if (result != base::File::FILE_OK) { | 550 if (result != base::File::FILE_OK) { |
| 562 // If an error in aborting happens, then do not abort the request in the | 551 // If an error in aborting happens, then do not abort the request in the |
| 563 // request manager, as the operation is supposed to complete. The only case | 552 // request manager, as the operation is supposed to complete. The only case |
| 564 // it wouldn't complete is if there is a bug in the extension code, and | 553 // it wouldn't complete is if there is a bug in the extension code, and |
| 565 // the extension never calls the callback. We consiously *do not* handle | 554 // the extension never calls the callback. We consiously *do not* handle |
| 566 // bugs in extensions here. | 555 // bugs in extensions here. |
| 567 return; | 556 return; |
| 568 } | 557 } |
| 569 request_manager_->RejectRequest(operation_request_id, | 558 request_manager_->RejectRequest(operation_request_id, |
| 570 make_scoped_ptr(new RequestValue()), | 559 base::WrapUnique(new RequestValue()), |
| 571 base::File::FILE_ERROR_ABORT); | 560 base::File::FILE_ERROR_ABORT); |
| 572 } | 561 } |
| 573 | 562 |
| 574 AbortCallback ProvidedFileSystem::AddWatcherInQueue( | 563 AbortCallback ProvidedFileSystem::AddWatcherInQueue( |
| 575 const AddWatcherInQueueArgs& args) { | 564 const AddWatcherInQueueArgs& args) { |
| 576 if (args.persistent && (!file_system_info_.supports_notify_tag() || | 565 if (args.persistent && (!file_system_info_.supports_notify_tag() || |
| 577 !args.notification_callback.is_null())) { | 566 !args.notification_callback.is_null())) { |
| 578 OnAddWatcherInQueueCompleted(args.token, args.entry_path, args.recursive, | 567 OnAddWatcherInQueueCompleted(args.token, args.entry_path, args.recursive, |
| 579 Subscriber(), args.callback, | 568 Subscriber(), args.callback, |
| 580 base::File::FILE_ERROR_INVALID_OPERATION); | 569 base::File::FILE_ERROR_INVALID_OPERATION); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 594 const bool exists = it->second.subscribers.find(args.origin) != | 583 const bool exists = it->second.subscribers.find(args.origin) != |
| 595 it->second.subscribers.end(); | 584 it->second.subscribers.end(); |
| 596 OnAddWatcherInQueueCompleted( | 585 OnAddWatcherInQueueCompleted( |
| 597 args.token, args.entry_path, args.recursive, subscriber, args.callback, | 586 args.token, args.entry_path, args.recursive, subscriber, args.callback, |
| 598 exists ? base::File::FILE_ERROR_EXISTS : base::File::FILE_OK); | 587 exists ? base::File::FILE_ERROR_EXISTS : base::File::FILE_OK); |
| 599 return AbortCallback(); | 588 return AbortCallback(); |
| 600 } | 589 } |
| 601 | 590 |
| 602 const int request_id = request_manager_->CreateRequest( | 591 const int request_id = request_manager_->CreateRequest( |
| 603 ADD_WATCHER, | 592 ADD_WATCHER, |
| 604 scoped_ptr<RequestManager::HandlerInterface>(new operations::AddWatcher( | 593 std::unique_ptr<RequestManager::HandlerInterface>( |
| 605 event_router_, file_system_info_, args.entry_path, args.recursive, | 594 new operations::AddWatcher( |
| 606 base::Bind(&ProvidedFileSystem::OnAddWatcherInQueueCompleted, | 595 event_router_, file_system_info_, args.entry_path, args.recursive, |
| 607 weak_ptr_factory_.GetWeakPtr(), args.token, | 596 base::Bind(&ProvidedFileSystem::OnAddWatcherInQueueCompleted, |
| 608 args.entry_path, args.recursive, subscriber, | 597 weak_ptr_factory_.GetWeakPtr(), args.token, |
| 609 args.callback)))); | 598 args.entry_path, args.recursive, subscriber, |
| 599 args.callback)))); |
| 610 | 600 |
| 611 if (!request_id) { | 601 if (!request_id) { |
| 612 OnAddWatcherInQueueCompleted(args.token, args.entry_path, args.recursive, | 602 OnAddWatcherInQueueCompleted(args.token, args.entry_path, args.recursive, |
| 613 subscriber, args.callback, | 603 subscriber, args.callback, |
| 614 base::File::FILE_ERROR_SECURITY); | 604 base::File::FILE_ERROR_SECURITY); |
| 615 } | 605 } |
| 616 | 606 |
| 617 return AbortCallback(); | 607 return AbortCallback(); |
| 618 } | 608 } |
| 619 | 609 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 638 if (it->second.subscribers.size() > 1) { | 628 if (it->second.subscribers.size() > 1) { |
| 639 OnRemoveWatcherInQueueCompleted(token, origin, key, callback, | 629 OnRemoveWatcherInQueueCompleted(token, origin, key, callback, |
| 640 false /* extension_response */, | 630 false /* extension_response */, |
| 641 base::File::FILE_OK); | 631 base::File::FILE_OK); |
| 642 return AbortCallback(); | 632 return AbortCallback(); |
| 643 } | 633 } |
| 644 | 634 |
| 645 // Otherwise, emit an event, and remove the watcher. | 635 // Otherwise, emit an event, and remove the watcher. |
| 646 request_manager_->CreateRequest( | 636 request_manager_->CreateRequest( |
| 647 REMOVE_WATCHER, | 637 REMOVE_WATCHER, |
| 648 scoped_ptr<RequestManager::HandlerInterface>( | 638 std::unique_ptr<RequestManager::HandlerInterface>( |
| 649 new operations::RemoveWatcher( | 639 new operations::RemoveWatcher( |
| 650 event_router_, file_system_info_, entry_path, recursive, | 640 event_router_, file_system_info_, entry_path, recursive, |
| 651 base::Bind(&ProvidedFileSystem::OnRemoveWatcherInQueueCompleted, | 641 base::Bind(&ProvidedFileSystem::OnRemoveWatcherInQueueCompleted, |
| 652 weak_ptr_factory_.GetWeakPtr(), token, origin, key, | 642 weak_ptr_factory_.GetWeakPtr(), token, origin, key, |
| 653 callback, true /* extension_response */)))); | 643 callback, true /* extension_response */)))); |
| 654 | 644 |
| 655 return AbortCallback(); | 645 return AbortCallback(); |
| 656 } | 646 } |
| 657 | 647 |
| 658 AbortCallback ProvidedFileSystem::NotifyInQueue( | 648 AbortCallback ProvidedFileSystem::NotifyInQueue( |
| 659 scoped_ptr<NotifyInQueueArgs> args) { | 649 std::unique_ptr<NotifyInQueueArgs> args) { |
| 660 const WatcherKey key(args->entry_path, args->recursive); | 650 const WatcherKey key(args->entry_path, args->recursive); |
| 661 const auto& watcher_it = watchers_.find(key); | 651 const auto& watcher_it = watchers_.find(key); |
| 662 if (watcher_it == watchers_.end()) { | 652 if (watcher_it == watchers_.end()) { |
| 663 OnNotifyInQueueCompleted(std::move(args), base::File::FILE_ERROR_NOT_FOUND); | 653 OnNotifyInQueueCompleted(std::move(args), base::File::FILE_ERROR_NOT_FOUND); |
| 664 return AbortCallback(); | 654 return AbortCallback(); |
| 665 } | 655 } |
| 666 | 656 |
| 667 // The tag must be provided if and only if it's explicitly supported. | 657 // The tag must be provided if and only if it's explicitly supported. |
| 668 if (file_system_info_.supports_notify_tag() == args->tag.empty()) { | 658 if (file_system_info_.supports_notify_tag() == args->tag.empty()) { |
| 669 OnNotifyInQueueCompleted(std::move(args), | 659 OnNotifyInQueueCompleted(std::move(args), |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 | 762 |
| 773 // If there are no more subscribers, then remove the watcher. | 763 // If there are no more subscribers, then remove the watcher. |
| 774 if (!it->second.subscribers.size()) | 764 if (!it->second.subscribers.size()) |
| 775 watchers_.erase(it); | 765 watchers_.erase(it); |
| 776 | 766 |
| 777 callback.Run(base::File::FILE_OK); | 767 callback.Run(base::File::FILE_OK); |
| 778 watcher_queue_.Complete(token); | 768 watcher_queue_.Complete(token); |
| 779 } | 769 } |
| 780 | 770 |
| 781 void ProvidedFileSystem::OnNotifyInQueueCompleted( | 771 void ProvidedFileSystem::OnNotifyInQueueCompleted( |
| 782 scoped_ptr<NotifyInQueueArgs> args, | 772 std::unique_ptr<NotifyInQueueArgs> args, |
| 783 base::File::Error result) { | 773 base::File::Error result) { |
| 784 if (result != base::File::FILE_OK) { | 774 if (result != base::File::FILE_OK) { |
| 785 args->callback.Run(result); | 775 args->callback.Run(result); |
| 786 watcher_queue_.Complete(args->token); | 776 watcher_queue_.Complete(args->token); |
| 787 return; | 777 return; |
| 788 } | 778 } |
| 789 | 779 |
| 790 // Check if the entry is still watched. | 780 // Check if the entry is still watched. |
| 791 const WatcherKey key(args->entry_path, args->recursive); | 781 const WatcherKey key(args->entry_path, args->recursive); |
| 792 const Watchers::iterator it = watchers_.find(key); | 782 const Watchers::iterator it = watchers_.find(key); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 const storage::AsyncFileUtil::StatusCallback& callback, | 826 const storage::AsyncFileUtil::StatusCallback& callback, |
| 837 base::File::Error result) { | 827 base::File::Error result) { |
| 838 // Closing files is final. Even if an error happened, we remove it from the | 828 // Closing files is final. Even if an error happened, we remove it from the |
| 839 // list of opened files. | 829 // list of opened files. |
| 840 opened_files_.erase(file_handle); | 830 opened_files_.erase(file_handle); |
| 841 callback.Run(result); | 831 callback.Run(result); |
| 842 } | 832 } |
| 843 | 833 |
| 844 } // namespace file_system_provider | 834 } // namespace file_system_provider |
| 845 } // namespace chromeos | 835 } // namespace chromeos |
| OLD | NEW |