Componentize HistoryURLProvider/ScoredHistoryMatch.
[chromium-blink-merge.git] / chrome / browser / image_holder.h
blob6692749862b40bac4bbfdc1fdfa7a3e4ddc193f0
1 // Copyright 2014 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 CHROME_BROWSER_IMAGE_HOLDER_H_
6 #define CHROME_BROWSER_IMAGE_HOLDER_H_
8 #include "base/memory/scoped_vector.h"
9 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h"
10 #include "ui/gfx/image/image.h"
11 #include "ui/gfx/image/image_skia.h"
12 #include "url/gurl.h"
14 class Profile;
16 namespace chrome {
18 // This provides a callback so the ImageHolder can inform its parent when a
19 // bitmap arrives.
20 class ImageHolderDelegate {
21 public:
22 virtual void OnFetchComplete() = 0;
25 // This class encapsulates the action of fetching a bitmap, reporting when it is
26 // fetched, and holding onto the bitmap until no longer needed.
27 class ImageHolder : public chrome::BitmapFetcherDelegate {
28 public:
29 ImageHolder(const GURL& low_dpi_url,
30 const GURL& high_dpi_url,
31 Profile* profile,
32 ImageHolderDelegate* delegate);
33 ~ImageHolder() override;
35 // Begin fetching of the URLs we have.
36 void StartFetch();
38 // Check whether we have a response from the server for these resources,
39 // even if the response is a failed fetch.
40 bool IsFetchingDone() const;
42 // Inherited from BitmapFetcherDelegate
43 void OnFetchComplete(const GURL& url, const SkBitmap* bitmap) override;
45 // Accessors:
46 GURL low_dpi_url() const { return low_dpi_url_; }
47 GURL high_dpi_url() const { return high_dpi_url_; }
48 gfx::Image low_dpi_image() { return gfx::Image(image_); }
50 private:
51 // Helper function to create a bitmap fetcher (but not start the fetch).
52 void CreateBitmapFetcher(const GURL& url);
54 GURL low_dpi_url_;
55 GURL high_dpi_url_;
56 bool low_dpi_fetched_;
57 bool high_dpi_fetched_;
58 gfx::ImageSkia image_;
59 ImageHolderDelegate* delegate_;
60 ScopedVector<chrome::BitmapFetcher> fetchers_;
61 Profile* profile_;
63 FRIEND_TEST_ALL_PREFIXES(ImageHolderTest, CreateBitmapFetcherTest);
64 FRIEND_TEST_ALL_PREFIXES(ImageHolderTest, OnFetchCompleteTest);
65 FRIEND_TEST_ALL_PREFIXES(ImageHolderTest, IsFetchingDoneTest);
67 DISALLOW_COPY_AND_ASSIGN(ImageHolder);
70 } // namespace chrome.
72 #endif // CHROME_BROWSER_IMAGE_HOLDER_H_