OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_SAFE_IMAGE_FETCHER_H_ | |
6 #define CHROME_BROWSER_SAFE_IMAGE_FETCHER_H_ | |
7 | |
8 #include "base/callback_forward.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/memory/weak_ptr.h" | |
11 #include "chrome/browser/image_decoder.h" | |
12 #include "net/url_request/url_fetcher_delegate.h" | |
13 #include "url/gurl.h" | |
14 | |
15 class SkBitmap; | |
16 | |
17 namespace net { | |
18 class URLFetcher; | |
19 class URLRequestContextGetter; | |
20 } | |
21 | |
22 // 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.
| |
23 // (safely in a utility process, by using ImageDecoder). In the case of an error | |
24 // during fetching or decoding, an empty SkBitmap is returned. | |
25 class SafeImageFetcher : public ImageDecoder::ImageRequest, | |
26 public net::URLFetcherDelegate { | |
27 public: | |
28 using GetImageCallback = base::Callback<void(const SkBitmap&)>; | |
29 | |
30 SafeImageFetcher(const GURL& url, | |
31 net::URLRequestContextGetter* context_getter, | |
32 const GetImageCallback& callback); | |
33 ~SafeImageFetcher() override; | |
34 | |
35 private: | |
36 // net::URLFetcherDelegate implementation. | |
37 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
38 | |
39 // ImageDecoder::ImageRequest implementation. | |
40 void OnImageDecoded(const SkBitmap& decoded_image) override; | |
41 void OnDecodeImageFailed() override; | |
42 | |
43 scoped_ptr<net::URLFetcher> url_fetcher_; | |
44 GetImageCallback callback_; | |
45 | |
46 base::WeakPtrFactory<SafeImageFetcher> weak_ptr_factory_; | |
47 }; | |
Lei Zhang
2015/03/31 09:39:09
DISALLOW_COPY_AND_ASSIGN() ?
| |
48 | |
49 #endif // CHROME_BROWSER_SAFE_IMAGE_FETCHER_H_ | |
OLD | NEW |