| 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 "base/files/file.h" | 7 #include "base/files/file.h" |
| 8 #include "base/values.h" | 8 #include "chrome/browser/chromeos/file_system_provider/operations/unmount.h" |
| 9 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" | 9 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" |
| 10 #include "chrome/common/extensions/api/file_system_provider.h" | 10 #include "chrome/common/extensions/api/file_system_provider.h" |
| 11 #include "extensions/browser/event_router.h" | 11 #include "extensions/browser/event_router.h" |
| 12 | 12 |
| 13 namespace chromeos { | 13 namespace chromeos { |
| 14 namespace file_system_provider { | 14 namespace file_system_provider { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // Creates values to be passed to request events. These values can be extended | |
| 18 // by additional fields. | |
| 19 scoped_ptr<base::ListValue> CreateRequestValues(int file_system_id, | |
| 20 int request_id) { | |
| 21 scoped_ptr<base::ListValue> values(new base::ListValue()); | |
| 22 values->AppendInteger(file_system_id); | |
| 23 values->AppendInteger(request_id); | |
| 24 return values.Pass(); | |
| 25 } | |
| 26 | |
| 27 // Forwards the success callback to the status callback. Ignores arguments, | |
| 28 // since unmount request does not provide arguments. | |
| 29 void OnRequestUnmountSuccess( | |
| 30 const fileapi::AsyncFileUtil::StatusCallback& callback, | |
| 31 scoped_ptr<base::DictionaryValue> /* result */, | |
| 32 bool /* has_next */) { | |
| 33 callback.Run(base::File::FILE_OK); | |
| 34 } | |
| 35 | |
| 36 } // namespace | 17 } // namespace |
| 37 | 18 |
| 38 ProvidedFileSystem::ProvidedFileSystem( | 19 ProvidedFileSystem::ProvidedFileSystem( |
| 39 extensions::EventRouter* event_router, | 20 extensions::EventRouter* event_router, |
| 40 const ProvidedFileSystemInfo& file_system_info) | 21 const ProvidedFileSystemInfo& file_system_info) |
| 41 : event_router_(event_router), file_system_info_(file_system_info) {} | 22 : event_router_(event_router), file_system_info_(file_system_info) { |
| 23 } |
| 42 | 24 |
| 43 ProvidedFileSystem::~ProvidedFileSystem() {} | 25 ProvidedFileSystem::~ProvidedFileSystem() {} |
| 44 | 26 |
| 45 bool ProvidedFileSystem::RequestUnmount( | 27 void ProvidedFileSystem::RequestUnmount( |
| 46 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 28 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| 47 int request_id = request_manager_.CreateRequest( | 29 if (!request_manager_.CreateRequest( |
| 48 base::Bind(&OnRequestUnmountSuccess, callback), callback); | 30 make_scoped_ptr<RequestManager::HandlerInterface>( |
| 49 | 31 new operations::Unmount( |
| 50 if (!request_id) | 32 event_router_, file_system_info_, callback)))) { |
| 51 return false; | 33 callback.Run(base::File::FILE_ERROR_SECURITY); |
| 52 | 34 } |
| 53 scoped_ptr<base::ListValue> values( | |
| 54 CreateRequestValues(file_system_info_.file_system_id(), request_id)); | |
| 55 | |
| 56 event_router_->DispatchEventToExtension( | |
| 57 file_system_info_.extension_id(), | |
| 58 make_scoped_ptr(new extensions::Event( | |
| 59 extensions::api::file_system_provider::OnUnmountRequested::kEventName, | |
| 60 values.Pass()))); | |
| 61 | |
| 62 return true; | |
| 63 } | 35 } |
| 64 | 36 |
| 65 const ProvidedFileSystemInfo& ProvidedFileSystem::GetFileSystemInfo() const { | 37 const ProvidedFileSystemInfo& ProvidedFileSystem::GetFileSystemInfo() const { |
| 66 return file_system_info_; | 38 return file_system_info_; |
| 67 } | 39 } |
| 68 | 40 |
| 69 RequestManager* ProvidedFileSystem::GetRequestManager() { | 41 RequestManager* ProvidedFileSystem::GetRequestManager() { |
| 70 return &request_manager_; | 42 return &request_manager_; |
| 71 } | 43 } |
| 72 | 44 |
| 73 } // namespace file_system_provider | 45 } // namespace file_system_provider |
| 74 } // namespace chromeos | 46 } // namespace chromeos |
| OLD | NEW |