| OLD | NEW |
| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 base::BindOnce( | 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 base::ThreadRestrictions::AssertIOAllowed(); |
| 167 | 167 |
| 168 // Downscale to fit within 512x512. TODO(johnme): Get this from Finch. | 168 // Downscale to fit within 512x512. TODO(johnme): Get this from Finch. |
| 169 const double MAX_SIZE = 512; | 169 const double MAX_SIZE = 512; |
| 170 SkBitmap downscaled_image = image; | 170 SkBitmap downscaled_image = image; |
| 171 if ((image.width() > MAX_SIZE || image.height() > MAX_SIZE) && | 171 if ((image.width() > MAX_SIZE || image.height() > MAX_SIZE) && |
| 172 image.width() > 0 && image.height() > 0) { | 172 image.width() > 0 && image.height() > 0) { |
| 173 double scale = | 173 double scale = |
| 174 std::min(MAX_SIZE / image.width(), MAX_SIZE / image.height()); | 174 std::min(MAX_SIZE / image.width(), MAX_SIZE / image.height()); |
| 175 downscaled_image = | 175 downscaled_image = |
| 176 skia::ImageOperations::Resize(image, skia::ImageOperations::RESIZE_GOOD, | 176 skia::ImageOperations::Resize(image, skia::ImageOperations::RESIZE_GOOD, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 report.SerializeToString(&serialized_report); | 218 report.SerializeToString(&serialized_report); |
| 219 report_sender_->Send(GURL(kReportingUploadUrl), "application/octet-stream", | 219 report_sender_->Send(GURL(kReportingUploadUrl), "application/octet-stream", |
| 220 serialized_report, | 220 serialized_report, |
| 221 base::Bind(&LogReportResult, GURL(kReportingUploadUrl), | 221 base::Bind(&LogReportResult, GURL(kReportingUploadUrl), |
| 222 net::OK, net::HTTP_OK), | 222 net::OK, net::HTTP_OK), |
| 223 base::Bind(&LogReportResult)); | 223 base::Bind(&LogReportResult)); |
| 224 // TODO(johnme): Consider logging bandwidth and/or duration to UMA. | 224 // TODO(johnme): Consider logging bandwidth and/or duration to UMA. |
| 225 } | 225 } |
| 226 | 226 |
| 227 } // namespace safe_browsing | 227 } // namespace safe_browsing |
| OLD | NEW |