blob: ed18401cb65a773159f9228a4f1290ce2b8bcb45 [file] [log] [blame]
[email protected]78376af2012-02-07 06:56:281// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]71e1ac42011-03-23 00:46:534
[email protected]6981d9632010-11-30 21:34:025// This file contains URLFetcher, a wrapper around net::URLRequest that handles
initial.commit09911bf2008-07-26 23:55:296// low-level details like thread safety, ref counting, and incremental buffer
7// reading. This is useful for callers who simply want to get the data from a
8// URL and don't care about all the nitty-gritty details.
[email protected]0b1ad312010-10-22 01:01:389//
10// NOTE(willchan): Only one "IO" thread is supported for URLFetcher. This is a
11// temporary situation. We will work on allowing support for multiple "io"
12// threads per process.
initial.commit09911bf2008-07-26 23:55:2913
[email protected]7b419b82011-10-27 04:23:4614#ifndef CONTENT_COMMON_NET_URL_FETCHER_IMPL_H_
15#define CONTENT_COMMON_NET_URL_FETCHER_IMPL_H_
[email protected]32b76ef2010-07-26 23:08:2416#pragma once
initial.commit09911bf2008-07-26 23:55:2917
[email protected]d2106bc912012-04-02 13:47:0118#include "base/basictypes.h"
[email protected]7cc6e5632011-10-25 17:56:1219#include "base/compiler_specific.h"
[email protected]d2106bc912012-04-02 13:47:0120#include "content/common/content_export.h"
[email protected]7cc6e5632011-10-25 17:56:1221#include "content/public/common/url_fetcher.h"
initial.commit09911bf2008-07-26 23:55:2922
[email protected]beba03b32011-10-26 23:39:5923namespace content {
[email protected]d2106bc912012-04-02 13:47:0124class URLFetcherCore;
25class URLFetcherDelegate;
[email protected]beba03b32011-10-26 23:39:5926class URLFetcherFactory;
[email protected]d2106bc912012-04-02 13:47:0127} // namespace content
[email protected]beba03b32011-10-26 23:39:5928
[email protected]d2106bc912012-04-02 13:47:0129class CONTENT_EXPORT URLFetcherImpl : public content::URLFetcher {
initial.commit09911bf2008-07-26 23:55:2930 public:
initial.commit09911bf2008-07-26 23:55:2931 // |url| is the URL to send the request to.
32 // |request_type| is the type of request to make.
33 // |d| the object that will receive the callback on fetch completion.
[email protected]7b419b82011-10-27 04:23:4634 URLFetcherImpl(const GURL& url,
35 RequestType request_type,
36 content::URLFetcherDelegate* d);
37 virtual ~URLFetcherImpl();
[email protected]b6c911a2009-04-21 21:58:4538
[email protected]7cc6e5632011-10-25 17:56:1239 // content::URLFetcher implementation:
40 virtual void SetUploadData(const std::string& upload_content_type,
41 const std::string& upload_content) OVERRIDE;
42 virtual void SetChunkedUpload(
43 const std::string& upload_content_type) OVERRIDE;
44 virtual void AppendChunkToUpload(const std::string& data,
45 bool is_last_chunk) OVERRIDE;
46 virtual void SetLoadFlags(int load_flags) OVERRIDE;
47 virtual int GetLoadFlags() const OVERRIDE;
48 virtual void SetReferrer(const std::string& referrer) OVERRIDE;
49 virtual void SetExtraRequestHeaders(
50 const std::string& extra_request_headers) OVERRIDE;
[email protected]78376af2012-02-07 06:56:2851 virtual void AddExtraRequestHeader(const std::string& header_line) OVERRIDE;
[email protected]7cc6e5632011-10-25 17:56:1252 virtual void GetExtraRequestHeaders(
[email protected]d2106bc912012-04-02 13:47:0153 net::HttpRequestHeaders* headers) const OVERRIDE;
[email protected]7cc6e5632011-10-25 17:56:1254 virtual void SetRequestContext(
55 net::URLRequestContextGetter* request_context_getter) OVERRIDE;
[email protected]7c3bb862012-05-22 00:14:4156 virtual void SetFirstPartyForCookies(
57 const GURL& first_party_for_cookies) OVERRIDE;
58 virtual void SetURLRequestUserData(
59 const void* key,
60 const CreateDataCallback& create_data_callback) OVERRIDE;
[email protected]7cc6e5632011-10-25 17:56:1261 virtual void SetAutomaticallyRetryOn5xx(bool retry) OVERRIDE;
62 virtual void SetMaxRetries(int max_retries) OVERRIDE;
63 virtual int GetMaxRetries() const OVERRIDE;
64 virtual base::TimeDelta GetBackoffDelay() const OVERRIDE;
[email protected]32c82012012-03-09 23:25:4465 virtual void SaveResponseToFileAtPath(
66 const FilePath& file_path,
67 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) OVERRIDE;
[email protected]7cc6e5632011-10-25 17:56:1268 virtual void SaveResponseToTemporaryFile(
69 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) OVERRIDE;
70 virtual net::HttpResponseHeaders* GetResponseHeaders() const OVERRIDE;
71 virtual net::HostPortPair GetSocketAddress() const OVERRIDE;
72 virtual bool WasFetchedViaProxy() const OVERRIDE;
73 virtual void Start() OVERRIDE;
[email protected]5645d5b2011-10-28 00:40:4874 virtual const GURL& GetOriginalURL() const OVERRIDE;
75 virtual const GURL& GetURL() const OVERRIDE;
[email protected]7cc6e5632011-10-25 17:56:1276 virtual const net::URLRequestStatus& GetStatus() const OVERRIDE;
77 virtual int GetResponseCode() const OVERRIDE;
78 virtual const net::ResponseCookies& GetCookies() const OVERRIDE;
79 virtual bool FileErrorOccurred(
80 base::PlatformFileError* out_error_code) const OVERRIDE;
81 virtual void ReceivedContentWasMalformed() OVERRIDE;
82 virtual bool GetResponseAsString(
83 std::string* out_response_string) const OVERRIDE;
84 virtual bool GetResponseAsFilePath(
85 bool take_ownership,
86 FilePath* out_response_path) const OVERRIDE;
initial.commit09911bf2008-07-26 23:55:2987
[email protected]0b1ad312010-10-22 01:01:3888 static void CancelAll();
89
[email protected]b6c911a2009-04-21 21:58:4590 protected:
91 // Returns the delegate.
[email protected]c530c852011-10-24 18:18:3492 content::URLFetcherDelegate* delegate() const;
[email protected]b6c911a2009-04-21 21:58:4593
initial.commit09911bf2008-07-26 23:55:2994 private:
[email protected]91c06e5e2011-07-29 16:48:1995 friend class ScopedURLFetcherFactory;
[email protected]b3aced02011-05-23 12:40:4396 friend class TestURLFetcher;
[email protected]91c06e5e2011-07-29 16:48:1997 friend class URLFetcherTest;
[email protected]b3aced02011-05-23 12:40:4398
[email protected]17903192011-03-08 22:27:1099 // Only used by URLFetcherTest, returns the number of URLFetcher::Core objects
100 // actively running.
101 static int GetNumFetcherCores();
102
[email protected]beba03b32011-10-26 23:39:59103 static content::URLFetcherFactory* factory();
[email protected]91c06e5e2011-07-29 16:48:19104
105 // Sets the factory used by the static method Create to create a URLFetcher.
106 // URLFetcher does not take ownership of |factory|. A value of NULL results
107 // in a URLFetcher being created directly.
108 //
109 // NOTE: for safety, this should only be used through ScopedURLFetcherFactory!
[email protected]beba03b32011-10-26 23:39:59110 static void set_factory(content::URLFetcherFactory* factory);
[email protected]91c06e5e2011-07-29 16:48:19111
[email protected]d2106bc912012-04-02 13:47:01112 const scoped_refptr<content::URLFetcherCore> core_;
initial.commit09911bf2008-07-26 23:55:29113
[email protected]7b419b82011-10-27 04:23:46114 DISALLOW_COPY_AND_ASSIGN(URLFetcherImpl);
initial.commit09911bf2008-07-26 23:55:29115};
116
[email protected]7b419b82011-10-27 04:23:46117#endif // CONTENT_COMMON_NET_URL_FETCHER_IMPL_H_