resource_fetcher.h revision f2477e01787aa58f445919b809d89e252beef54f
18403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// Copyright 2013 The Chromium Authors. All rights reserved.
28403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// Use of this source code is governed by a BSD-style license that can be
38403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// found in the LICENSE file.
48403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel
58403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel#ifndef CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_
68403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel#define CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_
78403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel
88403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel#include <string>
98403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel
108403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel#include "base/callback.h"
118403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel#include "content/common/content_export.h"
128403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel#include "third_party/WebKit/public/platform/WebURLRequest.h"
138403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel
148403881c365ab36b721ccc4500af1b3a5bd25870mikesamuelclass GURL;
158403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel
168403881c365ab36b721ccc4500af1b3a5bd25870mikesamuelnamespace base {
178403881c365ab36b721ccc4500af1b3a5bd25870mikesamuelclass TimeDelta;
188403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel}
198403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel
208403881c365ab36b721ccc4500af1b3a5bd25870mikesamuelnamespace blink {
218403881c365ab36b721ccc4500af1b3a5bd25870mikesamuelclass WebFrame;
228403881c365ab36b721ccc4500af1b3a5bd25870mikesamuelclass WebURLResponse;
238403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel}
248403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel
258403881c365ab36b721ccc4500af1b3a5bd25870mikesamuelnamespace content {
268403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel
278403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// Interface to download resources asynchronously.
288403881c365ab36b721ccc4500af1b3a5bd25870mikesamuelclass CONTENT_EXPORT ResourceFetcher {
295c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com public:
305c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com  virtual ~ResourceFetcher() {}
315c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com
325c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com  // This will be called asynchronously after the URL has been fetched,
335c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com  // successfully or not.  If there is a failure, response and data will both be
345c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com  // empty.  |response| and |data| are both valid until the URLFetcher instance
355c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com  // is destroyed.
36be666032a113a8af92bc557add8e83579cf0ef5cmikesamuel  typedef base::Callback<void(const blink::WebURLResponse& response,
37be666032a113a8af92bc557add8e83579cf0ef5cmikesamuel                              const std::string& data)> Callback;
385c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com
395c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com  // Creates a ResourceFetcher and starts fetching the specified resource.
405c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com  // Caller takes ownership of the returned object.  Deleting the
415c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com  // ResourceFetcher will cancel the request, and the callback will never be
425c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com  // run.
435c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com  static ResourceFetcher* Create(const GURL& url,
44aab0cbeeb7abb201e1ed154fd1db4e4846e51692mikesamuel                                 blink::WebFrame* frame,
455c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com                                 blink::WebURLRequest::TargetType target_type,
465c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com                                 const Callback& callback);
475c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com
485c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com  // Sets how long to wait for the server to reply.  By default, there is no
495c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com  // timeout.
505c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com  virtual void SetTimeout(const base::TimeDelta& timeout) = 0;
515c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com};
525c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com
535c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com}  // namespace content
545c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com
555c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com#endif  // CONTENT_PUBLIC_RENDERER_RESOURCE_FETCHER_H_
565c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com