OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/data_reduction_proxy/content/browser/content_lofi_ui_servic
e.h" | 5 #include "components/data_reduction_proxy/content/browser/content_lofi_ui_servic
e.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
11 #include "content/public/browser/render_frame_host.h" | 11 #include "content/public/browser/render_frame_host.h" |
12 #include "content/public/browser/resource_request_info.h" | 12 #include "content/public/browser/resource_request_info.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
15 | 15 |
16 namespace data_reduction_proxy { | 16 namespace data_reduction_proxy { |
17 | 17 |
18 ContentLoFiUIService::ContentLoFiUIService( | 18 ContentLoFiUIService::ContentLoFiUIService( |
19 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | 19 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
20 const OnLoFiResponseReceivedCallback& | 20 const OnLoFiResponseReceivedCallback& |
21 notify_lofi_response_received_callback) | 21 notify_lofi_response_received_callback) |
22 : ui_task_runner_(ui_task_runner), | 22 : ui_task_runner_(ui_task_runner), |
23 on_lofi_response_received_callback_( | 23 on_lofi_response_received_callback_( |
24 notify_lofi_response_received_callback) { | 24 notify_lofi_response_received_callback) { |
25 DCHECK(!on_lofi_response_received_callback_.is_null()); | 25 DCHECK(!on_lofi_response_received_callback_.is_null()); |
26 } | 26 } |
27 | 27 |
28 ContentLoFiUIService::~ContentLoFiUIService() {} | 28 ContentLoFiUIService::~ContentLoFiUIService() {} |
29 | 29 |
30 void ContentLoFiUIService::OnLoFiReponseReceived( | 30 void ContentLoFiUIService::OnLoFiReponseReceived(const net::URLRequest& request, |
31 const net::URLRequest& request) { | 31 bool is_preview) { |
32 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 32 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
33 int render_process_id = -1; | 33 int render_process_id = -1; |
34 int render_frame_id = -1; | 34 int render_frame_id = -1; |
35 if (content::ResourceRequestInfo::GetRenderFrameForRequest( | 35 if (content::ResourceRequestInfo::GetRenderFrameForRequest( |
36 &request, &render_process_id, &render_frame_id)) { | 36 &request, &render_process_id, &render_frame_id)) { |
37 ui_task_runner_->PostTask( | 37 ui_task_runner_->PostTask( |
38 FROM_HERE, | 38 FROM_HERE, |
39 base::Bind(&ContentLoFiUIService::OnLoFiResponseReceivedOnUIThread, | 39 base::Bind(&ContentLoFiUIService::OnLoFiResponseReceivedOnUIThread, |
40 base::Unretained(this), render_process_id, render_frame_id)); | 40 base::Unretained(this), render_process_id, render_frame_id, |
| 41 is_preview)); |
41 } | 42 } |
42 } | 43 } |
43 | 44 |
44 void ContentLoFiUIService::OnLoFiResponseReceivedOnUIThread( | 45 void ContentLoFiUIService::OnLoFiResponseReceivedOnUIThread( |
45 int render_process_id, | 46 int render_process_id, |
46 int render_frame_id) { | 47 int render_frame_id, |
| 48 bool is_preview) { |
47 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 49 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
48 content::RenderFrameHost* frame = | 50 content::RenderFrameHost* frame = |
49 content::RenderFrameHost::FromID(render_process_id, render_frame_id); | 51 content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
50 if (frame) { | 52 if (frame) { |
51 DCHECK(!on_lofi_response_received_callback_.is_null()); | 53 DCHECK(!on_lofi_response_received_callback_.is_null()); |
52 content::WebContents* web_contents = | 54 content::WebContents* web_contents = |
53 content::WebContents::FromRenderFrameHost(frame); | 55 content::WebContents::FromRenderFrameHost(frame); |
54 on_lofi_response_received_callback_.Run(web_contents); | 56 on_lofi_response_received_callback_.Run(web_contents, is_preview); |
55 } | 57 } |
56 } | 58 } |
57 | 59 |
58 } // namespace data_reduction_proxy | 60 } // namespace data_reduction_proxy |
OLD | NEW |