Chromium Code Reviews| Index: chrome/browser/safe_image_fetcher.h |
| diff --git a/chrome/browser/safe_image_fetcher.h b/chrome/browser/safe_image_fetcher.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..72e28ebc4760f9614dfe64f56fc3d9d53f3b2dbc |
| --- /dev/null |
| +++ b/chrome/browser/safe_image_fetcher.h |
| @@ -0,0 +1,49 @@ |
| +// Copyright 2015 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_SAFE_IMAGE_FETCHER_H_ |
| +#define CHROME_BROWSER_SAFE_IMAGE_FETCHER_H_ |
| + |
| +#include "base/callback_forward.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "chrome/browser/image_decoder.h" |
| +#include "net/url_request/url_fetcher_delegate.h" |
| +#include "url/gurl.h" |
| + |
| +class SkBitmap; |
| + |
| +namespace net { |
| +class URLFetcher; |
| +class URLRequestContextGetter; |
| +} |
| + |
| +// Helper class to fetch an image from a given URL and decode it into a SkBitmap |
|
Lei Zhang
2015/03/31 09:39:08
You may want to document the thread(s) this class
Lei Zhang
2015/03/31 09:39:09
This class sounds a lot like BitmapFetcher.
Marc Treib
2015/03/31 12:48:21
Indeed it does! I didn't know about BitmapFetcher.
|
| +// (safely in a utility process, by using ImageDecoder). In the case of an error |
| +// during fetching or decoding, an empty SkBitmap is returned. |
| +class SafeImageFetcher : public ImageDecoder::ImageRequest, |
| + public net::URLFetcherDelegate { |
| + public: |
| + using GetImageCallback = base::Callback<void(const SkBitmap&)>; |
| + |
| + SafeImageFetcher(const GURL& url, |
| + net::URLRequestContextGetter* context_getter, |
| + const GetImageCallback& callback); |
| + ~SafeImageFetcher() override; |
| + |
| + private: |
| + // net::URLFetcherDelegate implementation. |
| + void OnURLFetchComplete(const net::URLFetcher* source) override; |
| + |
| + // ImageDecoder::ImageRequest implementation. |
| + void OnImageDecoded(const SkBitmap& decoded_image) override; |
| + void OnDecodeImageFailed() override; |
| + |
| + scoped_ptr<net::URLFetcher> url_fetcher_; |
| + GetImageCallback callback_; |
| + |
| + base::WeakPtrFactory<SafeImageFetcher> weak_ptr_factory_; |
| +}; |
|
Lei Zhang
2015/03/31 09:39:09
DISALLOW_COPY_AND_ASSIGN() ?
|
| + |
| +#endif // CHROME_BROWSER_SAFE_IMAGE_FETCHER_H_ |