Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: chrome/browser/search/suggestions/thumbnail_manager.h

Issue 299713007: [Suggestions] Adding a Thumbnail Manager for the Suggestions Service (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: latest round Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 <utility>
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 typedef base::Callback<void(const GURL&, const SkBitmap*)>
23 BitmapResponseCallback;
24
25 class SuggestionsProfile;
26
27 // A class used to fetch server thumbnails asynchronously.
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 website URL
34 // to thumbnail URL.
35 void InitializeThumbnailMap(const SuggestionsProfile& suggestions);
36
37 // Retrieves stored thumbnail for website |url| asynchronously. Calls
38 // |callback| with Bitmap pointer if found, and NULL otherwise. Should be
39 // called from the UI thread.
40 void GetPageThumbnail(
41 const GURL& url,
42 base::Callback<void(const GURL&, const SkBitmap*)> callback);
43
44 // Inherited from BitmapFetcherDelegate. Runs on the UI thread.
45 virtual void OnFetchComplete(const GURL thumbnail_url,
huangs 2014/05/23 20:16:22 Can this be private, to prevent direct call?
Mathieu 2014/05/23 20:22:43 Done. Good point.
46 const SkBitmap* bitmap) OVERRIDE;
47
48 private:
49 FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerTest, InitializeThumbnailMapTest);
50 FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerBrowserTest, FetchThumbnails);
51 FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerBrowserTest, FetchThumbnailsInvalid);
52 FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerBrowserTest,
53 FetchThumbnailsMultiple);
54
55 typedef std::vector<base::Callback<void(const GURL&, const SkBitmap*)> >
56 CallbackVector;
57
58 // State related to a thumbnail fetch (associated website url, fetcher,
59 // pending callbacks).
60 struct ThumbnailRequest {
61 GURL url;
62 chrome::BitmapFetcher* fetcher;
63 // Queue for pending callbacks, which may accumulate while the request is in
64 // flight.
65 CallbackVector callbacks;
66 };
67
68 typedef std::map<const GURL, ThumbnailRequest> ThumbnailRequestMap;
69
70 // Looks up thumbnail for |url|. If found, writes the result to
71 // |thumbnail_url| and returns true. Otherwise just returns false.
72 bool GetThumbnailURL(const GURL& url, GURL* thumbnail_url);
73
74 // Used for substituting the request context during testing.
75 void set_request_context(net::URLRequestContextGetter* context) {
76 url_request_context_ = context;
77 }
78
79 // Map from URL to thumbnail URL. Should be kept up to date when a new
80 // SuggestionsProfile is available.
81 std::map<GURL, GURL> thumbnail_map_;
82
83 // Map from each thumbnail URL to the session information (associated website
huangs 2014/05/23 20:16:22 NB the word "session" is used (keep it if that's i
Mathieu 2014/05/23 20:22:43 Done.
84 // url, fetcher, pending callbacks).
85 ThumbnailRequestMap pending_requests_;
86
87 net::URLRequestContextGetter* url_request_context_;
88
89 DISALLOW_COPY_AND_ASSIGN(ThumbnailManager);
90 };
91
92 } // namespace suggestions
93
94 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/search/suggestions/suggestions_service.cc ('k') | chrome/browser/search/suggestions/thumbnail_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698