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 | 4 |
5 #ifndef CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_ |
6 #define CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_ | 6 #define CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" | 17 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
18 #include "chrome/browser/search/suggestions/image_manager.h" | |
18 #include "chrome/browser/search/suggestions/proto/suggestions.pb.h" | 19 #include "chrome/browser/search/suggestions/proto/suggestions.pb.h" |
19 #include "components/leveldb_proto/proto_database.h" | 20 #include "components/leveldb_proto/proto_database.h" |
20 #include "ui/gfx/image/image_skia.h" | 21 #include "ui/gfx/image/image_skia.h" |
21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
22 | 23 |
23 namespace net { | 24 namespace net { |
24 class URLRequestContextGetter; | 25 class URLRequestContextGetter; |
25 } | 26 } |
26 | 27 |
27 namespace suggestions { | 28 namespace suggestions { |
28 | 29 |
29 class SuggestionsProfile; | 30 class SuggestionsProfile; |
30 class ThumbnailData; | 31 class ThumbnailData; |
31 | 32 |
32 // A class used to fetch server thumbnails asynchronously and manage the caching | 33 // A class used to fetch server thumbnails asynchronously and manage the caching |
33 // layer (both in memory and on disk). | 34 // layer (both in memory and on disk). |
34 class ThumbnailManager : public chrome::BitmapFetcherDelegate { | 35 class ThumbnailManager : public ImageManager, |
36 public chrome::BitmapFetcherDelegate { | |
35 public: | 37 public: |
36 typedef std::vector<ThumbnailData> ThumbnailVector; | 38 typedef std::vector<ThumbnailData> ThumbnailVector; |
37 | 39 |
38 ThumbnailManager( | 40 ThumbnailManager( |
39 net::URLRequestContextGetter* url_request_context, | 41 net::URLRequestContextGetter* url_request_context, |
40 scoped_ptr<leveldb_proto::ProtoDatabase<ThumbnailData> > database, | 42 scoped_ptr<leveldb_proto::ProtoDatabase<ThumbnailData> > database, |
41 const base::FilePath& database_dir); | 43 const base::FilePath& database_dir); |
42 virtual ~ThumbnailManager(); | 44 virtual ~ThumbnailManager(); |
43 | 45 |
44 // Initializes the |thumbnail_url_map_| with the proper mapping from website | 46 // Initializes the |thumbnail_url_map_| with the proper mapping from website |
huangs
2014/07/17 18:23:35
Add something similar to
// ImageManager interface
Mathieu
2014/07/17 18:29:13
Done.
| |
45 // URL to thumbnail URL. | 47 // URL to thumbnail URL. |
46 void InitializeThumbnailMap(const SuggestionsProfile& suggestions); | 48 virtual void Initialize(const SuggestionsProfile& suggestions) OVERRIDE; |
47 | 49 |
48 // Retrieves stored thumbnail for website |url| asynchronously. Calls | 50 // Retrieves stored thumbnail for website |url| asynchronously. Calls |
49 // |callback| with Bitmap pointer if found, and NULL otherwise. Should be | 51 // |callback| with Bitmap pointer if found, and NULL otherwise. Should be |
50 // called from the UI thread. | 52 // called from the UI thread. |
51 void GetPageThumbnail( | 53 virtual void GetImageForURL( |
huangs
2014/07/17 18:23:35
// ImageManager interface.
The UI thread constrai
Mathieu
2014/07/17 18:29:13
Done.
| |
52 const GURL& url, | 54 const GURL& url, |
53 base::Callback<void(const GURL&, const SkBitmap*)> callback); | 55 base::Callback<void(const GURL&, const SkBitmap*)> callback) OVERRIDE; |
54 | 56 |
55 private: | 57 private: |
56 friend class MockThumbnailManager; | 58 friend class MockThumbnailManager; |
57 friend class ThumbnailManagerBrowserTest; | 59 friend class ThumbnailManagerBrowserTest; |
58 FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerTest, InitializeThumbnailMapTest); | 60 FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerTest, InitializeTest); |
59 FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerBrowserTest, | 61 FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerBrowserTest, |
60 GetPageThumbnailNetworkCacheHit); | 62 GetImageForURLNetworkCacheHit); |
61 FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerBrowserTest, | 63 FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerBrowserTest, |
62 GetPageThumbnailNetworkCacheNotInitialized); | 64 GetImageForURLNetworkCacheNotInitialized); |
63 | 65 |
64 // Used for testing. | 66 // Used for testing. |
65 ThumbnailManager(); | 67 ThumbnailManager(); |
66 | 68 |
67 typedef std::vector<base::Callback<void(const GURL&, const SkBitmap*)> > | 69 typedef std::vector<base::Callback<void(const GURL&, const SkBitmap*)> > |
68 CallbackVector; | 70 CallbackVector; |
69 typedef base::hash_map<std::string, SkBitmap> ThumbnailMap; | 71 typedef base::hash_map<std::string, SkBitmap> ThumbnailMap; |
70 | 72 |
71 // State related to a thumbnail fetch (associated website url, thumbnail_url, | 73 // State related to a thumbnail fetch (associated website url, thumbnail_url, |
72 // fetcher, pending callbacks). | 74 // fetcher, pending callbacks). |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 bool database_ready_; | 165 bool database_ready_; |
164 | 166 |
165 base::WeakPtrFactory<ThumbnailManager> weak_ptr_factory_; | 167 base::WeakPtrFactory<ThumbnailManager> weak_ptr_factory_; |
166 | 168 |
167 DISALLOW_COPY_AND_ASSIGN(ThumbnailManager); | 169 DISALLOW_COPY_AND_ASSIGN(ThumbnailManager); |
168 }; | 170 }; |
169 | 171 |
170 } // namespace suggestions | 172 } // namespace suggestions |
171 | 173 |
172 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_ | 174 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_ |
OLD | NEW |