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

Side by Side Diff: chrome/browser/bitmap_fetcher/bitmap_fetcher.h

Issue 1097383005: Add possibility to define data callback to BitmapFetcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@r479598_extensions_content_verifier_directories_fail
Patch Set: Created 5 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_H_ 5 #ifndef CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_H_
6 #define CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_H_ 6 #define CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_H_
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_delegate.h" 9 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_delegate.h"
10 #include "chrome/browser/image_decoder.h" 10 #include "chrome/browser/image_decoder.h"
11 #include "net/url_request/url_fetcher.h"
11 #include "net/url_request/url_fetcher_delegate.h" 12 #include "net/url_request/url_fetcher_delegate.h"
12 #include "net/url_request/url_request.h" 13 #include "net/url_request/url_request.h"
13 #include "third_party/skia/include/core/SkBitmap.h" 14 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "url/gurl.h" 15 #include "url/gurl.h"
15 16
16 namespace net { 17 namespace net {
17 class URLFetcher;
18 class URLRequestContextGetter; 18 class URLRequestContextGetter;
19 } // namespace net 19 } // namespace net
20 20
21 namespace chrome { 21 namespace chrome {
22 22
23 // Asynchrounously fetches an image from the given URL and returns the 23 // Asynchrounously fetches an image from the given URL and returns the
24 // decoded Bitmap to the provided BitmapFetcherDelegate. 24 // decoded Bitmap to the provided BitmapFetcherDelegate.
25 class BitmapFetcher : public net::URLFetcherDelegate, 25 class BitmapFetcher : public net::URLFetcherDelegate,
26 public ImageDecoder::ImageRequest { 26 public ImageDecoder::ImageRequest {
27 public: 27 public:
28 BitmapFetcher(const GURL& url, BitmapFetcherDelegate* delegate); 28 BitmapFetcher(const GURL& url, BitmapFetcherDelegate* delegate);
29 ~BitmapFetcher() override; 29 ~BitmapFetcher() override;
30 30
31 const GURL& url() const { return url_; } 31 const GURL& url() const { return url_; }
32 32
33 // Start fetching the URL with the fetcher. The delegate is notified 33 // Start fetching the URL with the fetcher. The delegate is notified
34 // asynchronously when done. Start may be called more than once in some 34 // asynchronously when done. Start may be called more than once in some
35 // cases. If so, subsequent starts will be ignored since the operation is 35 // cases. If so, subsequent starts will be ignored since the operation is
36 // already in progress. Arguments are used to configure the internal fetcher. 36 // already in progress. Arguments are used to configure the internal fetcher.
37 // Values for |load_flags| are defined in net/base/load_flags.h. In general, 37 // Values for |load_flags| are defined in net/base/load_flags.h. In general,
38 // |net::LOAD_NORMAL| is appropriate. 38 // |net::LOAD_NORMAL| is appropriate.
39 void Start(net::URLRequestContextGetter* request_context, 39 void Start(net::URLRequestContextGetter* request_context,
40 const std::string& referrer, 40 const std::string& referrer,
41 net::URLRequest::ReferrerPolicy referrer_policy, 41 net::URLRequest::ReferrerPolicy referrer_policy,
42 int load_flags); 42 int load_flags);
43 43
44 // Like BitmapFetcher::Start above but it allows to define user data key
45 // and create data callback for URLFetcher it creates.
Theresa 2015/04/22 23:07:06 The phrasing here is a little unclear, maybe somet
46 void Start(net::URLRequestContextGetter* request_context,
47 const std::string& referrer,
48 net::URLRequest::ReferrerPolicy referrer_policy,
49 int load_flags,
50 const void* user_data_key,
51 const net::URLFetcher::CreateDataCallback& create_data_callback);
52
44 // Methods inherited from URLFetcherDelegate 53 // Methods inherited from URLFetcherDelegate
45 54
46 // This will be called when the URL has been fetched, successfully or not. 55 // This will be called when the URL has been fetched, successfully or not.
47 // Use accessor methods on |source| to get the results. 56 // Use accessor methods on |source| to get the results.
48 void OnURLFetchComplete(const net::URLFetcher* source) override; 57 void OnURLFetchComplete(const net::URLFetcher* source) override;
49 58
50 // This will be called when some part of the response is read. |current| 59 // This will be called when some part of the response is read. |current|
51 // denotes the number of bytes received up to the call, and |total| is the 60 // denotes the number of bytes received up to the call, and |total| is the
52 // expected total size of the response (or -1 if not determined). 61 // expected total size of the response (or -1 if not determined).
53 void OnURLFetchDownloadProgress(const net::URLFetcher* source, 62 void OnURLFetchDownloadProgress(const net::URLFetcher* source,
54 int64 current, 63 int64 current,
55 int64 total) override; 64 int64 total) override;
56 65
57 // Methods inherited from ImageDecoder::ImageRequest 66 // Methods inherited from ImageDecoder::ImageRequest
58 67
59 // Called when image is decoded. |decoder| is used to identify the image in 68 // Called when image is decoded. |decoder| is used to identify the image in
60 // case of decoding several images simultaneously. This will not be called 69 // case of decoding several images simultaneously. This will not be called
61 // on the UI thread. 70 // on the UI thread.
62 void OnImageDecoded(const SkBitmap& decoded_image) override; 71 void OnImageDecoded(const SkBitmap& decoded_image) override;
63 72
64 // Called when decoding image failed. 73 // Called when decoding image failed.
65 void OnDecodeImageFailed() override; 74 void OnDecodeImageFailed() override;
66 75
67 private: 76 private:
68 // Alerts the delegate that a failure occurred. 77 // Alerts the delegate that a failure occurred.
69 void ReportFailure(); 78 void ReportFailure();
70 79
80 scoped_ptr<net::URLFetcher> CreateURLFetcher(
81 net::URLRequestContextGetter* request_context,
82 const std::string& referrer,
83 net::URLRequest::ReferrerPolicy referrer_policy,
84 int load_flags);
85
71 scoped_ptr<net::URLFetcher> url_fetcher_; 86 scoped_ptr<net::URLFetcher> url_fetcher_;
72 const GURL url_; 87 const GURL url_;
73 BitmapFetcherDelegate* const delegate_; 88 BitmapFetcherDelegate* const delegate_;
74 89
75 DISALLOW_COPY_AND_ASSIGN(BitmapFetcher); 90 DISALLOW_COPY_AND_ASSIGN(BitmapFetcher);
76 }; 91 };
77 92
78 } // namespace chrome 93 } // namespace chrome
79 94
80 #endif // CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_H_ 95 #endif // CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/bitmap_fetcher/bitmap_fetcher.cc » ('j') | chrome/browser/bitmap_fetcher/bitmap_fetcher.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698