[Android] Add tests for toolbar of Chrome Custom Tabs
[chromium-blink-merge.git] / components / resource_provider / public / cpp / resource_loader.h
blob97f2b2ae3e04ba91749948c49c17ce7067f92fd3
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_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
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/application/public/interfaces/service_provider.mojom.h"
17 #include "mojo/platform_handle/platform_handle.h"
18 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h"
19 #include "third_party/mojo/src/mojo/public/cpp/system/handle.h"
21 namespace base {
22 class File;
25 namespace mojo {
26 class Shell;
29 namespace resource_provider {
31 // ResourceLoader handles making a request to ResourceProvider and blocking
32 // until the resources are available. Expected use is to create a ResourceLoader
33 // and shortly thereafter call BlockUntilLoaded() to wait until the resources
34 // have been obtained.
35 class ResourceLoader {
36 public:
37 ResourceLoader(mojo::Shell* shell, const std::set<std::string>& paths);
38 ~ResourceLoader();
40 // Uses WaitForIncomingMessage() to block until the results are available, or
41 // an error occurs. Returns true if the resources were obtained, false on
42 // error. This immediately returns if the resources have already been
43 // obtained.
44 bool BlockUntilLoaded();
46 // Releases and returns the file wrapping the handle.
47 base::File ReleaseFile(const std::string& path);
49 bool loaded() const { return loaded_; }
51 private:
52 using ResourceMap = std::map<std::string, scoped_ptr<base::File>>;
54 // Callback when resources have loaded.
55 void OnGotResources(const std::vector<std::string>& paths,
56 mojo::Array<mojo::ScopedHandle> resources);
58 mojo::ServiceProviderPtr resource_provider_service_provider_;
60 ResourceProviderPtr resource_provider_;
62 ResourceMap resource_map_;
64 bool loaded_;
65 bool did_block_;
67 DISALLOW_COPY_AND_ASSIGN(ResourceLoader);
70 } // namespace resource_provider
72 #endif // COMPONENTS_RESOURCE_PROVIDER_PUBLIC_CPP_RESOURCE_LOADER_H_