OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 #ifndef HEADLESS_PUBLIC_UTIL_URL_FETCHER_H_ |
| 6 #define HEADLESS_PUBLIC_UTIL_URL_FETCHER_H_ |
| 7 |
| 8 #include <stddef.h> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "net/base/net_errors.h" |
| 15 #include "url/gurl.h" |
| 16 |
| 17 namespace net { |
| 18 class HttpRequestHeaders; |
| 19 class HttpResponseHeaders; |
| 20 } // namespace net |
| 21 |
| 22 namespace headless { |
| 23 |
| 24 // An interface for fetching URLs. Note these are only intended to be used once. |
| 25 // TODO(alexclarke): Implement a URLFetcher that can backend onto a URLRequest |
| 26 // and hook this up in headless_shell under a flag. |
| 27 class URLFetcher { |
| 28 public: |
| 29 URLFetcher() {} |
| 30 virtual ~URLFetcher() {} |
| 31 |
| 32 // Interface for reporting the fetch result. |
| 33 class ResultListener { |
| 34 public: |
| 35 ResultListener() {} |
| 36 |
| 37 // Informs the listener that the fetch failed. |
| 38 virtual void OnStartError(net::Error error) = 0; |
| 39 |
| 40 // Informs the listener that the fetch succeeded and returns the HTTP |
| 41 // headers and the body. NOTE |body| must be owned by the caller and remain |
| 42 // valid until the fetcher is destroyed, |
| 43 virtual void OnFetchComplete( |
| 44 const GURL& final_url, |
| 45 int http_response_code, |
| 46 scoped_refptr<net::HttpResponseHeaders> response_headers, |
| 47 const char* body, |
| 48 size_t body_size) = 0; |
| 49 |
| 50 // Helper function which extracts the headers from |response_data| and calls |
| 51 // OnFetchComplete. |
| 52 void OnFetchCompleteExtractHeaders(const GURL& final_url, |
| 53 int http_response_code, |
| 54 const char* response_data, |
| 55 size_t response_data_size); |
| 56 |
| 57 protected: |
| 58 virtual ~ResultListener() {} |
| 59 |
| 60 private: |
| 61 DISALLOW_COPY_AND_ASSIGN(ResultListener); |
| 62 }; |
| 63 |
| 64 // Instructs the sub-class to fetch the resource. |
| 65 virtual void StartFetch(const GURL& rewritten_url, |
| 66 const net::HttpRequestHeaders& request_headers, |
| 67 ResultListener* result_listener) = 0; |
| 68 |
| 69 private: |
| 70 DISALLOW_COPY_AND_ASSIGN(URLFetcher); |
| 71 }; |
| 72 |
| 73 } // namespace headless |
| 74 |
| 75 #endif // HEADLESS_PUBLIC_UTIL_URL_FETCHER_H_ |
OLD | NEW |