| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // NOTE: The observer might be called back synchronously from RequestImage if | 56 // NOTE: The observer might be called back synchronously from RequestImage if |
| 57 // the image is already in the cache. | 57 // the image is already in the cache. |
| 58 RequestId RequestImage(const GURL& url, Observer* observer); | 58 RequestId RequestImage(const GURL& url, Observer* observer); |
| 59 | 59 |
| 60 // Start fetching the image at the given |url|. | 60 // Start fetching the image at the given |url|. |
| 61 void Prefetch(const GURL& url); | 61 void Prefetch(const GURL& url); |
| 62 | 62 |
| 63 protected: | 63 protected: |
| 64 // Create a bitmap fetcher for the given |url| and start it. Virtual method | 64 // Create a bitmap fetcher for the given |url| and start it. Virtual method |
| 65 // so tests can override this for different behavior. | 65 // so tests can override this for different behavior. |
| 66 virtual chrome::BitmapFetcher* CreateFetcher(const GURL& url); | 66 virtual scoped_ptr<chrome::BitmapFetcher> CreateFetcher(const GURL& url); |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 friend class BitmapFetcherServiceTest; | 69 friend class BitmapFetcherServiceTest; |
| 70 | 70 |
| 71 typedef ScopedVector<chrome::BitmapFetcher> BitmapFetchers; | |
| 72 | |
| 73 // Gets the existing fetcher for |url| or constructs a new one if it doesn't | 71 // Gets the existing fetcher for |url| or constructs a new one if it doesn't |
| 74 // exist. | 72 // exist. |
| 75 const chrome::BitmapFetcher* EnsureFetcherForUrl(const GURL& url); | 73 const chrome::BitmapFetcher* EnsureFetcherForUrl(const GURL& url); |
| 76 | 74 |
| 77 // Find a fetcher with a given |url|. Return NULL if none is found. | 75 // Find a fetcher with a given |url|. Return NULL if none is found. |
| 78 const chrome::BitmapFetcher* FindFetcherForUrl(const GURL& url); | 76 const chrome::BitmapFetcher* FindFetcherForUrl(const GURL& url); |
| 79 | 77 |
| 80 // Remove |fetcher| from list of active fetchers. |fetcher| MUST be part of | 78 // Remove |fetcher| from list of active fetchers. |fetcher| MUST be part of |
| 81 // the list. | 79 // the list. |
| 82 void RemoveFetcher(const chrome::BitmapFetcher* fetcher); | 80 void RemoveFetcher(const chrome::BitmapFetcher* fetcher); |
| 83 | 81 |
| 84 // BitmapFetcherDelegate implementation. | 82 // BitmapFetcherDelegate implementation. |
| 85 void OnFetchComplete(const GURL& url, const SkBitmap* bitmap) override; | 83 void OnFetchComplete(const GURL& url, const SkBitmap* bitmap) override; |
| 86 | 84 |
| 87 // Currently active image fetchers. | 85 // Currently active image fetchers. |
| 88 BitmapFetchers active_fetchers_; | 86 std::vector<scoped_ptr<chrome::BitmapFetcher>> active_fetchers_; |
| 89 | 87 |
| 90 // Currently active requests. | 88 // Currently active requests. |
| 91 ScopedVector<BitmapFetcherRequest> requests_; | 89 ScopedVector<BitmapFetcherRequest> requests_; |
| 92 | 90 |
| 93 // Cache of retrieved images. | 91 // Cache of retrieved images. |
| 94 struct CacheEntry { | 92 struct CacheEntry { |
| 95 CacheEntry(); | 93 CacheEntry(); |
| 96 ~CacheEntry(); | 94 ~CacheEntry(); |
| 97 | 95 |
| 98 scoped_ptr<const SkBitmap> bitmap; | 96 scoped_ptr<const SkBitmap> bitmap; |
| 99 }; | 97 }; |
| 100 base::OwningMRUCache<GURL, CacheEntry*> cache_; | 98 base::OwningMRUCache<GURL, CacheEntry*> cache_; |
| 101 | 99 |
| 102 // Current request ID to be used. | 100 // Current request ID to be used. |
| 103 int current_request_id_; | 101 int current_request_id_; |
| 104 | 102 |
| 105 // Browser context this service is active for. | 103 // Browser context this service is active for. |
| 106 content::BrowserContext* context_; | 104 content::BrowserContext* context_; |
| 107 | 105 |
| 108 DISALLOW_COPY_AND_ASSIGN(BitmapFetcherService); | 106 DISALLOW_COPY_AND_ASSIGN(BitmapFetcherService); |
| 109 }; | 107 }; |
| 110 | 108 |
| 111 #endif // CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_SERVICE_H_ | 109 #endif // CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_SERVICE_H_ |
| OLD | NEW |