OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/resource_provider/public/cpp/resource_loader.h" | 5 #include "components/resource_provider/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" |
11 #include "base/files/file.h" | 11 #include "base/files/file.h" |
12 #include "mojo/common/common_type_converters.h" | 12 #include "mojo/common/common_type_converters.h" |
13 #include "mojo/platform_handle/platform_handle_functions.h" | 13 #include "mojo/platform_handle/platform_handle_functions.h" |
14 #include "mojo/shell/public/cpp/application_impl.h" | 14 #include "mojo/shell/public/cpp/shell.h" |
15 #include "mojo/shell/public/cpp/connect.h" | |
16 #include "mojo/shell/public/interfaces/service_provider.mojom.h" | 15 #include "mojo/shell/public/interfaces/service_provider.mojom.h" |
17 #include "mojo/shell/public/interfaces/shell.mojom.h" | 16 #include "mojo/shell/public/interfaces/shell.mojom.h" |
18 | 17 |
19 namespace resource_provider { | 18 namespace resource_provider { |
20 namespace { | 19 namespace { |
21 base::File GetFileFromHandle(mojo::ScopedHandle handle) { | 20 base::File GetFileFromHandle(mojo::ScopedHandle handle) { |
22 CHECK(handle.is_valid()); | 21 CHECK(handle.is_valid()); |
23 MojoPlatformHandle platform_handle; | 22 MojoPlatformHandle platform_handle; |
24 CHECK(MojoExtractPlatformHandle(handle.release().value(), | 23 CHECK(MojoExtractPlatformHandle(handle.release().value(), |
25 &platform_handle) == MOJO_RESULT_OK); | 24 &platform_handle) == MOJO_RESULT_OK); |
26 return base::File(platform_handle); | 25 return base::File(platform_handle); |
27 } | 26 } |
28 } | 27 } |
29 | 28 |
30 ResourceLoader::ResourceLoader(mojo::ApplicationImpl* app, | 29 ResourceLoader::ResourceLoader(mojo::Shell* shell, |
31 const std::set<std::string>& paths) | 30 const std::set<std::string>& paths) |
32 : loaded_(false), did_block_(false) { | 31 : loaded_(false), did_block_(false) { |
33 app->ConnectToService("mojo:resource_provider", &resource_provider_); | 32 shell->ConnectToService("mojo:resource_provider", &resource_provider_); |
34 std::vector<std::string> paths_vector(paths.begin(), paths.end()); | 33 std::vector<std::string> paths_vector(paths.begin(), paths.end()); |
35 resource_provider_->GetResources( | 34 resource_provider_->GetResources( |
36 mojo::Array<mojo::String>::From(paths_vector), | 35 mojo::Array<mojo::String>::From(paths_vector), |
37 base::Bind(&ResourceLoader::OnGotResources, base::Unretained(this), | 36 base::Bind(&ResourceLoader::OnGotResources, base::Unretained(this), |
38 paths_vector)); | 37 paths_vector)); |
39 } | 38 } |
40 | 39 |
41 ResourceLoader::~ResourceLoader() { | 40 ResourceLoader::~ResourceLoader() { |
42 } | 41 } |
43 | 42 |
(...skipping 19 matching lines...) Expand all Loading... |
63 CHECK(!resources.is_null()); | 62 CHECK(!resources.is_null()); |
64 CHECK_EQ(resources.size(), paths.size()); | 63 CHECK_EQ(resources.size(), paths.size()); |
65 for (size_t i = 0; i < resources.size(); ++i) { | 64 for (size_t i = 0; i < resources.size(); ++i) { |
66 resource_map_[paths[i]].reset( | 65 resource_map_[paths[i]].reset( |
67 new base::File(GetFileFromHandle(std::move(resources[i])))); | 66 new base::File(GetFileFromHandle(std::move(resources[i])))); |
68 } | 67 } |
69 loaded_ = true; | 68 loaded_ = true; |
70 } | 69 } |
71 | 70 |
72 } // namespace resource_provider | 71 } // namespace resource_provider |
OLD | NEW |