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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/catalog/public/cpp/resource_loader.cc
diff --git a/services/catalog/public/cpp/resource_loader.cc b/services/catalog/public/cpp/resource_loader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dc7fdc202df1662537efb75919a2e08089855a55
--- /dev/null
+++ b/services/catalog/public/cpp/resource_loader.cc
@@ -0,0 +1,62 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "services/catalog/public/cpp/resource_loader.h"
+
+#include <stddef.h>
+#include <utility>
+
+#include "base/bind.h"
+#include "base/files/file.h"
+#include "components/filesystem/public/interfaces/directory.mojom.h"
+#include "mojo/platform_handle/platform_handle_functions.h"
+#include "services/shell/public/cpp/connector.h"
+#include "services/shell/public/interfaces/interface_provider.mojom.h"
+
+namespace catalog {
+namespace {
+base::File GetFileFromHandle(mojo::ScopedHandle handle) {
+ CHECK(handle.is_valid());
+ MojoPlatformHandle platform_handle;
+ CHECK(MojoExtractPlatformHandle(handle.release().value(),
+ &platform_handle) == MOJO_RESULT_OK);
+ return base::File(platform_handle);
+}
+}
+
+ResourceLoader::ResourceLoader() {}
+ResourceLoader::~ResourceLoader() {}
+
+bool ResourceLoader::OpenFiles(filesystem::DirectoryPtr directory,
+ const std::set<std::string>& paths) {
+ mojo::Array<filesystem::FileOpenDetailsPtr> details(
+ mojo::Array<filesystem::FileOpenDetailsPtr>::New(paths.size()));
+ size_t i = 0;
+ for (const auto& path : paths) {
+ filesystem::FileOpenDetailsPtr open_details(
+ filesystem::FileOpenDetails::New());
+ open_details->path = path;
+ open_details->open_flags = filesystem::kFlagOpen | filesystem::kFlagRead;
+ details[i++] = std::move(open_details);
+ }
+
+ mojo::Array<filesystem::FileOpenResultPtr> results(
+ mojo::Array<filesystem::FileOpenResultPtr>::New(paths.size()));
+ if (!directory->OpenFileHandles(std::move(details), &results))
+ return false;
+
+ for (const auto& result : results) {
+ resource_map_[result->path].reset(
+ new base::File(GetFileFromHandle(std::move(result->file_handle))));
+ }
+ return true;
+}
+
+base::File ResourceLoader::TakeFile(const std::string& path) {
+ std::unique_ptr<base::File> file_wrapper(std::move(resource_map_[path]));
+ resource_map_.erase(path);
+ return std::move(*file_wrapper);
+}
+
+} // namespace catalog
« 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