Commit e232eca6 authored by pkasting's avatar pkasting Committed by Commit bot

Type conversion fixes, components/ edition.

This is mostly to fix MSVC warnings about possible value truncation.

BUG=81439
TEST=none

Review URL: https://codereview.chromium.org/656363002

Cr-Commit-Position: refs/heads/master@{#300134}
parent 69ccb323
...@@ -55,7 +55,8 @@ std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing( ...@@ -55,7 +55,8 @@ std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing(
// create a bitmap with given pixel size. // create a bitmap with given pixel size.
std::map<int, float> desired_pixel_sizes; std::map<int, float> desired_pixel_sizes;
for (size_t i = 0; i < favicon_scales.size(); ++i) { for (size_t i = 0; i < favicon_scales.size(); ++i) {
int pixel_size = std::ceil(favicon_size * favicon_scales[i]); int pixel_size =
static_cast<int>(std::ceil(favicon_size * favicon_scales[i]));
desired_pixel_sizes[pixel_size] = favicon_scales[i]; desired_pixel_sizes[pixel_size] = favicon_scales[i];
} }
...@@ -78,57 +79,58 @@ std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing( ...@@ -78,57 +79,58 @@ std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing(
return png_reps; return png_reps;
} }
// Returns a resampled bitmap of // Returns a resampled bitmap of |desired_size| x |desired_size| by resampling
// |desired_size_in_pixel| x |desired_size_in_pixel| by resampling the best // the best bitmap out of |input_bitmaps|.
// bitmap out of |input_bitmaps|. ResizeBitmapByDownsamplingIfPossible() is // ResizeBitmapByDownsamplingIfPossible() is similar to SelectFaviconFrames()
// similar to SelectFaviconFrames() but it operates on bitmaps which have // but it operates on bitmaps which have already been resampled via
// already been resampled via SelectFaviconFrames(). // SelectFaviconFrames().
SkBitmap ResizeBitmapByDownsamplingIfPossible( SkBitmap ResizeBitmapByDownsamplingIfPossible(
const std::vector<SkBitmap>& input_bitmaps, const std::vector<SkBitmap>& input_bitmaps,
int desired_size_in_pixel) { int desired_size) {
DCHECK(!input_bitmaps.empty()); DCHECK(!input_bitmaps.empty());
DCHECK_NE(desired_size_in_pixel, 0); DCHECK_NE(0, desired_size);
SkBitmap best_bitmap; SkBitmap best_bitmap;
for (size_t i = 0; i < input_bitmaps.size(); ++i) { for (size_t i = 0; i < input_bitmaps.size(); ++i) {
const SkBitmap& input_bitmap = input_bitmaps[i]; const SkBitmap& input_bitmap = input_bitmaps[i];
if (input_bitmap.width() == desired_size_in_pixel && if (input_bitmap.width() == desired_size &&
input_bitmap.height() == desired_size_in_pixel) { input_bitmap.height() == desired_size) {
return input_bitmap; return input_bitmap;
} else if (best_bitmap.isNull()) { } else if (best_bitmap.isNull()) {
best_bitmap = input_bitmap; best_bitmap = input_bitmap;
} else if (input_bitmap.width() >= best_bitmap.width() && } else if (input_bitmap.width() >= best_bitmap.width() &&
input_bitmap.height() >= best_bitmap.height()) { input_bitmap.height() >= best_bitmap.height()) {
if (best_bitmap.width() < desired_size_in_pixel || if (best_bitmap.width() < desired_size ||
best_bitmap.height() < desired_size_in_pixel) { best_bitmap.height() < desired_size) {
best_bitmap = input_bitmap; best_bitmap = input_bitmap;
} }
} else { } else {
if (input_bitmap.width() >= desired_size_in_pixel && if (input_bitmap.width() >= desired_size &&
input_bitmap.height() >= desired_size_in_pixel) { input_bitmap.height() >= desired_size) {
best_bitmap = input_bitmap; best_bitmap = input_bitmap;
} }
} }
} }
if (desired_size_in_pixel % best_bitmap.width() == 0 && if (desired_size % best_bitmap.width() == 0 &&
desired_size_in_pixel % best_bitmap.height() == 0) { desired_size % best_bitmap.height() == 0) {
// Use nearest neighbour resampling if upsampling by an integer. This // Use nearest neighbour resampling if upsampling by an integer. This
// makes the result look similar to the result of SelectFaviconFrames(). // makes the result look similar to the result of SelectFaviconFrames().
SkBitmap bitmap; SkBitmap bitmap;
bitmap.allocN32Pixels(desired_size_in_pixel, desired_size_in_pixel); bitmap.allocN32Pixels(desired_size, desired_size);
if (!best_bitmap.isOpaque()) if (!best_bitmap.isOpaque())
bitmap.eraseARGB(0, 0, 0, 0); bitmap.eraseARGB(0, 0, 0, 0);
SkCanvas canvas(bitmap); SkCanvas canvas(bitmap);
SkRect dest(SkRect::MakeWH(desired_size_in_pixel, desired_size_in_pixel)); canvas.drawBitmapRect(
canvas.drawBitmapRect(best_bitmap, NULL, dest); best_bitmap, NULL,
SkRect::MakeFromIRect(SkIRect::MakeWH(desired_size, desired_size)));
return bitmap; return bitmap;
} }
return skia::ImageOperations::Resize(best_bitmap, return skia::ImageOperations::Resize(best_bitmap,
skia::ImageOperations::RESIZE_LANCZOS3, skia::ImageOperations::RESIZE_LANCZOS3,
desired_size_in_pixel, desired_size,
desired_size_in_pixel); desired_size);
} }
} // namespace } // namespace
...@@ -214,7 +216,8 @@ gfx::Image SelectFaviconFramesFromPNGs( ...@@ -214,7 +216,8 @@ gfx::Image SelectFaviconFramesFromPNGs(
gfx::ImageSkia resized_image_skia; gfx::ImageSkia resized_image_skia;
for (size_t i = 0; i < favicon_scales_to_generate.size(); ++i) { for (size_t i = 0; i < favicon_scales_to_generate.size(); ++i) {
float scale = favicon_scales_to_generate[i]; float scale = favicon_scales_to_generate[i];
int desired_size_in_pixel = std::ceil(favicon_size * scale); int desired_size_in_pixel =
static_cast<int>(std::ceil(favicon_size * scale));
SkBitmap bitmap = SkBitmap bitmap =
ResizeBitmapByDownsamplingIfPossible(bitmaps, desired_size_in_pixel); ResizeBitmapByDownsamplingIfPossible(bitmaps, desired_size_in_pixel);
resized_image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); resized_image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale));
......
...@@ -41,8 +41,9 @@ SkBitmap SampleNearestNeighbor(const SkBitmap& contents, int desired_size) { ...@@ -41,8 +41,9 @@ SkBitmap SampleNearestNeighbor(const SkBitmap& contents, int desired_size) {
{ {
SkCanvas canvas(bitmap); SkCanvas canvas(bitmap);
SkRect dest(SkRect::MakeWH(desired_size, desired_size)); canvas.drawBitmapRect(
canvas.drawBitmapRect(contents, NULL, dest); contents, NULL,
SkRect::MakeFromIRect(SkIRect::MakeWH(desired_size, desired_size)));
} }
return bitmap; return bitmap;
...@@ -224,7 +225,8 @@ gfx::ImageSkia CreateFaviconImageSkia( ...@@ -224,7 +225,8 @@ gfx::ImageSkia CreateFaviconImageSkia(
} else { } else {
for (std::vector<float>::const_iterator iter = favicon_scales.begin(); for (std::vector<float>::const_iterator iter = favicon_scales.begin();
iter != favicon_scales.end(); ++iter) { iter != favicon_scales.end(); ++iter) {
desired_sizes.push_back(ceil(desired_size_in_dip * (*iter))); desired_sizes.push_back(
static_cast<int>(ceil(desired_size_in_dip * (*iter))));
} }
} }
......
...@@ -208,7 +208,7 @@ class BrowserValidationDBProxy : public NaClValidationDB { ...@@ -208,7 +208,7 @@ class BrowserValidationDBProxy : public NaClValidationDB {
IPC::PlatformFileForTransitToPlatformFile(ipc_fd); IPC::PlatformFileForTransitToPlatformFile(ipc_fd);
#if defined(OS_WIN) #if defined(OS_WIN)
// On Windows, valid handles are 32 bit unsigned integers so this is safe. // On Windows, valid handles are 32 bit unsigned integers so this is safe.
*fd = reinterpret_cast<uintptr_t>(handle); *fd = reinterpret_cast<int32>(handle);
#else #else
*fd = handle; *fd = handle;
#endif #endif
......
...@@ -345,7 +345,7 @@ metrics::OmniboxInputType::Type AutocompleteInput::Parse( ...@@ -345,7 +345,7 @@ metrics::OmniboxInputType::Type AutocompleteInput::Parse(
// Trailing slashes force the input to be treated as a URL. // Trailing slashes force the input to be treated as a URL.
if (parts->path.is_nonempty()) { if (parts->path.is_nonempty()) {
char c = text[parts->path.end() - 1]; base::char16 c = text[parts->path.end() - 1];
if ((c == '\\') || (c == '/')) if ((c == '\\') || (c == '/'))
return metrics::OmniboxInputType::URL; return metrics::OmniboxInputType::URL;
} }
......
...@@ -100,7 +100,8 @@ void PrecacheDatabase::RecordURLPrecached(const GURL& url, ...@@ -100,7 +100,8 @@ void PrecacheDatabase::RecordURLPrecached(const GURL& url,
if (!was_cached) { if (!was_cached) {
// The precache only counts as overhead if it was downloaded over the // The precache only counts as overhead if it was downloaded over the
// network. // network.
UMA_HISTOGRAM_COUNTS("Precache.DownloadedPrecacheMotivated", size); UMA_HISTOGRAM_COUNTS("Precache.DownloadedPrecacheMotivated",
static_cast<base::HistogramBase::Sample>(size));
} }
// Use the URL table to keep track of URLs that are in the cache thanks to // Use the URL table to keep track of URLs that are in the cache thanks to
...@@ -133,21 +134,24 @@ void PrecacheDatabase::RecordURLFetched(const GURL& url, ...@@ -133,21 +134,24 @@ void PrecacheDatabase::RecordURLFetched(const GURL& url,
return; return;
} }
base::HistogramBase::Sample size_sample =
static_cast<base::HistogramBase::Sample>(size);
if (!was_cached) { if (!was_cached) {
// The fetch was served over the network during user browsing, so count it // The fetch was served over the network during user browsing, so count it
// as downloaded non-precache bytes. // as downloaded non-precache bytes.
UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache", size); UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache", size_sample);
if (is_connection_cellular) { if (is_connection_cellular) {
UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache.Cellular", size); UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache.Cellular",
size_sample);
} }
} else { } else {
// The fetch was served from the cache, and since there's an entry for this // The fetch was served from the cache, and since there's an entry for this
// URL in the URL table, this means that the resource was served from the // URL in the URL table, this means that the resource was served from the
// cache only because precaching put it there. Thus, precaching was helpful, // cache only because precaching put it there. Thus, precaching was helpful,
// so count the fetch as saved bytes. // so count the fetch as saved bytes.
UMA_HISTOGRAM_COUNTS("Precache.Saved", size); UMA_HISTOGRAM_COUNTS("Precache.Saved", size_sample);
if (is_connection_cellular) { if (is_connection_cellular) {
UMA_HISTOGRAM_COUNTS("Precache.Saved.Cellular", size); UMA_HISTOGRAM_COUNTS("Precache.Saved.Cellular", size_sample);
} }
} }
......
...@@ -62,7 +62,8 @@ bool GetMassStorageDeviceDetails(const base::FilePath& device_path, ...@@ -62,7 +62,8 @@ bool GetMassStorageDeviceDetails(const base::FilePath& device_path,
base::FilePath path(device_path); base::FilePath path(device_path);
if (device_path.value().length() > 3) if (device_path.value().length() > 3)
path = base::FilePath(device_path.value().substr(0, 3)); path = base::FilePath(device_path.value().substr(0, 3));
if (path.value()[0] < L'A' || path.value()[0] > L'Z') base::FilePath::CharType drive_letter = path.value()[0];
if (drive_letter < L'A' || drive_letter > L'Z')
return false; return false;
StorageInfo::Type type = StorageInfo::FIXED_MASS_STORAGE; StorageInfo::Type type = StorageInfo::FIXED_MASS_STORAGE;
...@@ -73,7 +74,7 @@ bool GetMassStorageDeviceDetails(const base::FilePath& device_path, ...@@ -73,7 +74,7 @@ bool GetMassStorageDeviceDetails(const base::FilePath& device_path,
} }
std::string unique_id = std::string unique_id =
"\\\\?\\Volume{00000000-0000-0000-0000-000000000000}\\"; "\\\\?\\Volume{00000000-0000-0000-0000-000000000000}\\";
unique_id[11] = device_path.value()[0]; unique_id[11] = static_cast<char>(drive_letter);
std::string device_id = StorageInfo::MakeDeviceId(type, unique_id); std::string device_id = StorageInfo::MakeDeviceId(type, unique_id);
base::string16 storage_label = path.Append(L" Drive").LossyDisplayName(); base::string16 storage_label = path.Append(L" Drive").LossyDisplayName();
*info = StorageInfo(device_id, path.value(), storage_label, base::string16(), *info = StorageInfo(device_id, path.value(), storage_label, base::string16(),
......
...@@ -343,7 +343,7 @@ base::FilePath VolumeMountWatcherWin::DriveNumberToFilePath(int drive_number) { ...@@ -343,7 +343,7 @@ base::FilePath VolumeMountWatcherWin::DriveNumberToFilePath(int drive_number) {
if (drive_number < 0 || drive_number > 25) if (drive_number < 0 || drive_number > 25)
return base::FilePath(); return base::FilePath();
base::string16 path(L"_:\\"); base::string16 path(L"_:\\");
path[0] = L'A' + drive_number; path[0] = static_cast<base::char16>('A' + drive_number);
return base::FilePath(path); return base::FilePath(path);
} }
......
...@@ -82,19 +82,22 @@ void ReportLanguageVerification(LanguageVerificationType type) { ...@@ -82,19 +82,22 @@ void ReportLanguageVerification(LanguageVerificationType type) {
void ReportTimeToBeReady(double time_in_msec) { void ReportTimeToBeReady(double time_in_msec) {
UMA_HISTOGRAM_MEDIUM_TIMES( UMA_HISTOGRAM_MEDIUM_TIMES(
kTranslateTimeToBeReady, kTranslateTimeToBeReady,
base::TimeDelta::FromMicroseconds(time_in_msec * 1000.0)); base::TimeDelta::FromMicroseconds(
static_cast<int64>(time_in_msec * 1000.0)));
} }
void ReportTimeToLoad(double time_in_msec) { void ReportTimeToLoad(double time_in_msec) {
UMA_HISTOGRAM_MEDIUM_TIMES( UMA_HISTOGRAM_MEDIUM_TIMES(
kTranslateTimeToLoad, kTranslateTimeToLoad,
base::TimeDelta::FromMicroseconds(time_in_msec * 1000.0)); base::TimeDelta::FromMicroseconds(
static_cast<int64>(time_in_msec * 1000.0)));
} }
void ReportTimeToTranslate(double time_in_msec) { void ReportTimeToTranslate(double time_in_msec) {
UMA_HISTOGRAM_MEDIUM_TIMES( UMA_HISTOGRAM_MEDIUM_TIMES(
kTranslateTimeToTranslate, kTranslateTimeToTranslate,
base::TimeDelta::FromMicroseconds(time_in_msec * 1000.0)); base::TimeDelta::FromMicroseconds(
static_cast<int64>(time_in_msec * 1000.0)));
} }
void ReportUserActionDuration(base::TimeTicks begin, base::TimeTicks end) { void ReportUserActionDuration(base::TimeTicks begin, base::TimeTicks end) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment