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(
// create a bitmap with given pixel size.
std::map<int, float> desired_pixel_sizes;
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];
}
......@@ -78,57 +79,58 @@ std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing(
return png_reps;
}
// Returns a resampled bitmap of
// |desired_size_in_pixel| x |desired_size_in_pixel| by resampling the best
// bitmap out of |input_bitmaps|. ResizeBitmapByDownsamplingIfPossible() is
// similar to SelectFaviconFrames() but it operates on bitmaps which have
// already been resampled via SelectFaviconFrames().
// Returns a resampled bitmap of |desired_size| x |desired_size| by resampling
// the best bitmap out of |input_bitmaps|.
// ResizeBitmapByDownsamplingIfPossible() is similar to SelectFaviconFrames()
// but it operates on bitmaps which have already been resampled via
// SelectFaviconFrames().
SkBitmap ResizeBitmapByDownsamplingIfPossible(
const std::vector<SkBitmap>& input_bitmaps,
int desired_size_in_pixel) {
int desired_size) {
DCHECK(!input_bitmaps.empty());
DCHECK_NE(desired_size_in_pixel, 0);
DCHECK_NE(0, desired_size);
SkBitmap best_bitmap;
for (size_t i = 0; i < input_bitmaps.size(); ++i) {
const SkBitmap& input_bitmap = input_bitmaps[i];
if (input_bitmap.width() == desired_size_in_pixel &&
input_bitmap.height() == desired_size_in_pixel) {
if (input_bitmap.width() == desired_size &&
input_bitmap.height() == desired_size) {
return input_bitmap;
} else if (best_bitmap.isNull()) {
best_bitmap = input_bitmap;
} else if (input_bitmap.width() >= best_bitmap.width() &&
input_bitmap.height() >= best_bitmap.height()) {
if (best_bitmap.width() < desired_size_in_pixel ||
best_bitmap.height() < desired_size_in_pixel) {
if (best_bitmap.width() < desired_size ||
best_bitmap.height() < desired_size) {
best_bitmap = input_bitmap;
}
} else {
if (input_bitmap.width() >= desired_size_in_pixel &&
input_bitmap.height() >= desired_size_in_pixel) {
if (input_bitmap.width() >= desired_size &&
input_bitmap.height() >= desired_size) {
best_bitmap = input_bitmap;
}
}
}
if (desired_size_in_pixel % best_bitmap.width() == 0 &&
desired_size_in_pixel % best_bitmap.height() == 0) {
if (desired_size % best_bitmap.width() == 0 &&
desired_size % best_bitmap.height() == 0) {
// Use nearest neighbour resampling if upsampling by an integer. This
// makes the result look similar to the result of SelectFaviconFrames().
SkBitmap bitmap;
bitmap.allocN32Pixels(desired_size_in_pixel, desired_size_in_pixel);
bitmap.allocN32Pixels(desired_size, desired_size);
if (!best_bitmap.isOpaque())
bitmap.eraseARGB(0, 0, 0, 0);
SkCanvas canvas(bitmap);
SkRect dest(SkRect::MakeWH(desired_size_in_pixel, desired_size_in_pixel));
canvas.drawBitmapRect(best_bitmap, NULL, dest);
canvas.drawBitmapRect(
best_bitmap, NULL,
SkRect::MakeFromIRect(SkIRect::MakeWH(desired_size, desired_size)));
return bitmap;
}
return skia::ImageOperations::Resize(best_bitmap,
skia::ImageOperations::RESIZE_LANCZOS3,
desired_size_in_pixel,
desired_size_in_pixel);
desired_size,
desired_size);
}
} // namespace
......@@ -214,7 +216,8 @@ gfx::Image SelectFaviconFramesFromPNGs(
gfx::ImageSkia resized_image_skia;
for (size_t i = 0; i < favicon_scales_to_generate.size(); ++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 =
ResizeBitmapByDownsamplingIfPossible(bitmaps, desired_size_in_pixel);
resized_image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale));
......
......@@ -41,8 +41,9 @@ SkBitmap SampleNearestNeighbor(const SkBitmap& contents, int desired_size) {
{
SkCanvas canvas(bitmap);
SkRect dest(SkRect::MakeWH(desired_size, desired_size));
canvas.drawBitmapRect(contents, NULL, dest);
canvas.drawBitmapRect(
contents, NULL,
SkRect::MakeFromIRect(SkIRect::MakeWH(desired_size, desired_size)));
}
return bitmap;
......@@ -224,7 +225,8 @@ gfx::ImageSkia CreateFaviconImageSkia(
} else {
for (std::vector<float>::const_iterator iter = favicon_scales.begin();
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 {
IPC::PlatformFileForTransitToPlatformFile(ipc_fd);
#if defined(OS_WIN)
// 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
*fd = handle;
#endif
......
......@@ -345,7 +345,7 @@ metrics::OmniboxInputType::Type AutocompleteInput::Parse(
// Trailing slashes force the input to be treated as a URL.
if (parts->path.is_nonempty()) {
char c = text[parts->path.end() - 1];
base::char16 c = text[parts->path.end() - 1];
if ((c == '\\') || (c == '/'))
return metrics::OmniboxInputType::URL;
}
......
......@@ -100,7 +100,8 @@ void PrecacheDatabase::RecordURLPrecached(const GURL& url,
if (!was_cached) {
// The precache only counts as overhead if it was downloaded over the
// 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
......@@ -133,21 +134,24 @@ void PrecacheDatabase::RecordURLFetched(const GURL& url,
return;
}
base::HistogramBase::Sample size_sample =
static_cast<base::HistogramBase::Sample>(size);
if (!was_cached) {
// The fetch was served over the network during user browsing, so count it
// as downloaded non-precache bytes.
UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache", size);
UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache", size_sample);
if (is_connection_cellular) {
UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache.Cellular", size);
UMA_HISTOGRAM_COUNTS("Precache.DownloadedNonPrecache.Cellular",
size_sample);
}
} else {
// 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
// cache only because precaching put it there. Thus, precaching was helpful,
// so count the fetch as saved bytes.
UMA_HISTOGRAM_COUNTS("Precache.Saved", size);
UMA_HISTOGRAM_COUNTS("Precache.Saved", size_sample);
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,
base::FilePath path(device_path);
if (device_path.value().length() > 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;
StorageInfo::Type type = StorageInfo::FIXED_MASS_STORAGE;
......@@ -73,7 +74,7 @@ bool GetMassStorageDeviceDetails(const base::FilePath& device_path,
}
std::string unique_id =
"\\\\?\\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);
base::string16 storage_label = path.Append(L" Drive").LossyDisplayName();
*info = StorageInfo(device_id, path.value(), storage_label, base::string16(),
......
......@@ -343,7 +343,7 @@ base::FilePath VolumeMountWatcherWin::DriveNumberToFilePath(int drive_number) {
if (drive_number < 0 || drive_number > 25)
return base::FilePath();
base::string16 path(L"_:\\");
path[0] = L'A' + drive_number;
path[0] = static_cast<base::char16>('A' + drive_number);
return base::FilePath(path);
}
......
......@@ -82,19 +82,22 @@ void ReportLanguageVerification(LanguageVerificationType type) {
void ReportTimeToBeReady(double time_in_msec) {
UMA_HISTOGRAM_MEDIUM_TIMES(
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) {
UMA_HISTOGRAM_MEDIUM_TIMES(
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) {
UMA_HISTOGRAM_MEDIUM_TIMES(
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) {
......
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