Chromium Code Reviews| Index: chrome/browser/search/suggestions/image_fetcher_impl.h |
| diff --git a/chrome/browser/search/suggestions/image_fetcher_impl.h b/chrome/browser/search/suggestions/image_fetcher_impl.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a7edd70f5e6bcfe388f1f6d1baacab1f9388e972 |
| --- /dev/null |
| +++ b/chrome/browser/search/suggestions/image_fetcher_impl.h |
| @@ -0,0 +1,83 @@ |
| +// 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_IMAGE_FETCHER_IMPL_H_ |
| +#define CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_ |
| + |
| +#include <map> |
| +#include <utility> |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/callback.h" |
| +#include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
| +#include "components/suggestions/image_fetcher.h" |
| +#include "ui/gfx/image/image_skia.h" |
| +#include "url/gurl.h" |
| + |
| +namespace net { |
| +class URLRequestContextGetter; |
| +} |
| + |
| +namespace suggestions { |
| + |
| +// A class used to fetch server images. |
| +class ImageFetcherImpl : public ImageFetcher, |
| + public chrome::BitmapFetcherDelegate { |
| + public: |
| + explicit ImageFetcherImpl(net::URLRequestContextGetter* url_request_context); |
| + virtual ~ImageFetcherImpl(); |
| + |
| + virtual void SetImageFetcherDelegate(ImageFetcherDelegate* delegate) OVERRIDE; |
| + |
| + virtual void StartOrQueueNetworkRequest( |
| + const GURL& url, const GURL& image_url, |
| + base::Callback<void(const GURL&, const SkBitmap*)> callback) OVERRIDE; |
| + |
| + private: |
| + // Inherited from BitmapFetcherDelegate. Runs on the UI thread. |
| + virtual void OnFetchComplete(const GURL image_url, |
|
huangs
2014/09/22 21:51:13
const GURL or const GURL& ? Also check .cc file.
Mathieu
2014/09/23 14:59:06
The bitmap_fetcher_delegate is not controlled by m
|
| + const SkBitmap* bitmap) OVERRIDE; |
| + |
| + typedef std::vector<base::Callback<void(const GURL&, const SkBitmap*)> > |
| + CallbackVector; |
| + |
| + // State related to an image fetch (associated website url, image_url, |
| + // fetcher, pending callbacks). |
| + struct ImageRequest { |
| + ImageRequest(); |
| + explicit ImageRequest(chrome::BitmapFetcher* f); |
|
huangs
2014/09/22 21:51:13
Comment on the fact that the class takes ownership
Mathieu
2014/09/23 14:59:06
Done.
|
| + ~ImageRequest(); |
| + |
| + void swap(ImageRequest* other) { |
| + std::swap(url, other->url); |
| + std::swap(image_url, other->image_url); |
| + std::swap(callbacks, other->callbacks); |
| + std::swap(fetcher, other->fetcher); |
| + } |
| + |
| + GURL url; |
| + GURL image_url; |
| + chrome::BitmapFetcher* fetcher; |
| + // Queue for pending callbacks, which may accumulate while the request is in |
| + // flight. |
| + CallbackVector callbacks; |
| + }; |
| + |
| + typedef std::map<const GURL, ImageRequest> ImageRequestMap; |
| + |
| + // Map from each image URL to the request information (associated website |
| + // url, fetcher, pending callbacks). |
| + ImageRequestMap pending_net_requests_; |
| + |
| + ImageFetcherDelegate* delegate_; |
| + |
| + net::URLRequestContextGetter* url_request_context_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl); |
| +}; |
| + |
| +} // namespace suggestions |
| + |
| +#endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_IMAGE_FETCHER_IMPL_H_ |