OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_ | |
6 #define CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_ | |
7 | |
8 #include <memory> | |
huangs
2014/05/22 06:17:35
#include <map>
#include <utility> (for std::pa
Mathieu
2014/05/22 15:45:51
Done.
| |
9 #include <queue> | |
10 #include <vector> | |
11 | |
12 #include "base/basictypes.h" | |
13 #include "base/callback.h" | |
14 #include "chrome/browser/bitmap_fetcher.h" | |
15 #include "ui/gfx/image/image_skia.h" | |
16 #include "url/gurl.h" | |
17 | |
18 class Profile; | |
19 | |
20 namespace suggestions { | |
21 | |
22 class SuggestionsProfile; | |
23 | |
24 // An interface to maintain and fetch server thumbnails asynchronously. | |
huangs
2014/05/22 06:17:35
NIT: "base class" instead of interface? To me int
Mathieu
2014/05/22 15:45:51
I stated it below in a comment to GetPageThumbnail
| |
25 class ThumbnailManager : public chrome::BitmapFetcherDelegate { | |
26 public: | |
27 typedef base::Callback<void(const GURL&, const SkBitmap*)> | |
28 BitmapResponseCallback; | |
29 | |
30 explicit ThumbnailManager(Profile* profile); | |
31 virtual ~ThumbnailManager(); | |
32 | |
33 // Initialize the |thumbnail_map_| with the proper mapping from URL to | |
34 // thumbnail URL. | |
35 void InitializeThumbnailMap(const SuggestionsProfile& suggestions); | |
36 | |
37 // For a given |url|, if a thumbnail URL is known for it, will start the fetch | |
huangs
2014/05/22 06:17:35
Suggested comment:
// Retrieves stored thumbnail
Mathieu
2014/05/22 15:45:51
Done.
| |
38 // of the image and |callback|. In the case of a |url| for which the thumbnail | |
39 // is not known, the bitmap pointer given to the |callback| will be NULL. | |
40 void GetURLThumbnail(const GURL& url, BitmapResponseCallback callback); | |
41 | |
42 // Inherited from BitmapFetcherDelegate. | |
43 virtual void OnFetchComplete(const GURL thumbnail_url, | |
44 const SkBitmap* bitmap) OVERRIDE; | |
45 | |
46 private: | |
47 FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerTest, InitializeThumbnailMapTest); | |
48 FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerBrowserTest, FetchThumbnails); | |
49 FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerBrowserTest, FetchThumbnailsInvalid); | |
50 FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerBrowserTest, | |
51 FetchThumbnailsMultiple); | |
52 | |
53 // Given a website |url|, fill in a |thumbnail_url| and return whether it | |
54 // exists or not. | |
55 bool GetThumbnailURL(const GURL& url, GURL* thumbnail_url); | |
56 | |
57 // Used for substituting the request context during testing. | |
58 void set_request_context(net::URLRequestContextGetter* context) { | |
59 url_request_context_ = context; | |
60 } | |
61 | |
62 // Map from URL to thumbnail URL. Should be kept up to date when a new | |
63 // SuggestionsProfile is available. | |
64 std::map<GURL, GURL> thumbnail_map_; | |
65 | |
66 // Map from each thumbnail URL to a queue of pending callbacks. | |
huangs
2014/05/22 06:17:35
Both |pending_callbacks_| and |fetcher_map_| use t
Mathieu
2014/05/22 15:45:51
Done.
| |
67 std::map<GURL, std::queue<BitmapResponseCallback>> pending_callbacks_; | |
68 | |
69 // Map from each thumbnail URL to a pair composed of | |
70 // (website URL, bitmap fetcher). | |
71 std::map<GURL, std::pair<GURL, chrome::BitmapFetcher*>> fetcher_map_; | |
72 | |
73 Profile* profile_; | |
huangs
2014/05/22 06:17:35
|profile_| seems to be unused?
Mathieu
2014/05/22 15:45:51
Done.
| |
74 | |
75 net::URLRequestContextGetter* url_request_context_; | |
76 | |
77 DISALLOW_COPY_AND_ASSIGN(ThumbnailManager); | |
78 }; | |
79 | |
80 } // namespace suggestions | |
81 | |
82 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_ | |
OLD | NEW |