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

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: addressed comments 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 <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
huangs 2014/05/22 18:08:22 NIT: remove extra empty lines.
Mathieu 2014/05/22 19:46:32 Done.
27
28
29 // A base class to maintain and fetch server thumbnails asynchronously.
30 class ThumbnailManager : public chrome::BitmapFetcherDelegate {
31 public:
32 explicit ThumbnailManager(Profile* profile);
33 virtual ~ThumbnailManager();
34
35 // Initialize the |thumbnail_map_| with the proper mapping from URL to
huangs 2014/05/22 18:08:22 NIT: s/Initialize/Initializes/
Mathieu 2014/05/22 19:46:32 Done.
36 // thumbnail URL.
37 void InitializeThumbnailMap(const SuggestionsProfile& suggestions);
huangs 2014/05/22 18:08:22 Should this routine only be called once? What if i
Mathieu 2014/05/22 19:46:32 It can be updated when new suggestions are fetched
38
39 // Retrieves stored thumbnail for website |url| asynchronously. Returns
40 // thumbnail image as a Bitmap pointer to |callback| if found, and NULL
41 // otherwise. Calls should originate from the UI thread.
42 void GetPageThumbnail(const GURL& url, BitmapResponseCallback callback);
43
44 // Inherited from BitmapFetcherDelegate.
45 virtual void OnFetchComplete(const GURL thumbnail_url,
huangs 2014/05/22 18:08:22 I suspect this is not called from the UI thread?
Mathieu 2014/05/22 19:46:32 Done.
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 // Contains the information related with a thumbnail fetch (fetcher, pending
huangs 2014/05/22 18:08:22 also mention |url|?
Mathieu 2014/05/22 19:46:32 Done.
56 // callbacks).
57 class Session {
huangs 2014/05/22 18:08:22 Since Session doesn't do anything interesting anym
Mathieu 2014/05/22 19:46:32 I can't get rid of the constructors, nor inline th
58 public:
59 Session();
60 ~Session();
61
62 GURL url_;
63 chrome::BitmapFetcher* fetcher_;
64 std::queue<BitmapResponseCallback> callbacks_;
huangs 2014/05/22 18:08:22 // Queue for pending callbacks, which may accumula
Mathieu 2014/05/22 19:46:32 Done.
65 };
66
67 typedef std::map<const GURL, Session> ThumbnailSessionMap;
68
69 // Given a website |url|, fill in a |thumbnail_url| and return whether it
huangs 2014/05/22 18:08:22 // Looks up thumbnail for |url|. If found, writes
Mathieu 2014/05/22 19:46:32 Done.
70 // exists or not.
71 bool GetThumbnailURL(const GURL& url, GURL* thumbnail_url);
72
73 // Used for substituting the request context during testing.
74 void set_request_context(net::URLRequestContextGetter* context) {
75 url_request_context_ = context;
76 }
77
78 // Map from URL to thumbnail URL. Should be kept up to date when a new
79 // SuggestionsProfile is available.
80 std::map<GURL, GURL> thumbnail_map_;
81
82 // Map from each thumbnail URL to the session information (fetcher,
huangs 2014/05/22 18:08:22 url is also part of session information.
Mathieu 2014/05/22 19:46:32 Done.
83 // pending callbacks).
84 ThumbnailSessionMap session_map_;
85
86 net::URLRequestContextGetter* url_request_context_;
87
88 DISALLOW_COPY_AND_ASSIGN(ThumbnailManager);
89 };
90
91 } // namespace suggestions
92
93 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698