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

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
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/connector.mojom.h"
16 #include "services/shell/public/interfaces/interface_provider.mojom.h"
17
18 namespace catalog {
19 namespace {
20 base::File GetFileFromHandle(mojo::ScopedHandle handle) {
21 CHECK(handle.is_valid());
22 MojoPlatformHandle platform_handle;
23 CHECK(MojoExtractPlatformHandle(handle.release().value(),
24 &platform_handle) == MOJO_RESULT_OK);
25 return base::File(platform_handle);
26 }
27 }
28
29 ResourceLoader::ResourceLoader(shell::Connector* connector,
30 const std::set<std::string>& paths) {
31 filesystem::DirectoryPtr directory;
32 connector->ConnectToInterface("mojo:catalog", &directory);
33
34 /*
35 mojo::Array<filesystem::FileOpenDetailsPtr> deets(
36 mojo::Array<filesystem::FileOpenDetailsPtr>::new(paths.size()));
37 size_t i = 0;
38 for (const auto& path : paths) {
39 filesystem::FileOpenDetailsPtr open_details(filesystem::FileOpenDetails::New ());
40 open_details->path = path;
41 open_details->open_flags = 0;
42 deets[i++] = std::move(open_details);
43 }
44
45 mojo::Array<filesystem::FileOpenResultPtr> results(
46 mojo::Array<filesystem::FileOpenResultPtr>::New(paths.size())));
47 directory->OpenFileHandles(std::move(deets), &results);
48
49 CHECK_EQ(results.size(), paths.size());
50 for (const auto& result : results) {
51 resource_map_[result->path].reset(
52 new base::File(GetFileFromHandle(std::move(result->file_handle))));
53 }
54 */
55 }
56
57 ResourceLoader::~ResourceLoader() {
58 }
59
60 base::File ResourceLoader::TakeFile(const std::string& path) {
61 CHECK(resource_map_.count(path));
62 std::unique_ptr<base::File> file_wrapper(std::move(resource_map_[path]));
63 resource_map_.erase(path);
64 return std::move(*file_wrapper);
65 }
66
67 } // namespace catalog
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698