OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/browser/loader_delegate_impl.h" | 5 #include "content/browser/loader_delegate_impl.h" |
6 | 6 |
7 #include "content/browser/frame_host/render_frame_host_impl.h" | |
7 #include "content/browser/renderer_host/render_view_host_impl.h" | 8 #include "content/browser/renderer_host/render_view_host_impl.h" |
9 #include "content/browser/web_contents/web_contents_impl.h" | |
8 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
9 | 11 |
10 namespace content { | 12 namespace content { |
11 | 13 |
12 LoaderDelegateImpl::~LoaderDelegateImpl() {} | 14 LoaderDelegateImpl::~LoaderDelegateImpl() {} |
13 | 15 |
14 void LoaderDelegateImpl::LoadStateChanged( | 16 void LoaderDelegateImpl::LoadStateChanged( |
15 int child_id, | 17 int child_id, |
16 int route_id, | 18 int route_id, |
17 const GURL& url, | 19 const GURL& url, |
18 const net::LoadStateWithParam& load_state, | 20 const net::LoadStateWithParam& load_state, |
19 uint64_t upload_position, | 21 uint64_t upload_position, |
20 uint64_t upload_size) { | 22 uint64_t upload_size) { |
mmenke
2016/06/29 15:17:13
These should all DCHECK what thread we're on, for
jam
2016/06/29 17:19:45
IMO that's needless, i.e. we don't dcheck every si
mmenke
2016/06/29 17:52:52
I agree that classes that run on a single thread d
scottmg
2016/06/29 17:55:40
Done. (I agree with jam that it's pretty clear rig
jam
2016/06/29 18:13:23
Regarding running on multiple threads, that's not
mmenke
2016/06/29 18:20:51
RDH was being used in a non-threadsafe manner on t
jam
2016/06/29 20:36:48
We may be saying the same thing.. i.e. in the bug
mmenke
2016/06/29 20:39:24
They were being called by an external consumer.
| |
21 BrowserThread::PostTask( | 23 BrowserThread::PostTask( |
22 BrowserThread::UI, FROM_HERE, | 24 BrowserThread::UI, FROM_HERE, |
23 base::Bind(&LoaderDelegateImpl::NotifyLoadStateChangedOnUI, | 25 base::Bind(&LoaderDelegateImpl::NotifyLoadStateChangedOnUI, |
24 base::Unretained(this), child_id, route_id, url, load_state, | 26 base::Unretained(this), child_id, route_id, url, load_state, |
25 upload_position, upload_size)); | 27 upload_position, upload_size)); |
26 } | 28 } |
27 | 29 |
30 void LoaderDelegateImpl::DidGetResourceResponseStart( | |
31 int render_process_id, | |
32 int render_frame_host, | |
33 std::unique_ptr<ResourceRequestDetails> details) { | |
34 BrowserThread::PostTask( | |
35 BrowserThread::UI, FROM_HERE, | |
36 base::Bind(&LoaderDelegateImpl::DidGetResourceResponseStartOnUI, | |
37 base::Unretained(this), render_process_id, render_frame_host, | |
38 base::Passed(std::move(details)))); | |
39 } | |
40 | |
41 void LoaderDelegateImpl::DidGetRedirectForResourceRequest( | |
42 int render_process_id, | |
43 int render_frame_host, | |
44 std::unique_ptr<ResourceRedirectDetails> details) { | |
45 BrowserThread::PostTask( | |
46 BrowserThread::UI, FROM_HERE, | |
47 base::Bind(&LoaderDelegateImpl::DidGetRedirectForResourceRequestOnUI, | |
48 base::Unretained(this), render_process_id, render_frame_host, | |
mmenke
2016/06/29 15:17:13
What guarantees that the loader hasn't been delete
mmenke
2016/06/29 15:53:48
Actually...Everything we do on the UI thread can j
jam
2016/06/29 17:19:46
+1 to moving these methods to anonymous namespace
scottmg
2016/06/29 17:55:40
LoaderDelegate does need to outlive the RDH, I add
| |
49 base::Passed(std::move(details)))); | |
50 } | |
51 | |
28 void LoaderDelegateImpl::NotifyLoadStateChangedOnUI( | 52 void LoaderDelegateImpl::NotifyLoadStateChangedOnUI( |
29 int child_id, | 53 int child_id, |
30 int route_id, | 54 int route_id, |
31 const GURL& url, | 55 const GURL& url, |
32 const net::LoadStateWithParam& load_state, | 56 const net::LoadStateWithParam& load_state, |
33 uint64_t upload_position, | 57 uint64_t upload_position, |
34 uint64_t upload_size) { | 58 uint64_t upload_size) { |
35 RenderViewHostImpl* view = RenderViewHostImpl::FromID(child_id, route_id); | 59 RenderViewHostImpl* view = RenderViewHostImpl::FromID(child_id, route_id); |
36 if (view) | 60 if (view) |
37 view->LoadStateChanged(url, load_state, upload_position, upload_size); | 61 view->LoadStateChanged(url, load_state, upload_position, upload_size); |
38 } | 62 } |
39 | 63 |
64 void LoaderDelegateImpl::DidGetResourceResponseStartOnUI( | |
65 int render_process_id, | |
66 int render_frame_host, | |
67 std::unique_ptr<ResourceRequestDetails> details) { | |
68 RenderFrameHostImpl* host = | |
69 RenderFrameHostImpl::FromID(render_process_id, render_frame_host); | |
70 WebContentsImpl* web_contents = | |
71 static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(host)); | |
72 if (!web_contents) | |
73 return; | |
74 web_contents->DidGetResourceResponseStart(*details.get()); | |
75 } | |
76 | |
77 void LoaderDelegateImpl::DidGetRedirectForResourceRequestOnUI( | |
78 int render_process_id, | |
79 int render_frame_host, | |
80 std::unique_ptr<ResourceRedirectDetails> details) { | |
81 RenderFrameHostImpl* host = | |
82 RenderFrameHostImpl::FromID(render_process_id, render_frame_host); | |
83 WebContentsImpl* web_contents = | |
84 static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(host)); | |
85 if (!web_contents) | |
86 return; | |
87 web_contents->DidGetRedirectForResourceRequest(host, *details.get()); | |
88 } | |
89 | |
40 } // namespace content | 90 } // namespace content |
OLD | NEW |