Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / browser / manifest / manifest_manager_host.h
1 // Copyright 2014 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.
4
5 #ifndef CONTENT_RENDERER_MANIFEST_MANIFEST_MANAGER_HOST_H_
6 #define CONTENT_RENDERER_MANIFEST_MANIFEST_MANAGER_HOST_H_
7
8 #include "base/callback_forward.h"
9 #include "base/id_map.h"
10 #include "content/public/browser/web_contents_observer.h"
11
12 namespace content {
13
14 class RenderFrameHost;
15 class WebContents;
16 struct Manifest;
17
18 // ManifestManagerHost is a helper class that allows callers to get the Manifest
19 // associated with a frame. It handles the IPC messaging with the child process.
20 // TODO(mlamouri): keep a cached version and a dirty bit here.
21 class ManifestManagerHost : public WebContentsObserver {
22  public:
23   explicit ManifestManagerHost(WebContents* web_contents);
24   ~ManifestManagerHost() override;
25
26   typedef base::Callback<void(const Manifest&)> GetManifestCallback;
27
28   // Calls the given callback with the manifest associated with the
29   // given RenderFrameHost. If the frame has no manifest or if getting it failed
30   // the callback will have an empty manifest.
31   void GetManifest(RenderFrameHost*, const GetManifestCallback&);
32
33   // WebContentsObserver
34   bool OnMessageReceived(const IPC::Message&, RenderFrameHost*) override;
35   void RenderFrameDeleted(RenderFrameHost*) override;
36
37  private:
38   typedef IDMap<GetManifestCallback, IDMapOwnPointer> CallbackMap;
39   typedef base::hash_map<RenderFrameHost*, CallbackMap*> FrameCallbackMap;
40
41   void OnRequestManifestResponse(
42       RenderFrameHost*, int request_id, const Manifest&);
43
44   // Returns the CallbackMap associated with the given RenderFrameHost, or null.
45   CallbackMap* GetCallbackMapForFrame(RenderFrameHost*);
46
47   FrameCallbackMap pending_callbacks_;
48
49   DISALLOW_COPY_AND_ASSIGN(ManifestManagerHost);
50 };
51
52 } // namespace content
53
54 #endif // CONTENT_RENDERER_MANIFEST_MANIFEST_MANAGER_HOST_H_