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