OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #import "ios/chrome/browser/net/image_fetcher.h" | 5 #import "ios/chrome/browser/net/image_fetcher.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // Delegate callback that is called when URLFetcher completes. If the image | 105 // Delegate callback that is called when URLFetcher completes. If the image |
106 // was fetched successfully, creates a new NSData and returns it to the | 106 // was fetched successfully, creates a new NSData and returns it to the |
107 // callback, otherwise returns nil to the callback. | 107 // callback, otherwise returns nil to the callback. |
108 void ImageFetcher::OnURLFetchComplete(const net::URLFetcher* fetcher) { | 108 void ImageFetcher::OnURLFetchComplete(const net::URLFetcher* fetcher) { |
109 if (downloads_in_progress_.find(fetcher) == downloads_in_progress_.end()) { | 109 if (downloads_in_progress_.find(fetcher) == downloads_in_progress_.end()) { |
110 LOG(ERROR) << "Received callback for unknown URLFetcher " << fetcher; | 110 LOG(ERROR) << "Received callback for unknown URLFetcher " << fetcher; |
111 return; | 111 return; |
112 } | 112 } |
113 | 113 |
114 // Ensures that |fetcher| will be deleted in the event of early return. | 114 // Ensures that |fetcher| will be deleted in the event of early return. |
115 scoped_ptr<const net::URLFetcher> fetcher_deleter(fetcher); | 115 std::unique_ptr<const net::URLFetcher> fetcher_deleter(fetcher); |
116 | 116 |
117 // Retrieves the callback and ensures that it will be deleted in the event | 117 // Retrieves the callback and ensures that it will be deleted in the event |
118 // of early return. | 118 // of early return. |
119 base::mac::ScopedBlock<ImageFetchedCallback> callback( | 119 base::mac::ScopedBlock<ImageFetchedCallback> callback( |
120 downloads_in_progress_[fetcher]); | 120 downloads_in_progress_[fetcher]); |
121 | 121 |
122 // Remove |fetcher| from the map. | 122 // Remove |fetcher| from the map. |
123 downloads_in_progress_.erase(fetcher); | 123 downloads_in_progress_.erase(fetcher); |
124 | 124 |
125 // Make sure the request was successful. For "data" requests, the response | 125 // Make sure the request was successful. For "data" requests, the response |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 NSData* data) { | 169 NSData* data) { |
170 (callback.get())(url, http_response_code, data); | 170 (callback.get())(url, http_response_code, data); |
171 } | 171 } |
172 | 172 |
173 void ImageFetcher::SetRequestContextGetter( | 173 void ImageFetcher::SetRequestContextGetter( |
174 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter) { | 174 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter) { |
175 request_context_getter_ = request_context_getter; | 175 request_context_getter_ = request_context_getter; |
176 } | 176 } |
177 | 177 |
178 } // namespace image_fetcher | 178 } // namespace image_fetcher |
OLD | NEW |