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.
5 #ifndef CONTENT_RENDERER_MANIFEST_MANIFEST_MANAGER_HOST_H_
6 #define CONTENT_RENDERER_MANIFEST_MANIFEST_MANAGER_HOST_H_
8 #include "base/callback_forward.h"
9 #include "base/id_map.h"
10 #include "content/public/browser/web_contents_observer.h"
14 class RenderFrameHost
;
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
{
23 explicit ManifestManagerHost(WebContents
* web_contents
);
24 ~ManifestManagerHost() override
;
26 typedef base::Callback
<void(const Manifest
&)> GetManifestCallback
;
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
&);
33 // WebContentsObserver
34 bool OnMessageReceived(const IPC::Message
&, RenderFrameHost
*) override
;
35 void RenderFrameDeleted(RenderFrameHost
*) override
;
38 typedef IDMap
<GetManifestCallback
, IDMapOwnPointer
> CallbackMap
;
39 typedef base::hash_map
<RenderFrameHost
*, CallbackMap
*> FrameCallbackMap
;
41 void OnRequestManifestResponse(
42 RenderFrameHost
*, int request_id
, const Manifest
&);
44 // Returns the CallbackMap associated with the given RenderFrameHost, or null.
45 CallbackMap
* GetCallbackMapForFrame(RenderFrameHost
*);
47 FrameCallbackMap pending_callbacks_
;
49 DISALLOW_COPY_AND_ASSIGN(ManifestManagerHost
);
52 } // namespace content
54 #endif // CONTENT_RENDERER_MANIFEST_MANIFEST_MANAGER_HOST_H_