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

Unified Diff: chrome/browser/search/suggestions/image_fetcher_impl.h

Issue 543753002: [Suggestions] Move ImageManager to the component (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/search/suggestions/image_fetcher_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_
« no previous file with comments | « no previous file | chrome/browser/search/suggestions/image_fetcher_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698