| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/catalog/public/cpp/resource_loader.h" | 5 #include "services/catalog/public/cpp/resource_loader.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/files/file.h" | 11 #include "base/files/file.h" |
| 12 #include "components/filesystem/public/interfaces/directory.mojom.h" | 12 #include "components/filesystem/public/interfaces/directory.mojom.h" |
| 13 #include "mojo/platform_handle/platform_handle_functions.h" | 13 #include "mojo/public/cpp/system/platform_handle.h" |
| 14 #include "services/shell/public/cpp/connector.h" | 14 #include "services/shell/public/cpp/connector.h" |
| 15 #include "services/shell/public/interfaces/interface_provider.mojom.h" | 15 #include "services/shell/public/interfaces/interface_provider.mojom.h" |
| 16 | 16 |
| 17 namespace catalog { | 17 namespace catalog { |
| 18 |
| 18 namespace { | 19 namespace { |
| 20 |
| 19 base::File GetFileFromHandle(mojo::ScopedHandle handle) { | 21 base::File GetFileFromHandle(mojo::ScopedHandle handle) { |
| 20 CHECK(handle.is_valid()); | 22 CHECK(handle.is_valid()); |
| 21 MojoPlatformHandle platform_handle; | 23 base::PlatformFile platform_file; |
| 22 CHECK(MojoExtractPlatformHandle(handle.release().value(), | 24 CHECK_EQ(mojo::UnwrapPlatformFile(std::move(handle), &platform_file), |
| 23 &platform_handle) == MOJO_RESULT_OK); | 25 MOJO_RESULT_OK); |
| 24 return base::File(platform_handle); | 26 return base::File(platform_file); |
| 25 } | 27 } |
| 26 } | 28 |
| 29 } // namespace |
| 27 | 30 |
| 28 ResourceLoader::ResourceLoader() {} | 31 ResourceLoader::ResourceLoader() {} |
| 29 ResourceLoader::~ResourceLoader() {} | 32 ResourceLoader::~ResourceLoader() {} |
| 30 | 33 |
| 31 bool ResourceLoader::OpenFiles(filesystem::mojom::DirectoryPtr directory, | 34 bool ResourceLoader::OpenFiles(filesystem::mojom::DirectoryPtr directory, |
| 32 const std::set<std::string>& paths) { | 35 const std::set<std::string>& paths) { |
| 33 mojo::Array<filesystem::mojom::FileOpenDetailsPtr> details( | 36 mojo::Array<filesystem::mojom::FileOpenDetailsPtr> details( |
| 34 mojo::Array<filesystem::mojom::FileOpenDetailsPtr>::New(paths.size())); | 37 mojo::Array<filesystem::mojom::FileOpenDetailsPtr>::New(paths.size())); |
| 35 size_t i = 0; | 38 size_t i = 0; |
| 36 for (const auto& path : paths) { | 39 for (const auto& path : paths) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 54 return true; | 57 return true; |
| 55 } | 58 } |
| 56 | 59 |
| 57 base::File ResourceLoader::TakeFile(const std::string& path) { | 60 base::File ResourceLoader::TakeFile(const std::string& path) { |
| 58 std::unique_ptr<base::File> file_wrapper(std::move(resource_map_[path])); | 61 std::unique_ptr<base::File> file_wrapper(std::move(resource_map_[path])); |
| 59 resource_map_.erase(path); | 62 resource_map_.erase(path); |
| 60 return std::move(*file_wrapper); | 63 return std::move(*file_wrapper); |
| 61 } | 64 } |
| 62 | 65 |
| 63 } // namespace catalog | 66 } // namespace catalog |
| OLD | NEW |