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