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
3 // found in the LICENSE file.
5 #include "content/browser/loader/navigation_url_loader_impl.h"
8 #include "base/location.h"
9 #include "content/browser/frame_host/navigation_request_info.h"
10 #include "content/browser/loader/navigation_url_loader_delegate.h"
11 #include "content/browser/loader/navigation_url_loader_impl_core.h"
12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/stream_handle.h"
18 NavigationURLLoaderImpl::NavigationURLLoaderImpl(
19 BrowserContext
* browser_context
,
20 int64 frame_tree_node_id
,
21 const CommonNavigationParams
& common_params
,
22 scoped_ptr
<NavigationRequestInfo
> request_info
,
23 ResourceRequestBody
* request_body
,
24 NavigationURLLoaderDelegate
* delegate
)
25 : delegate_(delegate
),
27 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
29 core_
= new NavigationURLLoaderImplCore(weak_factory_
.GetWeakPtr());
30 BrowserThread::PostTask(
31 BrowserThread::IO
, FROM_HERE
,
32 base::Bind(&NavigationURLLoaderImplCore::Start
, base::Unretained(core_
),
33 browser_context
->GetResourceContext(), frame_tree_node_id
,
34 common_params
, base::Passed(&request_info
),
35 make_scoped_refptr(request_body
)));
38 NavigationURLLoaderImpl::~NavigationURLLoaderImpl() {
39 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
41 BrowserThread::DeleteSoon(BrowserThread::IO
, FROM_HERE
, core_
);
45 void NavigationURLLoaderImpl::FollowRedirect() {
46 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
48 BrowserThread::PostTask(
49 BrowserThread::IO
, FROM_HERE
,
50 base::Bind(&NavigationURLLoaderImplCore::FollowRedirect
,
51 base::Unretained(core_
)));
54 void NavigationURLLoaderImpl::NotifyRequestRedirected(
55 const net::RedirectInfo
& redirect_info
,
56 const scoped_refptr
<ResourceResponse
>& response
) {
57 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
59 delegate_
->OnRequestRedirected(redirect_info
, response
);
62 void NavigationURLLoaderImpl::NotifyResponseStarted(
63 const scoped_refptr
<ResourceResponse
>& response
,
64 scoped_ptr
<StreamHandle
> body
) {
65 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
67 delegate_
->OnResponseStarted(response
, body
.Pass());
70 void NavigationURLLoaderImpl::NotifyRequestFailed(int net_error
) {
71 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
73 delegate_
->OnRequestFailed(net_error
);
76 } // namespace content