OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 #ifndef CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_SERVICE_H_ | 4 #ifndef CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_SERVICE_H_ |
5 #define CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_SERVICE_H_ | 5 #define CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_SERVICE_H_ |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/containers/mru_cache.h" | 8 #include "base/containers/mru_cache.h" |
9 #include "base/containers/scoped_ptr_hash_map.h" | 9 #include "base/containers/scoped_ptr_hash_map.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 public: | 35 public: |
36 virtual ~Observer() {} | 36 virtual ~Observer() {} |
37 | 37 |
38 // Called whenever the image changes. Called with an empty image if the | 38 // Called whenever the image changes. Called with an empty image if the |
39 // fetch failed or the request ended for any reason. | 39 // fetch failed or the request ended for any reason. |
40 virtual void OnImageChanged(RequestId request_id, | 40 virtual void OnImageChanged(RequestId request_id, |
41 const SkBitmap& answers_image) = 0; | 41 const SkBitmap& answers_image) = 0; |
42 }; | 42 }; |
43 | 43 |
44 explicit BitmapFetcherService(content::BrowserContext* context); | 44 explicit BitmapFetcherService(content::BrowserContext* context); |
45 virtual ~BitmapFetcherService(); | 45 ~BitmapFetcherService() override; |
46 | 46 |
47 // Cancels a request, if it is still in-flight. | 47 // Cancels a request, if it is still in-flight. |
48 void CancelRequest(RequestId requestId); | 48 void CancelRequest(RequestId requestId); |
49 | 49 |
50 // Requests a new image. Will either trigger download or satisfy from cache. | 50 // Requests a new image. Will either trigger download or satisfy from cache. |
51 // Takes ownership of |observer|. If there are too many outstanding requests, | 51 // Takes ownership of |observer|. If there are too many outstanding requests, |
52 // the request will fail and |observer| will be called to signal failure. | 52 // the request will fail and |observer| will be called to signal failure. |
53 // Otherwise, |observer| will be called with either the cached image or the | 53 // Otherwise, |observer| will be called with either the cached image or the |
54 // downloaded one. | 54 // downloaded one. |
55 // NOTE: The observer might be called back synchronously from RequestImage if | 55 // NOTE: The observer might be called back synchronously from RequestImage if |
(...skipping 18 matching lines...) Expand all Loading... |
74 const chrome::BitmapFetcher* EnsureFetcherForUrl(const GURL& url); | 74 const chrome::BitmapFetcher* EnsureFetcherForUrl(const GURL& url); |
75 | 75 |
76 // Find a fetcher with a given |url|. Return NULL if none is found. | 76 // Find a fetcher with a given |url|. Return NULL if none is found. |
77 const chrome::BitmapFetcher* FindFetcherForUrl(const GURL& url); | 77 const chrome::BitmapFetcher* FindFetcherForUrl(const GURL& url); |
78 | 78 |
79 // Remove |fetcher| from list of active fetchers. |fetcher| MUST be part of | 79 // Remove |fetcher| from list of active fetchers. |fetcher| MUST be part of |
80 // the list. | 80 // the list. |
81 void RemoveFetcher(const chrome::BitmapFetcher* fetcher); | 81 void RemoveFetcher(const chrome::BitmapFetcher* fetcher); |
82 | 82 |
83 // BitmapFetcherDelegate implementation. | 83 // BitmapFetcherDelegate implementation. |
84 virtual void OnFetchComplete(const GURL url, const SkBitmap* bitmap) override; | 84 void OnFetchComplete(const GURL url, const SkBitmap* bitmap) override; |
85 | 85 |
86 // Currently active image fetchers. | 86 // Currently active image fetchers. |
87 BitmapFetchers active_fetchers_; | 87 BitmapFetchers active_fetchers_; |
88 | 88 |
89 // Currently active requests. | 89 // Currently active requests. |
90 ScopedVector<BitmapFetcherRequest> requests_; | 90 ScopedVector<BitmapFetcherRequest> requests_; |
91 | 91 |
92 // Cache of retrieved images. | 92 // Cache of retrieved images. |
93 struct CacheEntry { | 93 struct CacheEntry { |
94 CacheEntry(); | 94 CacheEntry(); |
95 ~CacheEntry(); | 95 ~CacheEntry(); |
96 | 96 |
97 scoped_ptr<const SkBitmap> bitmap; | 97 scoped_ptr<const SkBitmap> bitmap; |
98 }; | 98 }; |
99 base::OwningMRUCache<GURL, CacheEntry*> cache_; | 99 base::OwningMRUCache<GURL, CacheEntry*> cache_; |
100 | 100 |
101 // Current request ID to be used. | 101 // Current request ID to be used. |
102 int current_request_id_; | 102 int current_request_id_; |
103 | 103 |
104 // Browser context this service is active for. | 104 // Browser context this service is active for. |
105 content::BrowserContext* context_; | 105 content::BrowserContext* context_; |
106 | 106 |
107 DISALLOW_COPY_AND_ASSIGN(BitmapFetcherService); | 107 DISALLOW_COPY_AND_ASSIGN(BitmapFetcherService); |
108 }; | 108 }; |
109 | 109 |
110 #endif // CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_SERVICE_H_ | 110 #endif // CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_SERVICE_H_ |
OLD | NEW |