OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/frame_host/navigation_request.h" | 5 #include "content/browser/frame_host/navigation_request.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 8 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
9 #include "content/common/resource_request_body.h" | 9 #include "content/common/resource_request_body.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 void OnBeginNavigation(const NavigationRequestInfo& info, | 16 void OnBeginNavigation(const NavigationRequestInfo& info, |
17 scoped_refptr<ResourceRequestBody> request_body, | 17 scoped_refptr<ResourceRequestBody> request_body, |
| 18 int64 navigation_request_id, |
18 int64 frame_node_id) { | 19 int64 frame_node_id) { |
19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 20 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
20 ResourceDispatcherHostImpl::Get()->NavigationRequest( | 21 ResourceDispatcherHostImpl::Get()->StartNavigationRequest( |
21 info, request_body, frame_node_id); | 22 info, request_body, navigation_request_id, frame_node_id); |
| 23 } |
| 24 |
| 25 void OnDestructNavigationRequest(int64 navigation_request_id, |
| 26 int64 frame_node_id) { |
| 27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 28 ResourceDispatcherHostImpl::Get()->CancelNavigationRequest( |
| 29 navigation_request_id, frame_node_id); |
22 } | 30 } |
23 | 31 |
24 } // namespace | 32 } // namespace |
25 | 33 |
| 34 int64 NavigationRequest::next_navigation_request_id_ = 0; |
| 35 |
26 NavigationRequest::NavigationRequest(const NavigationRequestInfo& info, | 36 NavigationRequest::NavigationRequest(const NavigationRequestInfo& info, |
27 int64 frame_node_id) | 37 int64 frame_node_id) |
28 : info_(info), | 38 : navigation_request_id_(++next_navigation_request_id_), |
| 39 info_(info), |
29 frame_node_id_(frame_node_id) { | 40 frame_node_id_(frame_node_id) { |
30 } | 41 } |
31 | 42 |
32 NavigationRequest::~NavigationRequest() { | 43 NavigationRequest::~NavigationRequest() { |
33 // TODO(clamy): Cancel the corresponding request in ResourceDispatcherHost if | 44 // TODO(carlosk): Figure out when the navigation actually needs to be |
34 // it has not commited yet. | 45 // cancelled. |
| 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 47 BrowserThread::PostTask( |
| 48 BrowserThread::IO, |
| 49 FROM_HERE, |
| 50 base::Bind(&OnDestructNavigationRequest, |
| 51 navigation_request_id_, frame_node_id_)); |
35 } | 52 } |
36 | 53 |
37 void NavigationRequest::BeginNavigation( | 54 void NavigationRequest::BeginNavigation( |
38 scoped_refptr<ResourceRequestBody> request_body) { | 55 scoped_refptr<ResourceRequestBody> request_body) { |
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
40 BrowserThread::PostTask( | 57 BrowserThread::PostTask( |
41 BrowserThread::IO, | 58 BrowserThread::IO, |
42 FROM_HERE, | 59 FROM_HERE, |
43 base::Bind(&OnBeginNavigation, info_, request_body, frame_node_id_)); | 60 base::Bind(&OnBeginNavigation, |
| 61 info_, |
| 62 request_body, |
| 63 navigation_request_id_, |
| 64 frame_node_id_)); |
44 } | 65 } |
45 | 66 |
46 } // namespace content | 67 } // namespace content |
OLD | NEW |