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

Side by Side Diff: components/resource_provider/resource_provider_impl.cc

Issue 1108403008: Adds resource_provider::ResourceProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 5 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 2015 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 "components/resource_provider/resource_provider_impl.h"
6
7 #include "base/bind.h"
8 #include "base/files/file_util.h"
9 #include "base/location.h"
10 #include "base/logging.h"
11 #include "components/resource_provider/file_utils.h"
12 #include "mojo/platform_handle/platform_handle_functions.h"
13
14 using mojo::ScopedHandle;
15
16 namespace resource_provider {
17 namespace {
18
19 ScopedHandle GetHandleForPath(const base::FilePath& path) {
20 if (path.empty())
21 return ScopedHandle();
22
23 ScopedHandle to_pass;
24 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ);
25 if (!file.IsValid())
26 return ScopedHandle();
27
28 MojoHandle mojo_handle;
29 if (MojoCreatePlatformHandleWrapper(file.TakePlatformFile(), &mojo_handle) !=
30 MOJO_RESULT_OK)
31 return ScopedHandle();
32
33 return ScopedHandle(mojo::Handle(mojo_handle)).Pass();
34 }
35
36 } // namespace
37
38 ResourceProviderImpl::ResourceProviderImpl(
39 const base::FilePath& application_path)
40 : application_path_(application_path) {
41 CHECK(!application_path_.empty());
42 }
43
44 ResourceProviderImpl::~ResourceProviderImpl() {
45 }
46
47 void ResourceProviderImpl::GetResources(mojo::Array<mojo::String> paths,
48 const GetResourcesCallback& callback) {
49 mojo::Array<mojo::ScopedHandle> handles;
50 if (!paths.is_null()) {
51 handles.resize(paths.size());
52 for (size_t i = 0; i < paths.size(); ++i) {
53 handles[i] = GetHandleForPath(
54 GetPathForResourceNamed(application_path_, paths[i]));
55 }
56 }
57 callback.Run(handles.Pass());
58 }
59
60 } // namespace resource_provider
OLDNEW
« no previous file with comments | « components/resource_provider/resource_provider_impl.h ('k') | components/test/data/resource_provider/dir/sample2 » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698