| 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_system_provider/file_system_pr
ovider_api.h" | 5 #include "chrome/browser/chromeos/extensions/file_system_provider/file_system_pr
ovider_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 using chromeos::file_system_provider::ProvidedFileSystemInfo; | 26 using chromeos::file_system_provider::ProvidedFileSystemInfo; |
| 27 using chromeos::file_system_provider::ProvidedFileSystemInterface; | 27 using chromeos::file_system_provider::ProvidedFileSystemInterface; |
| 28 using chromeos::file_system_provider::ProvidedFileSystemObserver; | 28 using chromeos::file_system_provider::ProvidedFileSystemObserver; |
| 29 using chromeos::file_system_provider::RequestValue; | 29 using chromeos::file_system_provider::RequestValue; |
| 30 using chromeos::file_system_provider::Service; | 30 using chromeos::file_system_provider::Service; |
| 31 using chromeos::file_system_provider::Watchers; | 31 using chromeos::file_system_provider::Watchers; |
| 32 | 32 |
| 33 namespace extensions { | 33 namespace extensions { |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 typedef std::vector<linked_ptr<api::file_system_provider::Change>> IDLChanges; | |
| 37 | |
| 38 // Converts the change type from the IDL type to a native type. |changed_type| | 36 // Converts the change type from the IDL type to a native type. |changed_type| |
| 39 // must be specified (not CHANGE_TYPE_NONE). | 37 // must be specified (not CHANGE_TYPE_NONE). |
| 40 storage::WatcherManager::ChangeType ParseChangeType( | 38 storage::WatcherManager::ChangeType ParseChangeType( |
| 41 const api::file_system_provider::ChangeType& change_type) { | 39 const api::file_system_provider::ChangeType& change_type) { |
| 42 switch (change_type) { | 40 switch (change_type) { |
| 43 case api::file_system_provider::CHANGE_TYPE_CHANGED: | 41 case api::file_system_provider::CHANGE_TYPE_CHANGED: |
| 44 return storage::WatcherManager::CHANGED; | 42 return storage::WatcherManager::CHANGED; |
| 45 case api::file_system_provider::CHANGE_TYPE_DELETED: | 43 case api::file_system_provider::CHANGE_TYPE_DELETED: |
| 46 return storage::WatcherManager::DELETED; | 44 return storage::WatcherManager::DELETED; |
| 47 default: | 45 default: |
| 48 break; | 46 break; |
| 49 } | 47 } |
| 50 NOTREACHED(); | 48 NOTREACHED(); |
| 51 return storage::WatcherManager::CHANGED; | 49 return storage::WatcherManager::CHANGED; |
| 52 } | 50 } |
| 53 | 51 |
| 54 // Convert the change from the IDL type to a native type. The reason IDL types | 52 // Convert the change from the IDL type to a native type. The reason IDL types |
| 55 // are not used is since they are imperfect, eg. paths are stored as strings. | 53 // are not used is since they are imperfect, eg. paths are stored as strings. |
| 56 ProvidedFileSystemObserver::Change ParseChange( | 54 ProvidedFileSystemObserver::Change ParseChange( |
| 57 const api::file_system_provider::Change& change) { | 55 const api::file_system_provider::Change& change) { |
| 58 ProvidedFileSystemObserver::Change result; | 56 ProvidedFileSystemObserver::Change result; |
| 59 result.entry_path = base::FilePath::FromUTF8Unsafe(change.entry_path); | 57 result.entry_path = base::FilePath::FromUTF8Unsafe(change.entry_path); |
| 60 result.change_type = ParseChangeType(change.change_type); | 58 result.change_type = ParseChangeType(change.change_type); |
| 61 return result; | 59 return result; |
| 62 } | 60 } |
| 63 | 61 |
| 64 // Converts a list of child changes from the IDL type to a native type. | 62 // Converts a list of child changes from the IDL type to a native type. |
| 65 scoped_ptr<ProvidedFileSystemObserver::Changes> ParseChanges( | 63 scoped_ptr<ProvidedFileSystemObserver::Changes> ParseChanges( |
| 66 const IDLChanges& changes) { | 64 const std::vector<api::file_system_provider::Change>& changes) { |
| 67 scoped_ptr<ProvidedFileSystemObserver::Changes> results( | 65 scoped_ptr<ProvidedFileSystemObserver::Changes> results( |
| 68 new ProvidedFileSystemObserver::Changes); | 66 new ProvidedFileSystemObserver::Changes); |
| 69 for (const auto& change : changes) { | 67 for (const auto& change : changes) { |
| 70 results->push_back(ParseChange(*change)); | 68 results->push_back(ParseChange(change)); |
| 71 } | 69 } |
| 72 return results; | 70 return results; |
| 73 } | 71 } |
| 74 | 72 |
| 75 // Fills the IDL's FileSystemInfo with FSP's ProvidedFileSystemInfo and | 73 // Fills the IDL's FileSystemInfo with FSP's ProvidedFileSystemInfo and |
| 76 // Watchers. | 74 // Watchers. |
| 77 void FillFileSystemInfo(const ProvidedFileSystemInfo& file_system_info, | 75 void FillFileSystemInfo(const ProvidedFileSystemInfo& file_system_info, |
| 78 const Watchers& watchers, | 76 const Watchers& watchers, |
| 79 const OpenedFiles& opened_files, | 77 const OpenedFiles& opened_files, |
| 80 api::file_system_provider::FileSystemInfo* output) { | 78 api::file_system_provider::FileSystemInfo* output) { |
| 81 using api::file_system_provider::Watcher; | 79 using api::file_system_provider::Watcher; |
| 82 using api::file_system_provider::OpenedFile; | 80 using api::file_system_provider::OpenedFile; |
| 83 | 81 |
| 84 output->file_system_id = file_system_info.file_system_id(); | 82 output->file_system_id = file_system_info.file_system_id(); |
| 85 output->display_name = file_system_info.display_name(); | 83 output->display_name = file_system_info.display_name(); |
| 86 output->writable = file_system_info.writable(); | 84 output->writable = file_system_info.writable(); |
| 87 output->opened_files_limit = file_system_info.opened_files_limit(); | 85 output->opened_files_limit = file_system_info.opened_files_limit(); |
| 88 | 86 |
| 89 std::vector<linked_ptr<Watcher>> watcher_items; | |
| 90 for (const auto& watcher : watchers) { | 87 for (const auto& watcher : watchers) { |
| 91 const linked_ptr<Watcher> watcher_item(new Watcher); | 88 Watcher watcher_item; |
| 92 watcher_item->entry_path = watcher.second.entry_path.value(); | 89 watcher_item.entry_path = watcher.second.entry_path.value(); |
| 93 watcher_item->recursive = watcher.second.recursive; | 90 watcher_item.recursive = watcher.second.recursive; |
| 94 if (!watcher.second.last_tag.empty()) | 91 if (!watcher.second.last_tag.empty()) |
| 95 watcher_item->last_tag.reset(new std::string(watcher.second.last_tag)); | 92 watcher_item.last_tag.reset(new std::string(watcher.second.last_tag)); |
| 96 watcher_items.push_back(watcher_item); | 93 output->watchers.push_back(std::move(watcher_item)); |
| 97 } | 94 } |
| 98 output->watchers = watcher_items; | |
| 99 | 95 |
| 100 std::vector<linked_ptr<OpenedFile>> opened_file_items; | |
| 101 for (const auto& opened_file : opened_files) { | 96 for (const auto& opened_file : opened_files) { |
| 102 const linked_ptr<OpenedFile> opened_file_item(new OpenedFile); | 97 OpenedFile opened_file_item; |
| 103 opened_file_item->open_request_id = opened_file.first; | 98 opened_file_item.open_request_id = opened_file.first; |
| 104 opened_file_item->file_path = opened_file.second.file_path.value(); | 99 opened_file_item.file_path = opened_file.second.file_path.value(); |
| 105 switch (opened_file.second.mode) { | 100 switch (opened_file.second.mode) { |
| 106 case chromeos::file_system_provider::OPEN_FILE_MODE_READ: | 101 case chromeos::file_system_provider::OPEN_FILE_MODE_READ: |
| 107 opened_file_item->mode = | 102 opened_file_item.mode = |
| 108 extensions::api::file_system_provider::OPEN_FILE_MODE_READ; | 103 extensions::api::file_system_provider::OPEN_FILE_MODE_READ; |
| 109 break; | 104 break; |
| 110 case chromeos::file_system_provider::OPEN_FILE_MODE_WRITE: | 105 case chromeos::file_system_provider::OPEN_FILE_MODE_WRITE: |
| 111 opened_file_item->mode = | 106 opened_file_item.mode = |
| 112 extensions::api::file_system_provider::OPEN_FILE_MODE_WRITE; | 107 extensions::api::file_system_provider::OPEN_FILE_MODE_WRITE; |
| 113 break; | 108 break; |
| 114 } | 109 } |
| 115 opened_file_items.push_back(opened_file_item); | 110 output->opened_files.push_back(std::move(opened_file_item)); |
| 116 } | 111 } |
| 117 output->opened_files = opened_file_items; | |
| 118 } | 112 } |
| 119 | 113 |
| 120 } // namespace | 114 } // namespace |
| 121 | 115 |
| 122 bool FileSystemProviderMountFunction::RunSync() { | 116 bool FileSystemProviderMountFunction::RunSync() { |
| 123 using api::file_system_provider::Mount::Params; | 117 using api::file_system_provider::Mount::Params; |
| 124 const scoped_ptr<Params> params(Params::Create(*args_)); | 118 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 125 EXTENSION_FUNCTION_VALIDATE(params); | 119 EXTENSION_FUNCTION_VALIDATE(params); |
| 126 | 120 |
| 127 // It's an error if the file system Id is empty. | 121 // It's an error if the file system Id is empty. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 return true; | 178 return true; |
| 185 } | 179 } |
| 186 | 180 |
| 187 bool FileSystemProviderGetAllFunction::RunSync() { | 181 bool FileSystemProviderGetAllFunction::RunSync() { |
| 188 using api::file_system_provider::FileSystemInfo; | 182 using api::file_system_provider::FileSystemInfo; |
| 189 Service* const service = Service::Get(GetProfile()); | 183 Service* const service = Service::Get(GetProfile()); |
| 190 DCHECK(service); | 184 DCHECK(service); |
| 191 | 185 |
| 192 const std::vector<ProvidedFileSystemInfo> file_systems = | 186 const std::vector<ProvidedFileSystemInfo> file_systems = |
| 193 service->GetProvidedFileSystemInfoList(); | 187 service->GetProvidedFileSystemInfoList(); |
| 194 std::vector<linked_ptr<FileSystemInfo>> items; | 188 std::vector<FileSystemInfo> items; |
| 195 | 189 |
| 196 for (const auto& file_system_info : file_systems) { | 190 for (const auto& file_system_info : file_systems) { |
| 197 if (file_system_info.extension_id() == extension_id()) { | 191 if (file_system_info.extension_id() == extension_id()) { |
| 198 const linked_ptr<FileSystemInfo> item(new FileSystemInfo); | 192 FileSystemInfo item; |
| 199 | 193 |
| 200 chromeos::file_system_provider::ProvidedFileSystemInterface* const | 194 chromeos::file_system_provider::ProvidedFileSystemInterface* const |
| 201 file_system = | 195 file_system = |
| 202 service->GetProvidedFileSystem(file_system_info.extension_id(), | 196 service->GetProvidedFileSystem(file_system_info.extension_id(), |
| 203 file_system_info.file_system_id()); | 197 file_system_info.file_system_id()); |
| 204 DCHECK(file_system); | 198 DCHECK(file_system); |
| 205 | 199 |
| 206 FillFileSystemInfo(file_system_info, *file_system->GetWatchers(), | 200 FillFileSystemInfo(file_system_info, *file_system->GetWatchers(), |
| 207 file_system->GetOpenedFiles(), item.get()); | 201 file_system->GetOpenedFiles(), &item); |
| 208 items.push_back(item); | 202 items.push_back(std::move(item)); |
| 209 } | 203 } |
| 210 } | 204 } |
| 211 | 205 |
| 212 SetResultList(api::file_system_provider::GetAll::Results::Create(items)); | 206 SetResultList(api::file_system_provider::GetAll::Results::Create(items)); |
| 213 return true; | 207 return true; |
| 214 } | 208 } |
| 215 | 209 |
| 216 bool FileSystemProviderGetFunction::RunSync() { | 210 bool FileSystemProviderGetFunction::RunSync() { |
| 217 using api::file_system_provider::Get::Params; | 211 using api::file_system_provider::Get::Params; |
| 218 scoped_ptr<Params> params(Params::Create(*args_)); | 212 scoped_ptr<Params> params(Params::Create(*args_)); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 using api::file_system_provider_internal::OperationRequestedError::Params; | 346 using api::file_system_provider_internal::OperationRequestedError::Params; |
| 353 scoped_ptr<Params> params(Params::Create(*args_)); | 347 scoped_ptr<Params> params(Params::Create(*args_)); |
| 354 EXTENSION_FUNCTION_VALIDATE(params); | 348 EXTENSION_FUNCTION_VALIDATE(params); |
| 355 | 349 |
| 356 const base::File::Error error = ProviderErrorToFileError(params->error); | 350 const base::File::Error error = ProviderErrorToFileError(params->error); |
| 357 return RejectRequest(RequestValue::CreateForOperationError(std::move(params)), | 351 return RejectRequest(RequestValue::CreateForOperationError(std::move(params)), |
| 358 error); | 352 error); |
| 359 } | 353 } |
| 360 | 354 |
| 361 } // namespace extensions | 355 } // namespace extensions |
| OLD | NEW |