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

Unified Diff: chrome/browser/safe_image_fetcher.h

Issue 855513002: Add/resurrect support for bundles of WebStore items. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@testext_bundle
Patch Set: add CRXs Created 5 years, 9 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
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_

Powered by Google App Engine
This is Rietveld 408576698