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

Side by Side Diff: components/image_fetcher/ios/ios_image_data_fetcher_wrapper.mm

Issue 2674653003: Use IOSImageDataFetcherWrapper in BrowserViewController (Closed)
Patch Set: Change IOSImageDataFetcherWrapper wrapping Created 3 years, 10 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h" 5 #import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h"
6 6
7 #import "base/mac/bind_objc_block.h" 7 #import "base/mac/bind_objc_block.h"
8 #import "base/mac/scoped_nsobject.h" 8 #import "base/mac/scoped_nsobject.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/task_runner.h" 10 #include "base/task_runner.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 : task_runner_(task_runner), 79 : task_runner_(task_runner),
80 image_data_fetcher_(url_request_context_getter) { 80 image_data_fetcher_(url_request_context_getter) {
81 DCHECK(task_runner_.get()); 81 DCHECK(task_runner_.get());
82 } 82 }
83 83
84 IOSImageDataFetcherWrapper::~IOSImageDataFetcherWrapper() {} 84 IOSImageDataFetcherWrapper::~IOSImageDataFetcherWrapper() {}
85 85
86 void IOSImageDataFetcherWrapper::FetchImageDataWebpDecoded( 86 void IOSImageDataFetcherWrapper::FetchImageDataWebpDecoded(
87 const GURL& image_url, 87 const GURL& image_url,
88 IOSImageDataFetcherCallback callback) { 88 IOSImageDataFetcherCallback callback) {
89 image_data_fetcher_.FetchImageData(image_url,
90 CallbackForImageDataFetcher(callback));
91 }
92
93 void IOSImageDataFetcherWrapper::FetchImageDataWebpDecoded(
94 const GURL& image_url,
95 IOSImageDataFetcherCallback callback,
96 const std::string& referrer,
97 net::URLRequest::ReferrerPolicy referrer_policy) {
89 DCHECK(callback); 98 DCHECK(callback);
90 99
91 scoped_refptr<base::TaskRunner> task_runner = task_runner_; 100 image_data_fetcher_.FetchImageData(image_url,
92 ImageDataFetcher::ImageDataFetcherCallback local_callback = 101 CallbackForImageDataFetcher(callback),
93 base::BindBlockArc(^(const std::string& image_data) { 102 referrer, referrer_policy);
94 // Create a NSData from the returned data and notify the callback.
95 NSData* data =
96 [NSData dataWithBytes:image_data.data() length:image_data.size()];
97
98 if (data.length < 12 ||
99 image_data.compare(0, 4, kWEBPFirstMagicPattern) != 0 ||
100 image_data.compare(8, 4, kWEBPSecondMagicPattern) != 0) {
101 callback(data);
102 return;
103 }
104
105 // The image is a webp image.
106 base::PostTaskAndReplyWithResult(task_runner.get(), FROM_HERE,
107 base::Bind(&DecodeWebpImage, data),
108 base::BindBlockArc(callback));
109 });
110 image_data_fetcher_.FetchImageData(image_url, local_callback);
111 } 103 }
112 104
113 void IOSImageDataFetcherWrapper::SetDataUseServiceName( 105 void IOSImageDataFetcherWrapper::SetDataUseServiceName(
114 DataUseServiceName data_use_service_name) { 106 DataUseServiceName data_use_service_name) {
115 image_data_fetcher_.SetDataUseServiceName(data_use_service_name); 107 image_data_fetcher_.SetDataUseServiceName(data_use_service_name);
116 } 108 }
117 109
110 ImageDataFetcher::ImageDataFetcherCallback
111 IOSImageDataFetcherWrapper::CallbackForImageDataFetcher(
112 IOSImageDataFetcherCallback callback) {
113 scoped_refptr<base::TaskRunner> task_runner = task_runner_;
114
115 return base::BindBlockArc(^(const std::string& image_data) {
116 // Create a NSData from the returned data and notify the callback.
117 NSData* data =
118 [NSData dataWithBytes:image_data.data() length:image_data.size()];
119
120 if (data.length < 12 ||
121 image_data.compare(0, 4, kWEBPFirstMagicPattern) != 0 ||
122 image_data.compare(8, 4, kWEBPSecondMagicPattern) != 0) {
123 callback(data);
124 return;
125 }
126
127 // The image is a webp image.
128 base::PostTaskAndReplyWithResult(task_runner.get(), FROM_HERE,
129 base::Bind(&DecodeWebpImage, data),
130 base::BindBlockArc(callback));
131 });
132 }
133
118 } // namespace image_fetcher 134 } // namespace image_fetcher
OLDNEW
« no previous file with comments | « components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h ('k') | ios/chrome/browser/ui/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698