Don't preload rarely seen large images
[chromium-blink-merge.git] / components / dom_distiller / core / distiller_url_fetcher.h
blobb8dd9e50421fb6c6c409d8605877f74e67c84838
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.
5 #ifndef COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_URL_FETCHER_H_
6 #define COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_URL_FETCHER_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "net/url_request/url_fetcher.h"
12 #include "net/url_request/url_fetcher_delegate.h"
13 #include "net/url_request/url_request_context_getter.h"
15 namespace dom_distiller {
17 class DistillerURLFetcher;
19 // Class for creating a DistillerURLFetcher.
20 class DistillerURLFetcherFactory {
21 public:
22 explicit DistillerURLFetcherFactory(
23 net::URLRequestContextGetter* context_getter);
24 virtual ~DistillerURLFetcherFactory() {}
25 virtual DistillerURLFetcher* CreateDistillerURLFetcher() const;
27 private:
28 net::URLRequestContextGetter* context_getter_;
31 // This class fetches a URL, and notifies the caller when the operation
32 // completes or fails. If the request fails, an empty string will be returned.
33 class DistillerURLFetcher : public net::URLFetcherDelegate {
34 public:
35 explicit DistillerURLFetcher(net::URLRequestContextGetter* context_getter);
36 ~DistillerURLFetcher() override;
38 // Indicates when a fetch is done.
39 typedef base::Callback<void(const std::string& data)> URLFetcherCallback;
41 // Fetches a |url|. Notifies when the fetch is done via |callback|.
42 virtual void FetchURL(const std::string& url,
43 const URLFetcherCallback& callback);
45 protected:
46 virtual scoped_ptr<net::URLFetcher> CreateURLFetcher(
47 net::URLRequestContextGetter* context_getter,
48 const std::string& url);
50 private:
51 // net::URLFetcherDelegate:
52 void OnURLFetchComplete(const net::URLFetcher* source) override;
54 scoped_ptr<net::URLFetcher> url_fetcher_;
55 URLFetcherCallback callback_;
56 net::URLRequestContextGetter* context_getter_;
57 DISALLOW_COPY_AND_ASSIGN(DistillerURLFetcher);
60 } // namespace dom_distiller
62 #endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_URL_FETCHER_H_