Chromium Code Reviews| Index: content/browser/manifest/manifest_manager_host.cc |
| diff --git a/content/browser/manifest/manifest_manager_host.cc b/content/browser/manifest/manifest_manager_host.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ae9967de1f63d19615748d158812f2f585d09455 |
| --- /dev/null |
| +++ b/content/browser/manifest/manifest_manager_host.cc |
| @@ -0,0 +1,96 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/manifest/manifest_manager_host.h" |
| + |
| +#include "content/common/manifest_manager_messages.h" |
| +#include "content/public/browser/render_frame_host.h" |
| +#include "content/public/common/manifest.h" |
| + |
| +namespace content { |
| + |
| +ManifestManagerHost::ManifestManagerHost(WebContents* web_contents) |
| + : WebContentsObserver(web_contents) { |
| +} |
| + |
| +ManifestManagerHost::~ManifestManagerHost() { |
| +} |
| + |
| +ManifestManagerHost::CallbackMap* ManifestManagerHost::GetCallbackMapForFrame( |
| + RenderFrameHost* render_frame_host) { |
| + FrameCallbackMap::iterator it = pending_callbacks_.find(render_frame_host); |
| + if (it == pending_callbacks_.end()) |
| + return 0; |
| + 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.
|
| +} |
| + |
| +void ManifestManagerHost::RenderFrameDeleted( |
| + RenderFrameHost* render_frame_host) { |
| + CallbackMap* callbacks = GetCallbackMapForFrame(render_frame_host); |
| + if (!callbacks) |
| + return; |
| + |
| + // Before deleting the callbacks, make sure they are called with a failure |
| + // state. |
| + CallbackMap::const_iterator it(callbacks); |
| + for (; !it.IsAtEnd(); it.Advance()) |
| + 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
|
| + |
| + pending_callbacks_.erase(render_frame_host); |
| +} |
| + |
| +void ManifestManagerHost::GetManifest(RenderFrameHost* render_frame_host, |
| + const GetManifestCallback& callback) { |
| + CallbackMap* callbacks = GetCallbackMapForFrame(render_frame_host); |
| + if (!callbacks) { |
| + callbacks = new CallbackMap(); |
| + pending_callbacks_[render_frame_host] = callbacks; |
| + } |
| + |
| + int request_id = callbacks->Add(new GetManifestCallback(callback)); |
| + |
| + render_frame_host->Send(new ManifestManagerMsg_RequestManifest( |
| + render_frame_host->GetRoutingID(), request_id)); |
| +} |
| + |
| +bool ManifestManagerHost::OnMessageReceived( |
| + const IPC::Message& message, RenderFrameHost* render_frame_host) { |
| + bool handled = true; |
| + |
| + IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ManifestManagerHost, message, |
| + render_frame_host) |
| + IPC_MESSAGE_HANDLER(ManifestManagerHostMsg_RequestManifestResponse, |
| + OnRequestManifestResponse) |
| + IPC_MESSAGE_UNHANDLED(handled = false) |
| + IPC_END_MESSAGE_MAP() |
| + |
| + return handled; |
| +} |
| + |
| +void ManifestManagerHost::OnRequestManifestResponse( |
| + RenderFrameHost* render_frame_host, |
| + int request_id, |
| + const Manifest& manifest) { |
| + CallbackMap* callbacks = GetCallbackMapForFrame(render_frame_host); |
| + if (!callbacks) { |
| + 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."
|
| + return; |
| + } |
| + |
| + GetManifestCallback* callback = callbacks->Lookup(request_id); |
| + if (!callback) { |
| + LOG(ERROR) << "Received a request_id (" << request_id << ") from renderer " |
| + "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.
|
| + return; |
| + } |
| + |
| + callback->Run(manifest); |
| + callbacks->Remove(request_id); |
| + if (callbacks->IsEmpty()) { |
| + delete callbacks; |
| + pending_callbacks_.erase(render_frame_host); |
| + } |
| +} |
| + |
| +} // namespace content |