Chromium Code Reviews| 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..5cfea41f62fa2c20a157f46c2c3ffd0865a0199e |
| --- /dev/null |
| +++ b/components/image_fetcher/image_data_fetcher.h |
| @@ -0,0 +1,54 @@ |
| +// 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 "base/macros.h" |
| +#include "net/url_request/url_fetcher.h" |
| +#include "net/url_request/url_fetcher_delegate.h" |
| +#include "net/url_request/url_request.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)>; |
| + |
| + 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 FetchImageURL(const GURL& image_url, |
|
Marc Treib
2016/06/10 08:32:37
FetchImageData?
markusheintz_
2016/06/10 09:43:14
Already done. Sorry I forgot last night and quickl
|
| + const ImageDataFetcherCallback& callback); |
| + |
| + private: |
| + class ImageDataFetcherRequest; |
|
Marc Treib
2016/06/10 08:32:37
optional: Since this is a private inner class, you
markusheintz_
2016/06/10 09:43:14
Acknowledged.
|
| + |
| + // 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>> request_queue_; |
|
Marc Treib
2016/06/10 08:32:37
Just requests_, or maybe pending_requests_? It's n
markusheintz_
2016/06/10 09:43:14
I chose pending_requests_.
|
| + |
| + net::URLRequestContextGetter* url_request_context_getter_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ImageDataFetcher); |
| +}; |
| + |
| +} // namespace image_fetcher |
| + |
| +#endif // COMPONENTS_IMAGE_FETCHER_IMAGE_DATA_FETCHER_H_ |