Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / bitmap_fetcher.h
blobb468c038b8dc0162a32d1146d7da0fd2c545dfe6
1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_BITMAP_FETCHER_H_
6 #define CHROME_BROWSER_BITMAP_FETCHER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/bitmap_fetcher_delegate.h"
10 #include "chrome/browser/image_decoder.h"
11 #include "net/url_request/url_fetcher_delegate.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "url/gurl.h"
15 namespace net {
16 class URLFetcher;
17 class URLRequestContextGetter;
18 } // namespace net
20 namespace chrome {
22 // Asynchrounously fetches an image from the given URL and returns the
23 // decoded Bitmap to the provided BitmapFetcherDelegate.
24 class BitmapFetcher : public net::URLFetcherDelegate,
25 public ImageDecoder::Delegate {
26 public:
27 BitmapFetcher(const GURL& url, BitmapFetcherDelegate* delegate);
28 virtual ~BitmapFetcher();
30 const GURL& url() const { return url_; }
32 // Start fetching the URL with the fetcher. The delegate is notified
33 // asynchronously when done. Start may be called more than once in some
34 // cases. If so, subsequent starts will be ignored since the operation is
35 // already in progress.
36 void Start(net::URLRequestContextGetter* request_context);
38 // Methods inherited from URLFetcherDelegate
40 // This will be called when the URL has been fetched, successfully or not.
41 // Use accessor methods on |source| to get the results.
42 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
44 // This will be called when some part of the response is read. |current|
45 // denotes the number of bytes received up to the call, and |total| is the
46 // expected total size of the response (or -1 if not determined).
47 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source,
48 int64 current,
49 int64 total) OVERRIDE;
51 // Methods inherited from ImageDecoder::Delegate
53 // Called when image is decoded. |decoder| is used to identify the image in
54 // case of decoding several images simultaneously. This will not be called
55 // on the UI thread.
56 virtual void OnImageDecoded(const ImageDecoder* decoder,
57 const SkBitmap& decoded_image) OVERRIDE;
59 // Called when decoding image failed.
60 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE;
62 private:
63 // Alerts the delegate that a failure occurred.
64 void ReportFailure();
66 scoped_ptr<net::URLFetcher> url_fetcher_;
67 scoped_refptr<ImageDecoder> image_decoder_;
68 const GURL url_;
69 BitmapFetcherDelegate* const delegate_;
71 DISALLOW_COPY_AND_ASSIGN(BitmapFetcher);
74 } // namespace chrome
76 #endif // CHROME_BROWSER_BITMAP_FETCHER_H_