OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/manifest/manifest_manager_host.h" | 5 #include "content/browser/manifest/manifest_manager_host.h" |
6 | 6 |
7 #include "content/common/manifest_manager_messages.h" | 7 #include "content/common/manifest_manager_messages.h" |
8 #include "content/public/browser/render_frame_host.h" | 8 #include "content/public/browser/render_frame_host.h" |
9 #include "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
10 #include "content/public/common/manifest.h" | 10 #include "content/public/common/manifest.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 return it != pending_callbacks_.end() ? it->second : 0; | 37 return it != pending_callbacks_.end() ? it->second : 0; |
38 } | 38 } |
39 | 39 |
40 void ManifestManagerHost::RenderFrameDeleted( | 40 void ManifestManagerHost::RenderFrameDeleted( |
41 RenderFrameHost* render_frame_host) { | 41 RenderFrameHost* render_frame_host) { |
42 CallbackMap* callbacks = GetCallbackMapForFrame(render_frame_host); | 42 CallbackMap* callbacks = GetCallbackMapForFrame(render_frame_host); |
43 if (!callbacks) | 43 if (!callbacks) |
44 return; | 44 return; |
45 | 45 |
46 // Before deleting the callbacks, make sure they are called with a failure | 46 // Before deleting the callbacks, make sure they are called with a failure |
47 // state. | 47 // state. Do this in a block so the iterator is destroyed before |callbacks|. |
48 CallbackMap::const_iterator it(callbacks); | 48 { |
49 for (; !it.IsAtEnd(); it.Advance()) | 49 CallbackMap::const_iterator it(callbacks); |
50 it.GetCurrentValue()->Run(Manifest()); | 50 for (; !it.IsAtEnd(); it.Advance()) |
| 51 it.GetCurrentValue()->Run(Manifest()); |
| 52 } |
51 | 53 |
| 54 delete callbacks; |
52 pending_callbacks_.erase(render_frame_host); | 55 pending_callbacks_.erase(render_frame_host); |
53 } | 56 } |
54 | 57 |
55 void ManifestManagerHost::GetManifest(RenderFrameHost* render_frame_host, | 58 void ManifestManagerHost::GetManifest(RenderFrameHost* render_frame_host, |
56 const GetManifestCallback& callback) { | 59 const GetManifestCallback& callback) { |
57 CallbackMap* callbacks = GetCallbackMapForFrame(render_frame_host); | 60 CallbackMap* callbacks = GetCallbackMapForFrame(render_frame_host); |
58 if (!callbacks) { | 61 if (!callbacks) { |
59 callbacks = new CallbackMap(); | 62 callbacks = new CallbackMap(); |
60 pending_callbacks_[render_frame_host] = callbacks; | 63 pending_callbacks_[render_frame_host] = callbacks; |
61 } | 64 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 129 |
127 callback->Run(manifest); | 130 callback->Run(manifest); |
128 callbacks->Remove(request_id); | 131 callbacks->Remove(request_id); |
129 if (callbacks->IsEmpty()) { | 132 if (callbacks->IsEmpty()) { |
130 delete callbacks; | 133 delete callbacks; |
131 pending_callbacks_.erase(render_frame_host); | 134 pending_callbacks_.erase(render_frame_host); |
132 } | 135 } |
133 } | 136 } |
134 | 137 |
135 } // namespace content | 138 } // namespace content |
OLD | NEW |