Chromium Code Reviews| Index: chrome/browser/search/suggestions/thumbnail_manager.h |
| diff --git a/chrome/browser/search/suggestions/thumbnail_manager.h b/chrome/browser/search/suggestions/thumbnail_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9b0f5011e58f160e2dd83c102333044a39bad18c |
| --- /dev/null |
| +++ b/chrome/browser/search/suggestions/thumbnail_manager.h |
| @@ -0,0 +1,92 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_ |
| +#define CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_ |
| + |
| +#include <map> |
| +#include <queue> |
| +#include <utility> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/callback.h" |
| +#include "chrome/browser/bitmap_fetcher.h" |
| +#include "ui/gfx/image/image_skia.h" |
| +#include "url/gurl.h" |
| + |
| +class Profile; |
| + |
| +namespace suggestions { |
| + |
| +typedef base::Callback<void(const GURL&, const SkBitmap*)> |
| + BitmapResponseCallback; |
| + |
| +class SuggestionsProfile; |
| + |
| +// 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
|
| +class ThumbnailManager : public chrome::BitmapFetcherDelegate { |
| + public: |
| + explicit ThumbnailManager(Profile* profile); |
| + virtual ~ThumbnailManager(); |
| + |
| + // 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.
|
| + // thumbnail URL. |
| + void InitializeThumbnailMap(const SuggestionsProfile& suggestions); |
| + |
| + // 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.
|
| + // thumbnail image as a Bitmap pointer to |callback| if found, and NULL |
| + // otherwise. Calls should originate from the UI thread. |
| + void GetPageThumbnail(const GURL& url, BitmapResponseCallback callback); |
| + |
| + // Inherited from BitmapFetcherDelegate. Runs on the UI thread. |
| + virtual void OnFetchComplete(const GURL thumbnail_url, |
| + const SkBitmap* bitmap) OVERRIDE; |
| + |
| + private: |
| + FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerTest, InitializeThumbnailMapTest); |
| + FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerBrowserTest, FetchThumbnails); |
| + FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerBrowserTest, FetchThumbnailsInvalid); |
| + FRIEND_TEST_ALL_PREFIXES(ThumbnailManagerBrowserTest, |
| + FetchThumbnailsMultiple); |
| + |
| + // 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.
|
| + // url, fetcher, pending callbacks). |
| + 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.
|
| + Session(); |
| + ~Session(); |
| + |
| + GURL url; |
| + chrome::BitmapFetcher* fetcher; |
| + // Queue for pending callbacks, which may accumulate while the request is in |
| + // flight. |
| + 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.
|
| + }; |
| + |
| + typedef std::map<const GURL, Session> ThumbnailSessionMap; |
| + |
| + // Looks up thumbnail for |url|. If found, writes the result to |
| + // |thumbnail_url| and returns true. Otherwise just returns false. |
| + bool GetThumbnailURL(const GURL& url, GURL* thumbnail_url); |
| + |
| + // Used for substituting the request context during testing. |
| + void set_request_context(net::URLRequestContextGetter* context) { |
| + url_request_context_ = context; |
| + } |
| + |
| + // Map from URL to thumbnail URL. Should be kept up to date when a new |
| + // SuggestionsProfile is available. |
| + std::map<GURL, GURL> thumbnail_map_; |
| + |
| + // Map from each thumbnail URL to the session information (associated website |
| + // url, fetcher, pending callbacks). |
| + ThumbnailSessionMap session_map_; |
|
Jered
2014/05/23 16:57:48
I'd call this pending_requests_.
Mathieu
2014/05/23 19:21:58
Done.
|
| + |
| + net::URLRequestContextGetter* url_request_context_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ThumbnailManager); |
| +}; |
| + |
| +} // namespace suggestions |
| + |
| +#endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_THUMBNAIL_MANAGER_H_ |