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.
5 #ifndef COMPONENTS_RESOURCE_PROVIDER_PUBLIC_CPP_RESOURCE_LOADER_H_
6 #define COMPONENTS_RESOURCE_PROVIDER_PUBLIC_CPP_RESOURCE_LOADER_H_
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "components/resource_provider/public/interfaces/resource_provider.mojom.h"
16 #include "mojo/platform_handle/platform_handle.h"
17 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h"
18 #include "third_party/mojo/src/mojo/public/cpp/system/handle.h"
28 namespace resource_provider
{
30 // ResourceLoader handles making a request to ResourceProvider and blocking
31 // until the resources are available. Expected use is to create a ResourceLoader
32 // and shortly thereafter call BlockUntilLoaded() to wait until the resources
33 // have been obtained.
34 class ResourceLoader
{
36 ResourceLoader(mojo::Shell
* shell
, const std::set
<std::string
>& paths
);
39 // Uses WaitForIncomingMessage() to block until the results are available, or
40 // an error occurs. Returns true if the resources were obtained, false on
41 // error. This immediately returns if the resources have already been
43 bool BlockUntilLoaded();
45 // Releases and returns the file wrapping the handle.
46 base::File
ReleaseFile(const std::string
& path
);
48 base::File
GetICUFile();
50 bool loaded() const { return loaded_
; }
53 using ResourceMap
= std::map
<std::string
, scoped_ptr
<base::File
>>;
55 // Callback when resources have loaded.
56 void OnGotResources(const std::vector
<std::string
>& paths
,
57 mojo::Array
<mojo::ScopedHandle
> resources
);
58 void OnGotICU(base::File
* file
, mojo::ScopedHandle handle
);
60 ResourceProviderPtr resource_provider_
;
62 ResourceMap resource_map_
;
67 DISALLOW_COPY_AND_ASSIGN(ResourceLoader
);
70 } // namespace resource_provider
72 #endif // COMPONENTS_RESOURCE_PROVIDER_PUBLIC_CPP_RESOURCE_LOADER_H_