OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/extension_function_dispatcher.h" | 5 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 error)); | 142 error)); |
143 } | 143 } |
144 | 144 |
145 void IOThreadResponseCallback( | 145 void IOThreadResponseCallback( |
146 const base::WeakPtr<ChromeRenderMessageFilter>& ipc_sender, | 146 const base::WeakPtr<ChromeRenderMessageFilter>& ipc_sender, |
147 int routing_id, | 147 int routing_id, |
148 int request_id, | 148 int request_id, |
149 ExtensionFunction::ResponseType type, | 149 ExtensionFunction::ResponseType type, |
150 const base::ListValue& results, | 150 const base::ListValue& results, |
151 const std::string& error) { | 151 const std::string& error) { |
152 if (!ipc_sender) | 152 if (!ipc_sender.get()) |
153 return; | 153 return; |
154 | 154 |
155 CommonResponseCallback(ipc_sender, routing_id, ipc_sender->peer_handle(), | 155 CommonResponseCallback(ipc_sender.get(), |
156 request_id, type, results, error); | 156 routing_id, |
| 157 ipc_sender->peer_handle(), |
| 158 request_id, |
| 159 type, |
| 160 results, |
| 161 error); |
157 } | 162 } |
158 | 163 |
159 } // namespace | 164 } // namespace |
160 | 165 |
161 class ExtensionFunctionDispatcher::UIThreadResponseCallbackWrapper | 166 class ExtensionFunctionDispatcher::UIThreadResponseCallbackWrapper |
162 : public content::RenderViewHostObserver { | 167 : public content::RenderViewHostObserver { |
163 public: | 168 public: |
164 UIThreadResponseCallbackWrapper( | 169 UIThreadResponseCallbackWrapper( |
165 const base::WeakPtr<ExtensionFunctionDispatcher>& dispatcher, | 170 const base::WeakPtr<ExtensionFunctionDispatcher>& dispatcher, |
166 RenderViewHost* render_view_host) | 171 RenderViewHost* render_view_host) |
167 : content::RenderViewHostObserver(render_view_host), | 172 : content::RenderViewHostObserver(render_view_host), |
168 dispatcher_(dispatcher), | 173 dispatcher_(dispatcher), |
169 weak_ptr_factory_(this) { | 174 weak_ptr_factory_(this) { |
170 } | 175 } |
171 | 176 |
172 virtual ~UIThreadResponseCallbackWrapper() { | 177 virtual ~UIThreadResponseCallbackWrapper() { |
173 } | 178 } |
174 | 179 |
175 // content::RenderViewHostObserver overrides. | 180 // content::RenderViewHostObserver overrides. |
176 virtual void RenderViewHostDestroyed( | 181 virtual void RenderViewHostDestroyed( |
177 RenderViewHost* render_view_host) OVERRIDE { | 182 RenderViewHost* render_view_host) OVERRIDE { |
178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
179 if (dispatcher_) { | 184 if (dispatcher_.get()) { |
180 dispatcher_->ui_thread_response_callback_wrappers_.erase( | 185 dispatcher_->ui_thread_response_callback_wrappers_ |
181 render_view_host); | 186 .erase(render_view_host); |
182 } | 187 } |
183 | 188 |
184 // This call will delete |this|. | 189 // This call will delete |this|. |
185 content::RenderViewHostObserver::RenderViewHostDestroyed(render_view_host); | 190 content::RenderViewHostObserver::RenderViewHostDestroyed(render_view_host); |
186 } | 191 } |
187 | 192 |
188 ExtensionFunction::ResponseCallback CreateCallback(int request_id) { | 193 ExtensionFunction::ResponseCallback CreateCallback(int request_id) { |
189 return base::Bind( | 194 return base::Bind( |
190 &UIThreadResponseCallbackWrapper::OnExtensionFunctionCompleted, | 195 &UIThreadResponseCallbackWrapper::OnExtensionFunctionCompleted, |
191 weak_ptr_factory_.GetWeakPtr(), | 196 weak_ptr_factory_.GetWeakPtr(), |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 return function; | 531 return function; |
527 } | 532 } |
528 | 533 |
529 // static | 534 // static |
530 void ExtensionFunctionDispatcher::SendAccessDenied( | 535 void ExtensionFunctionDispatcher::SendAccessDenied( |
531 const ExtensionFunction::ResponseCallback& callback) { | 536 const ExtensionFunction::ResponseCallback& callback) { |
532 ListValue empty_list; | 537 ListValue empty_list; |
533 callback.Run(ExtensionFunction::FAILED, empty_list, | 538 callback.Run(ExtensionFunction::FAILED, empty_list, |
534 "Access to extension API denied."); | 539 "Access to extension API denied."); |
535 } | 540 } |
OLD | NEW |