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

Side by Side Diff: chrome/browser/safe_browsing/notification_image_reporter.cc

Issue 2821193005: Rewrite base::Bind to base::BindOnce with base_bind_rewriters in //chrome/browser/safe_browsing (Closed)
Patch Set: Created 3 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 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 #include "chrome/browser/safe_browsing/notification_image_reporter.h" 5 #include "chrome/browser/safe_browsing/notification_image_reporter.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 return; 106 return;
107 } 107 }
108 // n.b. we write to report_times_ here even if we'll later end up skipping 108 // n.b. we write to report_times_ here even if we'll later end up skipping
109 // reporting because GetExtendedReportingLevel was not SBER_LEVEL_SCOUT. That 109 // reporting because GetExtendedReportingLevel was not SBER_LEVEL_SCOUT. That
110 // saves us two thread hops, with the downside that we may underreport 110 // saves us two thread hops, with the downside that we may underreport
111 // notifications on the first day that a user opts in to SBER_LEVEL_SCOUT. 111 // notifications on the first day that a user opts in to SBER_LEVEL_SCOUT.
112 report_times_.push(base::Time::Now()); 112 report_times_.push(base::Time::Now());
113 113
114 BrowserThread::PostTask( 114 BrowserThread::PostTask(
115 BrowserThread::UI, FROM_HERE, 115 BrowserThread::UI, FROM_HERE,
116 base::Bind(&NotificationImageReporter::ReportNotificationImageOnUI, 116 base::BindOnce(&NotificationImageReporter::ReportNotificationImageOnUI,
117 weak_factory_on_io_.GetWeakPtr(), profile, origin, image)); 117 weak_factory_on_io_.GetWeakPtr(), profile, origin, image));
118 } 118 }
119 119
120 double NotificationImageReporter::GetReportChance() const { 120 double NotificationImageReporter::GetReportChance() const {
121 // Get the report_chance from the Finch experiment. If there is no active 121 // Get the report_chance from the Finch experiment. If there is no active
122 // experiment, it will be set to the default of 0. 122 // experiment, it will be set to the default of 0.
123 double report_chance = variations::GetVariationParamByFeatureAsDouble( 123 double report_chance = variations::GetVariationParamByFeatureAsDouble(
124 kNotificationImageReporterFeature, kReportChance, 0.0); 124 kNotificationImageReporterFeature, kReportChance, 0.0);
125 125
126 if (report_chance < 0.0 || report_chance > 1.0) { 126 if (report_chance < 0.0 || report_chance > 1.0) {
127 DLOG(WARNING) << "Illegal value " << report_chance << " for the parameter " 127 DLOG(WARNING) << "Illegal value " << report_chance << " for the parameter "
(...skipping 11 matching lines...) Expand all
139 const base::WeakPtr<NotificationImageReporter>& weak_this_on_io, 139 const base::WeakPtr<NotificationImageReporter>& weak_this_on_io,
140 Profile* profile, 140 Profile* profile,
141 const GURL& origin, 141 const GURL& origin,
142 const SkBitmap& image) { 142 const SkBitmap& image) {
143 DCHECK_CURRENTLY_ON(BrowserThread::UI); 143 DCHECK_CURRENTLY_ON(BrowserThread::UI);
144 144
145 // Skip reporting unless SBER2 Scout is enabled. 145 // Skip reporting unless SBER2 Scout is enabled.
146 if (GetExtendedReportingLevel(*profile->GetPrefs()) != SBER_LEVEL_SCOUT) { 146 if (GetExtendedReportingLevel(*profile->GetPrefs()) != SBER_LEVEL_SCOUT) {
147 BrowserThread::PostTask( 147 BrowserThread::PostTask(
148 BrowserThread::IO, FROM_HERE, 148 BrowserThread::IO, FROM_HERE,
149 base::Bind(&NotificationImageReporter::SkippedReporting, 149 base::BindOnce(&NotificationImageReporter::SkippedReporting,
150 weak_this_on_io)); 150 weak_this_on_io));
151 return; 151 return;
152 } 152 }
153 153
154 BrowserThread::GetBlockingPool()->PostWorkerTask( 154 BrowserThread::GetBlockingPool()->PostWorkerTask(
155 FROM_HERE, 155 FROM_HERE,
156 base::Bind( 156 base::BindOnce(
157 &NotificationImageReporter::DownscaleNotificationImageOnBlockingPool, 157 &NotificationImageReporter::DownscaleNotificationImageOnBlockingPool,
158 weak_this_on_io, origin, image)); 158 weak_this_on_io, origin, image));
159 } 159 }
160 160
161 // static 161 // static
162 void NotificationImageReporter::DownscaleNotificationImageOnBlockingPool( 162 void NotificationImageReporter::DownscaleNotificationImageOnBlockingPool(
163 const base::WeakPtr<NotificationImageReporter>& weak_this_on_io, 163 const base::WeakPtr<NotificationImageReporter>& weak_this_on_io,
164 const GURL& origin, 164 const GURL& origin,
165 const SkBitmap& image) { 165 const SkBitmap& image) {
166 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 166 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
(...skipping 13 matching lines...) Expand all
180 180
181 // Encode as PNG. 181 // Encode as PNG.
182 std::vector<unsigned char> png_bytes; 182 std::vector<unsigned char> png_bytes;
183 if (!gfx::PNGCodec::EncodeBGRASkBitmap(downscaled_image, false, &png_bytes)) { 183 if (!gfx::PNGCodec::EncodeBGRASkBitmap(downscaled_image, false, &png_bytes)) {
184 NOTREACHED(); 184 NOTREACHED();
185 return; 185 return;
186 } 186 }
187 187
188 BrowserThread::PostTask( 188 BrowserThread::PostTask(
189 BrowserThread::IO, FROM_HERE, 189 BrowserThread::IO, FROM_HERE,
190 base::Bind(&NotificationImageReporter::SendReportOnIO, weak_this_on_io, 190 base::BindOnce(
191 origin, base::RefCountedBytes::TakeVector(&png_bytes), 191 &NotificationImageReporter::SendReportOnIO, weak_this_on_io, origin,
192 gfx::Size(downscaled_image.width(), downscaled_image.height()), 192 base::RefCountedBytes::TakeVector(&png_bytes),
193 gfx::Size(image.width(), image.height()))); 193 gfx::Size(downscaled_image.width(), downscaled_image.height()),
194 gfx::Size(image.width(), image.height())));
194 } 195 }
195 196
196 void NotificationImageReporter::SendReportOnIO( 197 void NotificationImageReporter::SendReportOnIO(
197 const GURL& origin, 198 const GURL& origin,
198 scoped_refptr<base::RefCountedMemory> data, 199 scoped_refptr<base::RefCountedMemory> data,
199 const gfx::Size& dimensions, 200 const gfx::Size& dimensions,
200 const gfx::Size& original_dimensions) { 201 const gfx::Size& original_dimensions) {
201 DCHECK_CURRENTLY_ON(BrowserThread::IO); 202 DCHECK_CURRENTLY_ON(BrowserThread::IO);
202 203
203 NotificationImageReportRequest report; 204 NotificationImageReportRequest report;
(...skipping 12 matching lines...) Expand all
216 std::string serialized_report; 217 std::string serialized_report;
217 report.SerializeToString(&serialized_report); 218 report.SerializeToString(&serialized_report);
218 report_sender_->Send( 219 report_sender_->Send(
219 GURL(kReportingUploadUrl), "application/octet-stream", serialized_report, 220 GURL(kReportingUploadUrl), "application/octet-stream", serialized_report,
220 base::Bind(&LogReportResult, GURL(kReportingUploadUrl), net::OK), 221 base::Bind(&LogReportResult, GURL(kReportingUploadUrl), net::OK),
221 base::Bind(&LogReportResult)); 222 base::Bind(&LogReportResult));
222 // TODO(johnme): Consider logging bandwidth and/or duration to UMA. 223 // TODO(johnme): Consider logging bandwidth and/or duration to UMA.
223 } 224 }
224 225
225 } // namespace safe_browsing 226 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698