| 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/application_impl.h" | 9 #include "mojo/application/public/cpp/application_impl.h" |
| 10 #include "mojo/application/public/cpp/connect.h" | 10 #include "mojo/application/public/cpp/connect.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 return loaded_; | 49 return loaded_; |
| 50 } | 50 } |
| 51 | 51 |
| 52 base::File ResourceLoader::ReleaseFile(const std::string& path) { | 52 base::File ResourceLoader::ReleaseFile(const std::string& path) { |
| 53 CHECK(resource_map_.count(path)); | 53 CHECK(resource_map_.count(path)); |
| 54 scoped_ptr<base::File> file_wrapper(resource_map_[path].Pass()); | 54 scoped_ptr<base::File> file_wrapper(resource_map_[path].Pass()); |
| 55 resource_map_.erase(path); | 55 resource_map_.erase(path); |
| 56 return file_wrapper->Pass(); | 56 return file_wrapper->Pass(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 base::File ResourceLoader::GetICUFile() { | |
| 60 base::File rv; | |
| 61 resource_provider_->GetICUHandle( | |
| 62 base::Bind(&ResourceLoader::OnGotICU, base::Unretained(this), &rv)); | |
| 63 resource_provider_.WaitForIncomingResponse(); | |
| 64 CHECK(rv.IsValid()); | |
| 65 return rv.Pass(); | |
| 66 } | |
| 67 | |
| 68 void ResourceLoader::OnGotResources(const std::vector<std::string>& paths, | 59 void ResourceLoader::OnGotResources(const std::vector<std::string>& paths, |
| 69 mojo::Array<mojo::ScopedHandle> resources) { | 60 mojo::Array<mojo::ScopedHandle> resources) { |
| 70 | 61 |
| 71 CHECK(!resources.is_null()); | 62 CHECK(!resources.is_null()); |
| 72 CHECK_EQ(resources.size(), paths.size()); | 63 CHECK_EQ(resources.size(), paths.size()); |
| 73 for (size_t i = 0; i < resources.size(); ++i) { | 64 for (size_t i = 0; i < resources.size(); ++i) { |
| 74 resource_map_[paths[i]].reset( | 65 resource_map_[paths[i]].reset( |
| 75 new base::File(GetFileFromHandle(resources[i].Pass()))); | 66 new base::File(GetFileFromHandle(resources[i].Pass()))); |
| 76 } | 67 } |
| 77 loaded_ = true; | 68 loaded_ = true; |
| 78 } | 69 } |
| 79 | 70 |
| 80 void ResourceLoader::OnGotICU(base::File* file, mojo::ScopedHandle handle) { | |
| 81 *file = GetFileFromHandle(handle.Pass()); | |
| 82 } | |
| 83 | |
| 84 } // namespace resource_provider | 71 } // namespace resource_provider |
| OLD | NEW |