| 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..4d79a6cd892b2c00bee26c18de69d49f3b1cff56
|
| --- /dev/null
|
| +++ b/chrome/browser/search/suggestions/image_fetcher_impl.h
|
| @@ -0,0 +1,84 @@
|
| +// 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,
|
| + 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();
|
| + // Struct takes ownership of |f|.
|
| + explicit ImageRequest(chrome::BitmapFetcher* f);
|
| + ~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_
|
|
|