| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // A wrapper around ResourceHandle and ResourceHandleClient that simplifies | 5 // A wrapper around ResourceHandle and ResourceHandleClient that simplifies |
| 6 // the download of an HTTP object. The interface is modeled after URLFetcher | 6 // the download of an HTTP object. The interface is modeled after URLFetcher |
| 7 // in the /chrome/browser. | 7 // in the /chrome/browser. |
| 8 // | 8 // |
| 9 // ResourceFetcher::Delegate::OnURLFetchComplete will be called async after | 9 // ResourceFetcher::Delegate::OnURLFetchComplete will be called async after |
| 10 // the ResourceFetcher object is created. | 10 // the ResourceFetcher object is created. |
| 11 | 11 |
| 12 #ifndef WEBKIT_GLUE_RESOURCE_FETCHER_H_ | 12 #ifndef WEBKIT_GLUE_RESOURCE_FETCHER_H_ |
| 13 #define WEBKIT_GLUE_RESOURCE_FETCHER_H_ | 13 #define WEBKIT_GLUE_RESOURCE_FETCHER_H_ |
| 14 | 14 |
| 15 #include <string> | 15 #include <string> |
| 16 | 16 |
| 17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
| 18 #include "base/scoped_ptr.h" | 18 #include "base/scoped_ptr.h" |
| 19 #include "base/timer.h" | 19 #include "base/timer.h" |
| 20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
| 21 #include "webkit/api/public/WebURLLoaderClient.h" | 21 #include "webkit/api/public/WebURLLoaderClient.h" |
| 22 #include "webkit/api/public/WebURLResponse.h" | 22 #include "webkit/api/public/WebURLResponse.h" |
| 23 | 23 |
| 24 class GURL; | 24 class GURL; |
| 25 class WebFrame; | |
| 26 | 25 |
| 27 namespace WebKit { | 26 namespace WebKit { |
| 27 class WebFrame; |
| 28 class WebURLLoader; | 28 class WebURLLoader; |
| 29 class WebURLRequest; | 29 class WebURLRequest; |
| 30 struct WebURLError; | 30 struct WebURLError; |
| 31 } | 31 } |
| 32 | 32 |
| 33 namespace webkit_glue { | 33 namespace webkit_glue { |
| 34 | 34 |
| 35 class ResourceFetcher : public WebKit::WebURLLoaderClient { | 35 class ResourceFetcher : public WebKit::WebURLLoaderClient { |
| 36 public: | 36 public: |
| 37 // This will be called when the URL has been fetched, successfully or not. | 37 // This will be called when the URL has been fetched, successfully or not. |
| 38 // If there is a failure, response and data will both be empty. |response| | 38 // If there is a failure, response and data will both be empty. |response| |
| 39 // and |data| are both valid until the URLFetcher instance is destroyed. | 39 // and |data| are both valid until the URLFetcher instance is destroyed. |
| 40 typedef Callback2<const WebKit::WebURLResponse&, | 40 typedef Callback2<const WebKit::WebURLResponse&, |
| 41 const std::string&>::Type Callback; | 41 const std::string&>::Type Callback; |
| 42 | 42 |
| 43 // We need a frame to make requests. | 43 // We need a frame to make requests. |
| 44 ResourceFetcher(const GURL& url, WebFrame* frame, Callback* callback); | 44 ResourceFetcher( |
| 45 const GURL& url, WebKit::WebFrame* frame, Callback* callback); |
| 45 ~ResourceFetcher(); | 46 ~ResourceFetcher(); |
| 46 | 47 |
| 47 // Stop the request and don't call the callback. | 48 // Stop the request and don't call the callback. |
| 48 void Cancel(); | 49 void Cancel(); |
| 49 | 50 |
| 50 bool completed() const { return completed_; } | 51 bool completed() const { return completed_; } |
| 51 | 52 |
| 52 protected: | 53 protected: |
| 53 // WebURLLoaderClient methods: | 54 // WebURLLoaderClient methods: |
| 54 virtual void willSendRequest( | 55 virtual void willSendRequest( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 75 scoped_ptr<Callback> callback_; | 76 scoped_ptr<Callback> callback_; |
| 76 | 77 |
| 77 // A copy of the original resource response | 78 // A copy of the original resource response |
| 78 WebKit::WebURLResponse response_; | 79 WebKit::WebURLResponse response_; |
| 79 | 80 |
| 80 // Set to true once the request is compelte. | 81 // Set to true once the request is compelte. |
| 81 bool completed_; | 82 bool completed_; |
| 82 | 83 |
| 83 private: | 84 private: |
| 84 // Start the actual download. | 85 // Start the actual download. |
| 85 void Start(WebFrame* frame); | 86 void Start(WebKit::WebFrame* frame); |
| 86 | 87 |
| 87 // Buffer to hold the content from the server. | 88 // Buffer to hold the content from the server. |
| 88 std::string data_; | 89 std::string data_; |
| 89 }; | 90 }; |
| 90 | 91 |
| 91 ///////////////////////////////////////////////////////////////////////////// | 92 ///////////////////////////////////////////////////////////////////////////// |
| 92 // A resource fetcher with a timeout | 93 // A resource fetcher with a timeout |
| 93 class ResourceFetcherWithTimeout : public ResourceFetcher { | 94 class ResourceFetcherWithTimeout : public ResourceFetcher { |
| 94 public: | 95 public: |
| 95 ResourceFetcherWithTimeout(const GURL& url, WebFrame* frame, | 96 ResourceFetcherWithTimeout(const GURL& url, WebKit::WebFrame* frame, |
| 96 int timeout_secs, Callback* c); | 97 int timeout_secs, Callback* c); |
| 97 virtual ~ResourceFetcherWithTimeout() {} | 98 virtual ~ResourceFetcherWithTimeout() {} |
| 98 | 99 |
| 99 private: | 100 private: |
| 100 // Callback for timer that limits how long we wait for the alternate error | 101 // Callback for timer that limits how long we wait for the alternate error |
| 101 // page server. If this timer fires and the request hasn't completed, we | 102 // page server. If this timer fires and the request hasn't completed, we |
| 102 // kill the request. | 103 // kill the request. |
| 103 void TimeoutFired(); | 104 void TimeoutFired(); |
| 104 | 105 |
| 105 // Limit how long we wait for the alternate error page server. | 106 // Limit how long we wait for the alternate error page server. |
| 106 base::OneShotTimer<ResourceFetcherWithTimeout> timeout_timer_; | 107 base::OneShotTimer<ResourceFetcherWithTimeout> timeout_timer_; |
| 107 }; | 108 }; |
| 108 | 109 |
| 109 } // namespace webkit_glue | 110 } // namespace webkit_glue |
| 110 | 111 |
| 111 #endif // WEBKIT_GLUE_RESOURCE_FETCHER_H_ | 112 #endif // WEBKIT_GLUE_RESOURCE_FETCHER_H_ |
| OLD | NEW |