url_request_redirect_job.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
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/message_loop.h"
10
11namespace net {
12
13URLRequestRedirectJob::URLRequestRedirectJob(URLRequest* request,
14                                             NetworkDelegate* network_delegate,
15                                             const GURL& redirect_destination)
16    : URLRequestJob(request, network_delegate),
17      redirect_destination_(redirect_destination),
18      http_status_code_(302),
19      ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {}
20
21void URLRequestRedirectJob::Start() {
22  MessageLoop::current()->PostTask(
23      FROM_HERE,
24      base::Bind(&URLRequestRedirectJob::StartAsync,
25                 weak_factory_.GetWeakPtr()));
26}
27
28bool URLRequestRedirectJob::IsRedirectResponse(GURL* location,
29                                               int* http_status_code) {
30  *location = redirect_destination_;
31  *http_status_code = http_status_code_;
32  return true;
33}
34
35URLRequestRedirectJob::~URLRequestRedirectJob() {}
36
37void URLRequestRedirectJob::StartAsync() {
38  NotifyHeadersComplete();
39}
40
41}  // namespace net
42