1 // Copyright (c) 2012 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 "net/url_request/url_request_redirect_job.h"
8 #include "base/compiler_specific.h"
9 #include "base/message_loop/message_loop.h"
10 #include "net/base/load_timing_info.h"
14 URLRequestRedirectJob::URLRequestRedirectJob(URLRequest* request,
15 NetworkDelegate* network_delegate,
16 const GURL& redirect_destination,
17 StatusCode http_status_code)
18 : URLRequestJob(request, network_delegate),
19 redirect_destination_(redirect_destination),
20 http_status_code_(http_status_code),
21 weak_factory_(this) {}
23 void URLRequestRedirectJob::Start() {
24 base::MessageLoop::current()->PostTask(
26 base::Bind(&URLRequestRedirectJob::StartAsync,
27 weak_factory_.GetWeakPtr()));
30 bool URLRequestRedirectJob::IsRedirectResponse(GURL* location,
31 int* http_status_code) {
32 *location = redirect_destination_;
33 *http_status_code = http_status_code_;
37 URLRequestRedirectJob::~URLRequestRedirectJob() {}
39 void URLRequestRedirectJob::StartAsync() {
40 receive_headers_end_ = base::TimeTicks::Now();
41 NotifyHeadersComplete();
44 void URLRequestRedirectJob::GetLoadTimingInfo(
45 LoadTimingInfo* load_timing_info) const {
46 // Set send_start and send_end to receive_headers_end_ to keep consistent
47 // with network cache behavior.
48 load_timing_info->send_start = receive_headers_end_;
49 load_timing_info->send_end = receive_headers_end_;
50 load_timing_info->receive_headers_end = receive_headers_end_;