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 |
| 25 ContentLoFiUIService::~ContentLoFiUIService() {} |
| 26 |
| 27 void ContentLoFiUIService::NotifyLoFiReponseReceived( |
| 28 const net::URLRequest& request) const { |
| 29 int render_process_id = -1; |
| 30 int render_frame_id = -1; |
| 31 if (content::ResourceRequestInfo::GetRenderFrameForRequest( |
| 32 &request, &render_process_id, &render_frame_id)) { |
| 33 ui_task_runner_->PostTask( |
| 34 FROM_HERE, |
| 35 base::Bind(&ContentLoFiUIService::NotifyLoFiResponseReceivedOnUI, |
| 36 base::Unretained(this), render_process_id, render_frame_id)); |
| 37 } |
| 38 } |
| 39 |
| 40 void ContentLoFiUIService::NotifyLoFiResponseReceivedOnUI( |
| 41 int render_process_id, |
| 42 int render_frame_id) const { |
| 43 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 44 content::RenderFrameHost* frame = |
| 45 content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
| 46 if (frame) { |
| 47 DCHECK(!notify_lofi_response_received_callback_.is_null()); |
| 48 content::WebContents* web_contents = |
| 49 content::WebContents::FromRenderFrameHost(frame); |
| 50 notify_lofi_response_received_callback_.Run(web_contents); |
| 51 } |
| 52 } |
| 53 |
| 54 } // namespace data_reduction_proxy |
OLD | NEW |