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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/containers/mru_cache.h" | 10 #include "base/containers/mru_cache.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_delegate.h" | 13 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_delegate.h" |
14 #include "components/keyed_service/core/keyed_service.h" | 14 #include "components/keyed_service/core/keyed_service.h" |
| 15 #include "net/traffic_annotation/network_traffic_annotation.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 class BrowserContext; | 18 class BrowserContext; |
18 } // namespace content | 19 } // namespace content |
19 | 20 |
20 namespace chrome { | 21 namespace chrome { |
21 class BitmapFetcher; | 22 class BitmapFetcher; |
22 } // namespace chrome | 23 } // namespace chrome |
23 | 24 |
24 class BitmapFetcherRequest; | 25 class BitmapFetcherRequest; |
(...skipping 24 matching lines...) Expand all Loading... |
49 // Cancels a request, if it is still in-flight. | 50 // Cancels a request, if it is still in-flight. |
50 void CancelRequest(RequestId requestId); | 51 void CancelRequest(RequestId requestId); |
51 | 52 |
52 // Requests a new image. Will either trigger download or satisfy from cache. | 53 // Requests a new image. Will either trigger download or satisfy from cache. |
53 // Takes ownership of |observer|. If there are too many outstanding requests, | 54 // Takes ownership of |observer|. If there are too many outstanding requests, |
54 // the request will fail and |observer| will be called to signal failure. | 55 // the request will fail and |observer| will be called to signal failure. |
55 // Otherwise, |observer| will be called with either the cached image or the | 56 // Otherwise, |observer| will be called with either the cached image or the |
56 // downloaded one. | 57 // downloaded one. |
57 // NOTE: The observer might be called back synchronously from RequestImage if | 58 // NOTE: The observer might be called back synchronously from RequestImage if |
58 // the image is already in the cache. | 59 // the image is already in the cache. |
59 RequestId RequestImage(const GURL& url, Observer* observer); | 60 RequestId RequestImage( |
| 61 const GURL& url, |
| 62 Observer* observer, |
| 63 const net::NetworkTrafficAnnotationTag& traffic_annotation); |
60 | 64 |
61 // Start fetching the image at the given |url|. | 65 // Start fetching the image at the given |url|. |
62 void Prefetch(const GURL& url); | 66 void Prefetch(const GURL& url, |
| 67 const net::NetworkTrafficAnnotationTag& traffic_annotation); |
63 | 68 |
64 protected: | 69 protected: |
65 // Create a bitmap fetcher for the given |url| and start it. Virtual method | 70 // Create a bitmap fetcher for the given |url| and start it. Virtual method |
66 // so tests can override this for different behavior. | 71 // so tests can override this for different behavior. |
67 virtual std::unique_ptr<chrome::BitmapFetcher> CreateFetcher(const GURL& url); | 72 virtual std::unique_ptr<chrome::BitmapFetcher> CreateFetcher( |
| 73 const GURL& url, |
| 74 const net::NetworkTrafficAnnotationTag& traffic_annotation); |
68 | 75 |
69 private: | 76 private: |
70 friend class BitmapFetcherServiceTest; | 77 friend class BitmapFetcherServiceTest; |
71 | 78 |
72 // Gets the existing fetcher for |url| or constructs a new one if it doesn't | 79 // Gets the existing fetcher for |url| or constructs a new one if it doesn't |
73 // exist. | 80 // exist. |
74 const chrome::BitmapFetcher* EnsureFetcherForUrl(const GURL& url); | 81 const chrome::BitmapFetcher* EnsureFetcherForUrl( |
| 82 const GURL& url, |
| 83 const net::NetworkTrafficAnnotationTag& traffic_annotation); |
75 | 84 |
76 // Find a fetcher with a given |url|. Return NULL if none is found. | 85 // Find a fetcher with a given |url|. Return NULL if none is found. |
77 const chrome::BitmapFetcher* FindFetcherForUrl(const GURL& url); | 86 const chrome::BitmapFetcher* FindFetcherForUrl(const GURL& url); |
78 | 87 |
79 // Remove |fetcher| from list of active fetchers. |fetcher| MUST be part of | 88 // Remove |fetcher| from list of active fetchers. |fetcher| MUST be part of |
80 // the list. | 89 // the list. |
81 void RemoveFetcher(const chrome::BitmapFetcher* fetcher); | 90 void RemoveFetcher(const chrome::BitmapFetcher* fetcher); |
82 | 91 |
83 // BitmapFetcherDelegate implementation. | 92 // BitmapFetcherDelegate implementation. |
84 void OnFetchComplete(const GURL& url, const SkBitmap* bitmap) override; | 93 void OnFetchComplete(const GURL& url, const SkBitmap* bitmap) override; |
(...skipping 16 matching lines...) Expand all Loading... |
101 // Current request ID to be used. | 110 // Current request ID to be used. |
102 int current_request_id_; | 111 int current_request_id_; |
103 | 112 |
104 // Browser context this service is active for. | 113 // Browser context this service is active for. |
105 content::BrowserContext* context_; | 114 content::BrowserContext* context_; |
106 | 115 |
107 DISALLOW_COPY_AND_ASSIGN(BitmapFetcherService); | 116 DISALLOW_COPY_AND_ASSIGN(BitmapFetcherService); |
108 }; | 117 }; |
109 | 118 |
110 #endif // CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_SERVICE_H_ | 119 #endif // CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_SERVICE_H_ |
OLD | NEW |