OLD | NEW |
---|---|
(Empty) | |
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 #include "content/browser/manifest/manifest_manager_host.h" | |
6 | |
7 #include "content/common/manifest_manager_messages.h" | |
8 #include "content/public/browser/render_frame_host.h" | |
9 #include "content/public/common/manifest.h" | |
10 | |
11 namespace content { | |
12 | |
13 ManifestManagerHost::ManifestManagerHost(WebContents* web_contents) | |
14 : WebContentsObserver(web_contents) { | |
15 } | |
16 | |
17 ManifestManagerHost::~ManifestManagerHost() { | |
18 } | |
19 | |
20 ManifestManagerHost::CallbackMap* ManifestManagerHost::GetCallbackMapForFrame( | |
21 RenderFrameHost* render_frame_host) { | |
22 FrameCallbackMap::iterator it = pending_callbacks_.find(render_frame_host); | |
23 if (it == pending_callbacks_.end()) | |
24 return 0; | |
25 return it->second; | |
kenneth.christiansen
2014/09/11 09:33:09
Wouldn't it be nicer in one line?
return (it != p
mlamouri (slow - plz ping)
2014/09/11 10:30:32
Done.
| |
26 } | |
27 | |
28 void ManifestManagerHost::RenderFrameDeleted( | |
29 RenderFrameHost* render_frame_host) { | |
30 CallbackMap* callbacks = GetCallbackMapForFrame(render_frame_host); | |
31 if (!callbacks) | |
32 return; | |
33 | |
34 // Before deleting the callbacks, make sure they are called with a failure | |
35 // state. | |
36 CallbackMap::const_iterator it(callbacks); | |
37 for (; !it.IsAtEnd(); it.Advance()) | |
38 it.GetCurrentValue()->Run(Manifest()); | |
kenneth.christiansen
2014/09/11 09:33:09
Is that a failure state?
mlamouri (slow - plz ping)
2014/09/11 10:30:32
Yes. An empty manifest is returned if no manifest
| |
39 | |
40 pending_callbacks_.erase(render_frame_host); | |
41 } | |
42 | |
43 void ManifestManagerHost::GetManifest(RenderFrameHost* render_frame_host, | |
44 const GetManifestCallback& callback) { | |
45 CallbackMap* callbacks = GetCallbackMapForFrame(render_frame_host); | |
46 if (!callbacks) { | |
47 callbacks = new CallbackMap(); | |
48 pending_callbacks_[render_frame_host] = callbacks; | |
49 } | |
50 | |
51 int request_id = callbacks->Add(new GetManifestCallback(callback)); | |
52 | |
53 render_frame_host->Send(new ManifestManagerMsg_RequestManifest( | |
54 render_frame_host->GetRoutingID(), request_id)); | |
55 } | |
56 | |
57 bool ManifestManagerHost::OnMessageReceived( | |
58 const IPC::Message& message, RenderFrameHost* render_frame_host) { | |
59 bool handled = true; | |
60 | |
61 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ManifestManagerHost, message, | |
62 render_frame_host) | |
63 IPC_MESSAGE_HANDLER(ManifestManagerHostMsg_RequestManifestResponse, | |
64 OnRequestManifestResponse) | |
65 IPC_MESSAGE_UNHANDLED(handled = false) | |
66 IPC_END_MESSAGE_MAP() | |
67 | |
68 return handled; | |
69 } | |
70 | |
71 void ManifestManagerHost::OnRequestManifestResponse( | |
72 RenderFrameHost* render_frame_host, | |
73 int request_id, | |
74 const Manifest& manifest) { | |
75 CallbackMap* callbacks = GetCallbackMapForFrame(render_frame_host); | |
76 if (!callbacks) { | |
77 LOG(ERROR) << "Received a ManifestResponse for a RFH not waiting for it"; | |
kenneth.christiansen
2014/09/11 09:33:09
without waiting for it?
Unexpectedly received a M
mlamouri (slow - plz ping)
2014/09/11 10:30:32
"Unexpected ManifestResponse to RFH."
| |
78 return; | |
79 } | |
80 | |
81 GetManifestCallback* callback = callbacks->Lookup(request_id); | |
82 if (!callback) { | |
83 LOG(ERROR) << "Received a request_id (" << request_id << ") from renderer " | |
84 "with no associated callabck."; | |
kenneth.christiansen
2014/09/11 09:33:09
spelling issue: callabck.
mlamouri (slow - plz ping)
2014/09/11 10:30:32
Done.
| |
85 return; | |
86 } | |
87 | |
88 callback->Run(manifest); | |
89 callbacks->Remove(request_id); | |
90 if (callbacks->IsEmpty()) { | |
91 delete callbacks; | |
92 pending_callbacks_.erase(render_frame_host); | |
93 } | |
94 } | |
95 | |
96 } // namespace content | |
OLD | NEW |