Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: services/catalog/public/cpp/resource_loader.cc

Issue 1942473002: Eliminate mojo:resource_provider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/catalog/public/cpp/resource_loader.h ('k') | services/shell/shell.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "services/catalog/public/cpp/resource_loader.h"
6
7 #include <stddef.h>
8 #include <utility>
9
10 #include "base/bind.h"
11 #include "base/files/file.h"
12 #include "components/filesystem/public/interfaces/directory.mojom.h"
13 #include "mojo/platform_handle/platform_handle_functions.h"
14 #include "services/shell/public/cpp/connector.h"
15 #include "services/shell/public/interfaces/interface_provider.mojom.h"
16
17 namespace catalog {
18 namespace {
19 base::File GetFileFromHandle(mojo::ScopedHandle handle) {
20 CHECK(handle.is_valid());
21 MojoPlatformHandle platform_handle;
22 CHECK(MojoExtractPlatformHandle(handle.release().value(),
23 &platform_handle) == MOJO_RESULT_OK);
24 return base::File(platform_handle);
25 }
26 }
27
28 ResourceLoader::ResourceLoader() {}
29 ResourceLoader::~ResourceLoader() {}
30
31 bool ResourceLoader::OpenFiles(filesystem::DirectoryPtr directory,
32 const std::set<std::string>& paths) {
33 mojo::Array<filesystem::FileOpenDetailsPtr> details(
34 mojo::Array<filesystem::FileOpenDetailsPtr>::New(paths.size()));
35 size_t i = 0;
36 for (const auto& path : paths) {
37 filesystem::FileOpenDetailsPtr open_details(
38 filesystem::FileOpenDetails::New());
39 open_details->path = path;
40 open_details->open_flags = filesystem::kFlagOpen | filesystem::kFlagRead;
41 details[i++] = std::move(open_details);
42 }
43
44 mojo::Array<filesystem::FileOpenResultPtr> results(
45 mojo::Array<filesystem::FileOpenResultPtr>::New(paths.size()));
46 if (!directory->OpenFileHandles(std::move(details), &results))
47 return false;
48
49 for (const auto& result : results) {
50 resource_map_[result->path].reset(
51 new base::File(GetFileFromHandle(std::move(result->file_handle))));
52 }
53 return true;
54 }
55
56 base::File ResourceLoader::TakeFile(const std::string& path) {
57 std::unique_ptr<base::File> file_wrapper(std::move(resource_map_[path]));
58 resource_map_.erase(path);
59 return std::move(*file_wrapper);
60 }
61
62 } // namespace catalog
OLDNEW
« no previous file with comments | « services/catalog/public/cpp/resource_loader.h ('k') | services/shell/shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698