url_request_redirect_job.cc revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
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. 4 5#include "net/url_request/url_request_redirect_job.h" 6 7#include "base/bind.h" 8#include "base/compiler_specific.h" 9#include "base/logging.h" 10#include "base/message_loop/message_loop.h" 11#include "net/base/load_timing_info.h" 12#include "net/base/net_log.h" 13#include "net/url_request/url_request.h" 14 15namespace net { 16 17URLRequestRedirectJob::URLRequestRedirectJob(URLRequest* request, 18 NetworkDelegate* network_delegate, 19 const GURL& redirect_destination, 20 StatusCode http_status_code, 21 const std::string& redirect_reason) 22 : URLRequestJob(request, network_delegate), 23 redirect_destination_(redirect_destination), 24 http_status_code_(http_status_code), 25 redirect_reason_(redirect_reason), 26 weak_factory_(this) { 27 DCHECK(!redirect_reason_.empty()); 28} 29 30void URLRequestRedirectJob::Start() { 31 request()->net_log().AddEvent( 32 NetLog::TYPE_URL_REQUEST_REDIRECT_JOB, 33 NetLog::StringCallback("reason", &redirect_reason_)); 34 base::MessageLoop::current()->PostTask( 35 FROM_HERE, 36 base::Bind(&URLRequestRedirectJob::StartAsync, 37 weak_factory_.GetWeakPtr())); 38} 39 40bool URLRequestRedirectJob::IsRedirectResponse(GURL* location, 41 int* http_status_code) { 42 *location = redirect_destination_; 43 *http_status_code = http_status_code_; 44 return true; 45} 46 47bool URLRequestRedirectJob::CopyFragmentOnRedirect(const GURL& location) const { 48 // The instantiators have full control over the desired redirection target, 49 // including the reference fragment part of the URL. 50 return false; 51} 52 53URLRequestRedirectJob::~URLRequestRedirectJob() {} 54 55void URLRequestRedirectJob::StartAsync() { 56 receive_headers_end_ = base::TimeTicks::Now(); 57 NotifyHeadersComplete(); 58} 59 60void URLRequestRedirectJob::GetLoadTimingInfo( 61 LoadTimingInfo* load_timing_info) const { 62 // Set send_start and send_end to receive_headers_end_ to keep consistent 63 // with network cache behavior. 64 load_timing_info->send_start = receive_headers_end_; 65 load_timing_info->send_end = receive_headers_end_; 66 load_timing_info->receive_headers_end = receive_headers_end_; 67} 68 69} // namespace net 70