OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 "components/data_reduction_proxy/content/browser/content_lofi_ui_servic e.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/location.h" | |
9 #include "base/single_thread_task_runner.h" | |
10 #include "content/public/browser/render_frame_host.h" | |
11 #include "content/public/browser/resource_request_info.h" | |
12 #include "content/public/browser/web_contents.h" | |
13 #include "net/url_request/url_request.h" | |
14 | |
15 namespace data_reduction_proxy { | |
16 | |
17 ContentLoFiUIService::ContentLoFiUIService( | |
18 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | |
19 const NotifyLoFiResponseReceivedCallback& | |
20 notify_lofi_response_received_callback) | |
21 : ui_task_runner_(ui_task_runner), | |
22 notify_lofi_response_received_callback_( | |
23 notify_lofi_response_received_callback) { | |
24 DCHECK(!notify_lofi_response_received_callback_.is_null()); | |
25 } | |
26 | |
27 ContentLoFiUIService::~ContentLoFiUIService() {} | |
28 | |
29 void ContentLoFiUIService::NotifyLoFiReponseReceived( | |
30 const net::URLRequest& request) { | |
tbansal1
2016/01/05 21:07:09
Add DCHECK that this is currently on IO thread?
megjablon
2016/01/06 17:20:47
Done.
| |
31 int render_process_id = -1; | |
32 int render_frame_id = -1; | |
33 if (content::ResourceRequestInfo::GetRenderFrameForRequest( | |
34 &request, &render_process_id, &render_frame_id)) { | |
35 ui_task_runner_->PostTask( | |
36 FROM_HERE, | |
37 base::Bind(&ContentLoFiUIService::NotifyLoFiResponseReceivedOnUI, | |
38 base::Unretained(this), render_process_id, render_frame_id)); | |
39 } | |
40 } | |
41 | |
42 void ContentLoFiUIService::NotifyLoFiResponseReceivedOnUI(int render_process_id, | |
43 int render_frame_id) { | |
44 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
45 content::RenderFrameHost* frame = | |
tbansal1
2016/01/05 21:07:09
nit: const
megjablon
2016/01/06 17:20:47
FromRenderFrameHost takes as non-const pointer so
| |
46 content::RenderFrameHost::FromID(render_process_id, render_frame_id); | |
47 if (frame) { | |
48 DCHECK(!notify_lofi_response_received_callback_.is_null()); | |
49 content::WebContents* web_contents = | |
50 content::WebContents::FromRenderFrameHost(frame); | |
51 notify_lofi_response_received_callback_.Run(web_contents); | |
52 } | |
53 } | |
54 | |
55 } // namespace data_reduction_proxy | |
OLD | NEW |