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

Unified Diff: components/image_fetcher/image_data_fetcher.h

Issue 2064793004: Reland: Split the code for fetching images and for decoding images into two separate classes. This w (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only start image requests once (Fixes a bug). Created 4 years, 6 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 | « components/image_fetcher/DEPS ('k') | components/image_fetcher/image_data_fetcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/image_fetcher/image_data_fetcher.h
diff --git a/components/image_fetcher/image_data_fetcher.h b/components/image_fetcher/image_data_fetcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..c503db85b506b399bf224d66fe90dede1de3d777
--- /dev/null
+++ b/components/image_fetcher/image_data_fetcher.h
@@ -0,0 +1,56 @@
+// Copyright 2016 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 COMPONENTS_IMAGE_FETCHER_IMAGE_DATA_FETCHER_H_
+#define COMPONENTS_IMAGE_FETCHER_IMAGE_DATA_FETCHER_H_
+
+#include <map>
+#include <memory>
+#include <string>
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "url/gurl.h"
+
+namespace net {
+class URLRequestContextGetter;
+} // namespace net
+
+namespace image_fetcher {
+
+class ImageDataFetcher {
+ public:
+ using ImageDataFetcherCallback =
+ base::Callback<void(const std::string& image_data)>;
+
+ explicit ImageDataFetcher(
+ net::URLRequestContextGetter* url_request_context_getter);
+ ~ImageDataFetcher();
+
+ // Fetches the raw image bytes from the given |image_url| and calls the given
+ // |callback|. The callback is run even if fetching the URL fails. In case
+ // of an error an empty string is passed to the callback.
+ void FetchImageData(const GURL& image_url,
+ const ImageDataFetcherCallback& callback);
+
+ private:
+ class ImageDataFetcherRequest;
+
+ // Removes the ImageDataFetcherRequest for the given |image_url| from the
+ // internal request queue.
+ void RemoveImageDataFetcherRequest(const GURL& image_url);
+
+ // All active image url requests.
+ std::map<const GURL, std::unique_ptr<ImageDataFetcherRequest>>
+ pending_requests_;
+
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
+
+ DISALLOW_COPY_AND_ASSIGN(ImageDataFetcher);
+};
+
+} // namespace image_fetcher
+
+#endif // COMPONENTS_IMAGE_FETCHER_IMAGE_DATA_FETCHER_H_
« no previous file with comments | « components/image_fetcher/DEPS ('k') | components/image_fetcher/image_data_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698