Home | History | Annotate | Download | only in renderer
      1 // Copyright 2013 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 CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_
      6 #define CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_
      7 
      8 #include <string>
      9 
     10 #include "base/callback.h"
     11 #include "content/common/content_export.h"
     12 #include "third_party/WebKit/public/platform/WebURLRequest.h"
     13 
     14 class GURL;
     15 
     16 namespace base {
     17 class TimeDelta;
     18 }
     19 
     20 namespace blink {
     21 class WebFrame;
     22 class WebURLResponse;
     23 }
     24 
     25 namespace content {
     26 
     27 // Interface to download resources asynchronously.
     28 class CONTENT_EXPORT ResourceFetcher {
     29  public:
     30   virtual ~ResourceFetcher() {}
     31 
     32   // This will be called asynchronously after the URL has been fetched,
     33   // successfully or not.  If there is a failure, response and data will both be
     34   // empty.  |response| and |data| are both valid until the URLFetcher instance
     35   // is destroyed.
     36   typedef base::Callback<void(const blink::WebURLResponse& response,
     37                               const std::string& data)> Callback;
     38 
     39   // Creates a ResourceFetcher and starts fetching the specified resource.
     40   // Caller takes ownership of the returned object.  Deleting the
     41   // ResourceFetcher will cancel the request, and the callback will never be
     42   // run.
     43   static ResourceFetcher* Create(const GURL& url,
     44                                  blink::WebFrame* frame,
     45                                  blink::WebURLRequest::TargetType target_type,
     46                                  const Callback& callback);
     47 
     48   // Sets how long to wait for the server to reply.  By default, there is no
     49   // timeout.
     50   virtual void SetTimeout(const base::TimeDelta& timeout) = 0;
     51 };
     52 
     53 }  // namespace content
     54 
     55 #endif  // CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_
     56