distiller_url_fetcher.h revision f2477e01787aa58f445919b809d89e252beef54f
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 COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_URL_FETCHER_H_ 6#define COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_URL_FETCHER_H_ 7 8#include "base/callback.h" 9#include "net/url_request/url_fetcher.h" 10#include "net/url_request/url_fetcher_delegate.h" 11#include "net/url_request/url_request_context_getter.h" 12 13namespace dom_distiller { 14 15class DistillerURLFetcher; 16 17// Class for creating a DistillerURLFetcher. 18class DistillerURLFetcherFactory { 19 public: 20 DistillerURLFetcherFactory(net::URLRequestContextGetter* context_getter); 21 virtual ~DistillerURLFetcherFactory() {} 22 virtual DistillerURLFetcher* CreateDistillerURLFetcher() const; 23 24 private: 25 net::URLRequestContextGetter* context_getter_; 26}; 27 28// This class fetches a URL, and notifies the caller when the operation 29// completes or fails. If the request fails, an empty string will be returned. 30class DistillerURLFetcher : public net::URLFetcherDelegate { 31 public: 32 DistillerURLFetcher(net::URLRequestContextGetter* context_getter); 33 virtual ~DistillerURLFetcher(); 34 35 // Indicates when a fetch is done. 36 typedef base::Callback<void(const std::string& data)> URLFetcherCallback; 37 38 // Fetches a |url|. Notifies when the fetch is done via |callback|. 39 virtual void FetchURL(const std::string& url, 40 const URLFetcherCallback& callback); 41 42 protected: 43 virtual net::URLFetcher* CreateURLFetcher( 44 net::URLRequestContextGetter* context_getter, 45 const std::string& url); 46 47 private: 48 // net::URLFetcherDelegate: 49 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 50 51 scoped_ptr<net::URLFetcher> url_fetcher_; 52 URLFetcherCallback callback_; 53 net::URLRequestContextGetter* context_getter_; 54 DISALLOW_COPY_AND_ASSIGN(DistillerURLFetcher); 55}; 56 57} // namespace dom_distiller 58 59#endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_URL_FETCHER_H_ 60