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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "mojo/application/public/cpp/connect.h" | 9 #include "mojo/application/public/cpp/connect.h" |
10 #include "mojo/application/public/interfaces/shell.mojom.h" | 10 #include "mojo/application/public/interfaces/shell.mojom.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 } | 31 } |
32 | 32 |
33 ResourceLoader::~ResourceLoader() { | 33 ResourceLoader::~ResourceLoader() { |
34 } | 34 } |
35 | 35 |
36 bool ResourceLoader::BlockUntilLoaded() { | 36 bool ResourceLoader::BlockUntilLoaded() { |
37 if (did_block_ || loaded_) | 37 if (did_block_ || loaded_) |
38 return loaded_; | 38 return loaded_; |
39 | 39 |
40 did_block_ = true; | 40 did_block_ = true; |
41 resource_provider_.WaitForIncomingResponse(); | 41 resource_provider_.WaitForIncomingMethodCall(); |
42 return loaded_; | 42 return loaded_; |
43 } | 43 } |
44 | 44 |
45 base::File ResourceLoader::ReleaseFile(const std::string& path) { | 45 base::File ResourceLoader::ReleaseFile(const std::string& path) { |
46 CHECK(resource_map_.count(path)); | 46 CHECK(resource_map_.count(path)); |
47 scoped_ptr<base::File> file_wrapper(resource_map_[path].Pass()); | 47 scoped_ptr<base::File> file_wrapper(resource_map_[path].Pass()); |
48 resource_map_.erase(path); | 48 resource_map_.erase(path); |
49 return file_wrapper->Pass(); | 49 return file_wrapper->Pass(); |
50 } | 50 } |
51 | 51 |
52 void ResourceLoader::OnGotResources(const std::vector<std::string>& paths, | 52 void ResourceLoader::OnGotResources(const std::vector<std::string>& paths, |
53 mojo::Array<mojo::ScopedHandle> resources) { | 53 mojo::Array<mojo::ScopedHandle> resources) { |
54 // We no longer need the connection to ResourceProvider. | 54 // We no longer need the connection to ResourceProvider. |
55 resource_provider_.reset(); | 55 resource_provider_.reset(); |
56 resource_provider_service_provider_.reset(); | 56 resource_provider_service_provider_.reset(); |
57 | 57 |
58 CHECK(!resources.is_null()); | 58 CHECK(!resources.is_null()); |
59 CHECK_EQ(resources.size(), paths.size()); | 59 CHECK_EQ(resources.size(), paths.size()); |
60 for (size_t i = 0; i < resources.size(); ++i) { | 60 for (size_t i = 0; i < resources.size(); ++i) { |
61 CHECK(resources[i].is_valid()); | 61 CHECK(resources[i].is_valid()); |
62 MojoPlatformHandle platform_handle; | 62 MojoPlatformHandle platform_handle; |
63 CHECK(MojoExtractPlatformHandle(resources[i].release().value(), | 63 CHECK(MojoExtractPlatformHandle(resources[i].release().value(), |
64 &platform_handle) == MOJO_RESULT_OK); | 64 &platform_handle) == MOJO_RESULT_OK); |
65 resource_map_[paths[i]].reset(new base::File(platform_handle)); | 65 resource_map_[paths[i]].reset(new base::File(platform_handle)); |
66 } | 66 } |
67 loaded_ = true; | 67 loaded_ = true; |
68 } | 68 } |
69 | 69 |
70 } // namespace resource_provider | 70 } // namespace resource_provider |
OLD | NEW |