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" |
(...skipping 10 matching lines...) Expand all Loading... |
21 MojoPlatformHandle platform_handle; | 21 MojoPlatformHandle platform_handle; |
22 CHECK(MojoExtractPlatformHandle(handle.release().value(), | 22 CHECK(MojoExtractPlatformHandle(handle.release().value(), |
23 &platform_handle) == MOJO_RESULT_OK); | 23 &platform_handle) == MOJO_RESULT_OK); |
24 return base::File(platform_handle); | 24 return base::File(platform_handle); |
25 } | 25 } |
26 } | 26 } |
27 | 27 |
28 ResourceLoader::ResourceLoader() {} | 28 ResourceLoader::ResourceLoader() {} |
29 ResourceLoader::~ResourceLoader() {} | 29 ResourceLoader::~ResourceLoader() {} |
30 | 30 |
31 bool ResourceLoader::OpenFiles(filesystem::DirectoryPtr directory, | 31 bool ResourceLoader::OpenFiles(filesystem::mojom::DirectoryPtr directory, |
32 const std::set<std::string>& paths) { | 32 const std::set<std::string>& paths) { |
33 mojo::Array<filesystem::FileOpenDetailsPtr> details( | 33 mojo::Array<filesystem::mojom::FileOpenDetailsPtr> details( |
34 mojo::Array<filesystem::FileOpenDetailsPtr>::New(paths.size())); | 34 mojo::Array<filesystem::mojom::FileOpenDetailsPtr>::New(paths.size())); |
35 size_t i = 0; | 35 size_t i = 0; |
36 for (const auto& path : paths) { | 36 for (const auto& path : paths) { |
37 filesystem::FileOpenDetailsPtr open_details( | 37 filesystem::mojom::FileOpenDetailsPtr open_details( |
38 filesystem::FileOpenDetails::New()); | 38 filesystem::mojom::FileOpenDetails::New()); |
39 open_details->path = path; | 39 open_details->path = path; |
40 open_details->open_flags = filesystem::kFlagOpen | filesystem::kFlagRead; | 40 open_details->open_flags = |
| 41 filesystem::mojom::kFlagOpen | filesystem::mojom::kFlagRead; |
41 details[i++] = std::move(open_details); | 42 details[i++] = std::move(open_details); |
42 } | 43 } |
43 | 44 |
44 mojo::Array<filesystem::FileOpenResultPtr> results( | 45 mojo::Array<filesystem::mojom::FileOpenResultPtr> results( |
45 mojo::Array<filesystem::FileOpenResultPtr>::New(paths.size())); | 46 mojo::Array<filesystem::mojom::FileOpenResultPtr>::New(paths.size())); |
46 if (!directory->OpenFileHandles(std::move(details), &results)) | 47 if (!directory->OpenFileHandles(std::move(details), &results)) |
47 return false; | 48 return false; |
48 | 49 |
49 for (const auto& result : results) { | 50 for (const auto& result : results) { |
50 resource_map_[result->path].reset( | 51 resource_map_[result->path].reset( |
51 new base::File(GetFileFromHandle(std::move(result->file_handle)))); | 52 new base::File(GetFileFromHandle(std::move(result->file_handle)))); |
52 } | 53 } |
53 return true; | 54 return true; |
54 } | 55 } |
55 | 56 |
56 base::File ResourceLoader::TakeFile(const std::string& path) { | 57 base::File ResourceLoader::TakeFile(const std::string& path) { |
57 std::unique_ptr<base::File> file_wrapper(std::move(resource_map_[path])); | 58 std::unique_ptr<base::File> file_wrapper(std::move(resource_map_[path])); |
58 resource_map_.erase(path); | 59 resource_map_.erase(path); |
59 return std::move(*file_wrapper); | 60 return std::move(*file_wrapper); |
60 } | 61 } |
61 | 62 |
62 } // namespace catalog | 63 } // namespace catalog |
OLD | NEW |