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 <map> | |
9 #include <queue> | |
10 #include <utility> | |
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 typedef base::Callback<void(const GURL&, const SkBitmap*)> | |
23 BitmapResponseCallback; | |
24 | |
25 class SuggestionsProfile; | |
26 | |
27 // A base class to maintain and fetch server thumbnails asynchronously. | |
Jered
2014/05/23 16:57:48
Here, explain what you mean by "maintain". Does th
Mathieu
2014/05/23 19:21:58
Reworded. It doesn't cache for now, will add it wh
| |
28 class ThumbnailManager : public chrome::BitmapFetcherDelegate { | |
29 public: | |
30 explicit ThumbnailManager(Profile* profile); | |
31 virtual ~ThumbnailManager(); | |
32 | |
33 // Initializes the |thumbnail_map_| with the proper mapping from URL to | |
Jered
2014/05/23 16:57:48
Does "URL" here mean "website URL"?
Mathieu
2014/05/23 19:21:58
Done.
| |
34 // thumbnail URL. | |
35 void InitializeThumbnailMap(const SuggestionsProfile& suggestions); | |
36 | |
37 // Retrieves stored thumbnail for website |url| asynchronously. Returns | |
Jered
2014/05/23 16:57:48
Same comment about "returns" here.
Mathieu
2014/05/23 19:21:58
Done.
| |
38 // thumbnail image as a Bitmap pointer to |callback| if found, and NULL | |
39 // otherwise. Calls should originate from the UI thread. | |
40 void GetPageThumbnail(const GURL& url, BitmapResponseCallback callback); | |
41 | |
42 // Inherited from BitmapFetcherDelegate. Runs on the UI thread. | |
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 // Contains the information related with a thumbnail fetch (associated website | |
Jered
2014/05/23 16:57:48
Omit "contains the". information -> state, related
Mathieu
2014/05/23 19:21:58
Done.
| |
54 // url, fetcher, pending callbacks). | |
55 struct Session { | |
Jered
2014/05/23 16:57:48
"ThumbnailRequest" might be a better name for this
Mathieu
2014/05/23 19:21:58
Done.
| |
56 Session(); | |
57 ~Session(); | |
58 | |
59 GURL url; | |
60 chrome::BitmapFetcher* fetcher; | |
61 // Queue for pending callbacks, which may accumulate while the request is in | |
62 // flight. | |
63 std::queue<BitmapResponseCallback> callbacks; | |
Jered
2014/05/23 16:57:48
Use a vector here. You don't really need linked al
Mathieu
2014/05/23 19:21:58
Done.
| |
64 }; | |
65 | |
66 typedef std::map<const GURL, Session> ThumbnailSessionMap; | |
67 | |
68 // Looks up thumbnail for |url|. If found, writes the result to | |
69 // |thumbnail_url| and returns true. Otherwise just returns false. | |
70 bool GetThumbnailURL(const GURL& url, GURL* thumbnail_url); | |
71 | |
72 // Used for substituting the request context during testing. | |
73 void set_request_context(net::URLRequestContextGetter* context) { | |
74 url_request_context_ = context; | |
75 } | |
76 | |
77 // Map from URL to thumbnail URL. Should be kept up to date when a new | |
78 // SuggestionsProfile is available. | |
79 std::map<GURL, GURL> thumbnail_map_; | |
80 | |
81 // Map from each thumbnail URL to the session information (associated website | |
82 // url, fetcher, pending callbacks). | |
83 ThumbnailSessionMap session_map_; | |
Jered
2014/05/23 16:57:48
I'd call this pending_requests_.
Mathieu
2014/05/23 19:21:58
Done.
| |
84 | |
85 net::URLRequestContextGetter* url_request_context_; | |
86 | |
87 DISALLOW_COPY_AND_ASSIGN(ThumbnailManager); | |
88 }; | |
89 | |
90 } // namespace suggestions | |
91 | |
92 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_ | |
OLD | NEW |