Cleanup code in printing/

- Use stdint.h types.
- Fix lint errors.

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

Cr-Commit-Position: refs/heads/master@{#348660}
diff --git a/printing/emf_win.cc b/printing/emf_win.cc
index b9dc9877..d5e1888 100644
--- a/printing/emf_win.cc
+++ b/printing/emf_win.cc
@@ -113,7 +113,6 @@
     RECT rect = bitmap_rect.ToRECT();
     ::FillRect(context_.Get(), &rect,
                static_cast<HBRUSH>(::GetStockObject(WHITE_BRUSH)));
-
   }
 
   ~RasterBitmap() {
@@ -139,7 +138,7 @@
 
 namespace printing {
 
-bool DIBFormatNativelySupported(HDC dc, uint32 escape, const BYTE* bits,
+bool DIBFormatNativelySupported(HDC dc, uint32_t escape, const BYTE* bits,
                                 int size) {
   BOOL supported = FALSE;
   if (ExtEscape(dc, QUERYESCSUPPORT, sizeof(escape),
@@ -185,7 +184,7 @@
   return hdc_ != NULL;
 }
 
-bool Emf::InitFromData(const void* src_buffer, uint32 src_buffer_size) {
+bool Emf::InitFromData(const void* src_buffer, uint32_t src_buffer_size) {
   DCHECK(!emf_ && !hdc_);
   emf_ = SetEnhMetaFileBits(src_buffer_size,
                             reinterpret_cast<const BYTE*>(src_buffer));
@@ -254,15 +253,15 @@
   return hdc_;
 }
 
-uint32 Emf::GetDataSize() const {
+uint32_t Emf::GetDataSize() const {
   DCHECK(emf_ && !hdc_);
   return GetEnhMetaFileBits(emf_, 0, NULL);
 }
 
-bool Emf::GetData(void* buffer, uint32 size) const {
+bool Emf::GetData(void* buffer, uint32_t size) const {
   DCHECK(emf_ && !hdc_);
   DCHECK(buffer && size);
-  uint32 size2 =
+  uint32_t size2 =
       GetEnhMetaFileBits(emf_, size, reinterpret_cast<BYTE*>(buffer));
   DCHECK(size2 == size);
   return size2 == size && size2 != 0;
@@ -530,7 +529,8 @@
     page_bounds = gfx::Rect(1, 1);
   }
 
-  float scale = sqrt(float(raster_area_in_pixels) / page_size.GetArea());
+  float scale = sqrt(
+      static_cast<float>(raster_area_in_pixels) / page_size.GetArea());
   page_size.set_width(std::max<int>(1, page_size.width() * scale));
   page_size.set_height(std::max<int>(1, page_size.height() * scale));
 
@@ -552,8 +552,10 @@
 
   ::ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
   XFORM xform = {
-    float(page_bounds.width()) / bitmap_rect.width(), 0,
-    0, float(page_bounds.height()) / bitmap_rect.height(),
+    static_cast<float>(page_bounds.width()) / bitmap_rect.width(),
+    0,
+    0,
+    static_cast<float>(page_bounds.height()) / bitmap_rect.height(),
     static_cast<float>(page_bounds.x()),
     static_cast<float>(page_bounds.y()),
   };
diff --git a/printing/emf_win.h b/printing/emf_win.h
index dcdfd8c..359d4b3e2 100644
--- a/printing/emf_win.h
+++ b/printing/emf_win.h
@@ -56,7 +56,7 @@
   // Metafile methods.
   bool Init() override;
   bool InitFromData(const void* src_buffer,
-                    uint32 src_buffer_size) override;
+                    uint32_t src_buffer_size) override;
 
   // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls
   // (since StartPage and EndPage do not work in a metafile DC). Only valid
@@ -68,8 +68,8 @@
   bool FinishPage() override;
   bool FinishDocument() override;
 
-  uint32 GetDataSize() const override;
-  bool GetData(void* buffer, uint32 size) const override;
+  uint32_t GetDataSize() const override;
+  bool GetData(void* buffer, uint32_t size) const override;
 
   // Should be passed to Playback to keep the exact same size.
   gfx::Rect GetPageBounds(unsigned int page_number) const override;
diff --git a/printing/emf_win_unittest.cc b/printing/emf_win_unittest.cc
index 0f20586..f6ea72a 100644
--- a/printing/emf_win_unittest.cc
+++ b/printing/emf_win_unittest.cc
@@ -45,13 +45,14 @@
   std::string GetAppLocale() override { return std::string(); }
 };
 
-const uint32 EMF_HEADER_SIZE = 128;
+const uint32_t EMF_HEADER_SIZE = 128;
+const int ONE_MB = 1024 * 1024;
 
 }  // namespace
 
 TEST(EmfTest, DC) {
   // Simplest use case.
-  uint32 size;
+  uint32_t size;
   std::vector<char> data;
   {
     Emf emf;
@@ -133,7 +134,7 @@
       CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL));
   if (!dc.Get())
     return;
-  uint32 size;
+  uint32_t size;
   std::vector<char> data;
   {
     Emf emf;
@@ -178,7 +179,7 @@
   base::FilePath metafile_path;
   EXPECT_TRUE(base::CreateTemporaryFileInDir(scratch_metafile_dir.path(),
                                              &metafile_path));
-  uint32 size;
+  uint32_t size;
   std::vector<char> data;
   {
     Emf emf;
@@ -192,7 +193,7 @@
     EXPECT_TRUE(emf.GetDataAsVector(&data));
     EXPECT_EQ(data.size(), size);
   }
-  int64 file_size = 0;
+  int64_t file_size = 0;
   base::GetFileSize(metafile_path, &file_size);
   EXPECT_EQ(size, file_size);
 
@@ -224,9 +225,9 @@
   raster = emf.RasterizeMetafile(20);
   EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1));
 
-  raster = emf.RasterizeMetafile(16 * 1024 * 1024);
+  raster = emf.RasterizeMetafile(16 * ONE_MB);
   // Expected size about 64MB.
-  EXPECT_LE(abs(int(raster->GetDataSize()) - 64 * 1024 * 1024), 1024 * 1024);
+  EXPECT_LE(abs(static_cast<int>(raster->GetDataSize()) - 64 * ONE_MB), ONE_MB);
   // Bounds should still be the same.
   EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1));
 }
diff --git a/printing/image.cc b/printing/image.cc
index cb47769..23f988a8 100644
--- a/printing/image.cc
+++ b/printing/image.cc
@@ -91,22 +91,22 @@
   int pixels_different = 0;
   for (int y = 0; y < height; ++y) {
     for (int x = 0; x < width; ++x) {
-      uint32 lhs_pixel = pixel_at(x, y);
-      uint32 rhs_pixel = rhs.pixel_at(x, y);
+      uint32_t lhs_pixel = pixel_at(x, y);
+      uint32_t rhs_pixel = rhs.pixel_at(x, y);
       if (lhs_pixel != rhs_pixel)
         ++pixels_different;
     }
 
     // Look for extra right lhs pixels. They should be white.
     for (int x = width; x < size_.width(); ++x) {
-      uint32 lhs_pixel = pixel_at(x, y);
+      uint32_t lhs_pixel = pixel_at(x, y);
       if (lhs_pixel != Color(SK_ColorWHITE))
         ++pixels_different;
     }
 
     // Look for extra right rhs pixels. They should be white.
     for (int x = width; x < rhs.size_.width(); ++x) {
-      uint32 rhs_pixel = rhs.pixel_at(x, y);
+      uint32_t rhs_pixel = rhs.pixel_at(x, y);
       if (rhs_pixel != Color(SK_ColorWHITE))
         ++pixels_different;
     }
@@ -115,7 +115,7 @@
   // Look for extra bottom lhs pixels. They should be white.
   for (int y = height; y < size_.height(); ++y) {
     for (int x = 0; x < size_.width(); ++x) {
-      uint32 lhs_pixel = pixel_at(x, y);
+      uint32_t lhs_pixel = pixel_at(x, y);
       if (lhs_pixel != Color(SK_ColorWHITE))
         ++pixels_different;
     }
@@ -124,7 +124,7 @@
   // Look for extra bottom rhs pixels. They should be white.
   for (int y = height; y < rhs.size_.height(); ++y) {
     for (int x = 0; x < rhs.size_.width(); ++x) {
-      uint32 rhs_pixel = rhs.pixel_at(x, y);
+      uint32_t rhs_pixel = rhs.pixel_at(x, y);
       if (rhs_pixel != Color(SK_ColorWHITE))
         ++pixels_different;
     }
@@ -144,7 +144,7 @@
       reinterpret_cast<const unsigned char*>(compressed.c_str()),
       compressed.size(), gfx::PNGCodec::FORMAT_BGRA, &data_, &w, &h);
   size_.SetSize(w, h);
-  row_length_ = size_.width() * sizeof(uint32);
+  row_length_ = size_.width() * sizeof(uint32_t);
   return success;
 }
 
@@ -152,7 +152,7 @@
   DCHECK(!data.empty());
   PdfMetafileSkia metafile;
   if (!metafile.InitFromData(data.data(),
-                             base::checked_cast<uint32>(data.size())))
+                             base::checked_cast<uint32_t>(data.size())))
     return false;
   return LoadMetafile(metafile);
 }
diff --git a/printing/image.h b/printing/image.h
index c5a609e..1406a85 100644
--- a/printing/image.h
+++ b/printing/image.h
@@ -53,18 +53,18 @@
   double PercentageDifferent(const Image& rhs) const;
 
   // Returns the 0x0RGB or 0xARGB value of the pixel at the given location.
-  uint32 Color(uint32 color) const {
+  uint32_t Color(uint32_t color) const {
     if (ignore_alpha_)
       return color & 0xFFFFFF;  // Strip out A.
     else
       return color;
   }
 
-  uint32 pixel_at(int x, int y) const {
+  uint32_t pixel_at(int x, int y) const {
     DCHECK(x >= 0 && x < size_.width());
     DCHECK(y >= 0 && y < size_.height());
-    const uint32* data = reinterpret_cast<const uint32*>(&*data_.begin());
-    const uint32* data_row = data + y * row_length_ / sizeof(uint32);
+    const uint32_t* data = reinterpret_cast<const uint32_t*>(&*data_.begin());
+    const uint32_t* data_row = data + y * row_length_ / sizeof(uint32_t);
     return Color(data_row[x]);
   }
 
@@ -85,7 +85,7 @@
   // Length of a line in bytes.
   int row_length_;
 
-  // Actual bitmap data in arrays of RGBAs (so when loaded as uint32, it's
+  // Actual bitmap data in arrays of RGBAs (so when loaded as uint32_t, it's
   // 0xABGR).
   std::vector<unsigned char> data_;
 
diff --git a/printing/image_mac.cc b/printing/image_mac.cc
index 55f61f8..864a150 100644
--- a/printing/image_mac.cc
+++ b/printing/image_mac.cc
@@ -20,7 +20,7 @@
     return false;
 
   size_ = rect.size();
-  row_length_ = size_.width() * sizeof(uint32);
+  row_length_ = size_.width() * sizeof(uint32_t);
   size_t bytes = row_length_ * size_.height();
   DCHECK(bytes);
 
diff --git a/printing/image_win.cc b/printing/image_win.cc
index 866625c..1411e16 100644
--- a/printing/image_win.cc
+++ b/printing/image_win.cc
@@ -23,7 +23,7 @@
 // destructor.
 class DisableFontSmoothing {
  public:
-  explicit DisableFontSmoothing() : enable_again_(false) {
+  DisableFontSmoothing() : enable_again_(false) {
     BOOL enabled;
     if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &enabled, 0) &&
         enabled) {
@@ -77,7 +77,7 @@
 
   bool success = metafile.Playback(hdc.Get(), NULL);
 
-  row_length_ = size_.width() * sizeof(uint32);
+  row_length_ = size_.width() * sizeof(uint32_t);
   size_t bytes = row_length_ * size_.height();
   DCHECK(bytes);
 
diff --git a/printing/metafile.cc b/printing/metafile.cc
index ece61df..33c84f4 100644
--- a/printing/metafile.cc
+++ b/printing/metafile.cc
@@ -27,7 +27,8 @@
   buffer->resize(GetDataSize());
   if (buffer->empty())
     return false;
-  return GetData(&buffer->front(), base::checked_cast<uint32>(buffer->size()));
+  return GetData(&buffer->front(),
+                 base::checked_cast<uint32_t>(buffer->size()));
 }
 
 bool Metafile::SaveTo(base::File* file) const {
diff --git a/printing/metafile.h b/printing/metafile.h
index 33ed54d..fb40aae 100644
--- a/printing/metafile.h
+++ b/printing/metafile.h
@@ -107,7 +107,8 @@
   // Initializes the metafile with the data in |src_buffer|. Returns true
   // on success.
   // Note: It should only be called from within the browser process.
-  virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size) = 0;
+  virtual bool InitFromData(const void* src_buffer,
+                            uint32_t src_buffer_size) = 0;
 
   // Prepares a context for rendering a new page with the given |page_size|,
   // |content_area| and  a |scale_factor| to use for the drawing. The units are
@@ -127,12 +128,12 @@
 
   // Returns the size of the underlying data stream. Only valid after Close()
   // has been called.
-  virtual uint32 GetDataSize() const = 0;
+  virtual uint32_t GetDataSize() const = 0;
 
   // Copies the first |dst_buffer_size| bytes of the underlying data stream into
   // |dst_buffer|. This function should ONLY be called after Close() is invoked.
   // Returns true if the copy succeeds.
-  virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const = 0;
+  virtual bool GetData(void* dst_buffer, uint32_t dst_buffer_size) const = 0;
 
   virtual gfx::Rect GetPageBounds(unsigned int page_number) const = 0;
   virtual unsigned int GetPageCount() const = 0;
diff --git a/printing/pdf_metafile_cg_mac.cc b/printing/pdf_metafile_cg_mac.cc
index d9d97c8..016e28a 100644
--- a/printing/pdf_metafile_cg_mac.cc
+++ b/printing/pdf_metafile_cg_mac.cc
@@ -70,7 +70,7 @@
     default:
       NOTREACHED();
       break;
-  };
+  }
 }
 
 }  // namespace
@@ -128,7 +128,7 @@
 }
 
 bool PdfMetafileCg::InitFromData(const void* src_buffer,
-                                 uint32 src_buffer_size) {
+                                 uint32_t src_buffer_size) {
   DCHECK(!context_.get());
   DCHECK(!pdf_data_.get());
 
@@ -295,23 +295,23 @@
   return gfx::Rect(page_rect);
 }
 
-uint32 PdfMetafileCg::GetDataSize() const {
+uint32_t PdfMetafileCg::GetDataSize() const {
   // PDF data is only valid/complete once the context is released.
   DCHECK(!context_);
 
   if (!pdf_data_)
     return 0;
-  return static_cast<uint32>(CFDataGetLength(pdf_data_));
+  return static_cast<uint32_t>(CFDataGetLength(pdf_data_));
 }
 
-bool PdfMetafileCg::GetData(void* dst_buffer, uint32 dst_buffer_size) const {
+bool PdfMetafileCg::GetData(void* dst_buffer, uint32_t dst_buffer_size) const {
   // PDF data is only valid/complete once the context is released.
   DCHECK(!context_);
   DCHECK(pdf_data_);
   DCHECK(dst_buffer);
   DCHECK_GT(dst_buffer_size, 0U);
 
-  uint32 data_size = GetDataSize();
+  uint32_t data_size = GetDataSize();
   if (dst_buffer_size > data_size) {
     return false;
   }
diff --git a/printing/pdf_metafile_cg_mac.h b/printing/pdf_metafile_cg_mac.h
index 26aed5c..4710879 100644
--- a/printing/pdf_metafile_cg_mac.h
+++ b/printing/pdf_metafile_cg_mac.h
@@ -33,7 +33,7 @@
 
   // Metafile methods.
   bool Init() override;
-  bool InitFromData(const void* src_buffer, uint32 src_buffer_size) override;
+  bool InitFromData(const void* src_buffer, uint32_t src_buffer_size) override;
 
   // Not implemented on mac.
   bool StartPage(const gfx::Size& page_size,
@@ -42,8 +42,8 @@
   bool FinishPage() override;
   bool FinishDocument() override;
 
-  uint32 GetDataSize() const override;
-  bool GetData(void* dst_buffer, uint32 dst_buffer_size) const override;
+  uint32_t GetDataSize() const override;
+  bool GetData(void* dst_buffer, uint32_t dst_buffer_size) const override;
 
   gfx::Rect GetPageBounds(unsigned int page_number) const override;
   unsigned int GetPageCount() const override;
diff --git a/printing/pdf_metafile_cg_mac_unittest.cc b/printing/pdf_metafile_cg_mac_unittest.cc
index dca7ea8fe..2a17227 100644
--- a/printing/pdf_metafile_cg_mac_unittest.cc
+++ b/printing/pdf_metafile_cg_mac_unittest.cc
@@ -35,7 +35,7 @@
   pdf.FinishDocument();
 
   // Check data size.
-  uint32 size = pdf.GetDataSize();
+  uint32_t size = pdf.GetDataSize();
   EXPECT_GT(size, 0U);
 
   // Get resulting data.
diff --git a/printing/pdf_metafile_skia.cc b/printing/pdf_metafile_skia.cc
index 1fb35576..78bcaec5 100644
--- a/printing/pdf_metafile_skia.cc
+++ b/printing/pdf_metafile_skia.cc
@@ -84,7 +84,7 @@
 // Metafile::InitFromData is orthogonal to what the rest of
 // PdfMetafileSkia does.
 bool PdfMetafileSkia::InitFromData(const void* src_buffer,
-                                   uint32 src_buffer_size) {
+                                   uint32_t src_buffer_size) {
   data_->pdf_data_.reset(new SkMemoryStream(src_buffer, src_buffer_size, true));
   return true;
 }
@@ -153,14 +153,14 @@
   return true;
 }
 
-uint32 PdfMetafileSkia::GetDataSize() const {
+uint32_t PdfMetafileSkia::GetDataSize() const {
   if (!data_->pdf_data_)
     return 0;
-  return base::checked_cast<uint32>(data_->pdf_data_->getLength());
+  return base::checked_cast<uint32_t>(data_->pdf_data_->getLength());
 }
 
 bool PdfMetafileSkia::GetData(void* dst_buffer,
-                              uint32 dst_buffer_size) const {
+                              uint32_t dst_buffer_size) const {
   if (!data_->pdf_data_)
     return false;
   return WriteAssetToBuffer(data_->pdf_data_.get(), dst_buffer,
@@ -215,7 +215,8 @@
     size_t length = data_->pdf_data_->getLength();
     std::vector<uint8_t> buffer(length);
     (void)WriteAssetToBuffer(data_->pdf_data_.get(), &buffer[0], length);
-    data_->pdf_cg_.InitFromData(&buffer[0], base::checked_cast<uint32>(length));
+    data_->pdf_cg_.InitFromData(&buffer[0],
+                                base::checked_cast<uint32_t>(length));
   }
   return data_->pdf_cg_.RenderPage(page_number, context, rect, params);
 }
diff --git a/printing/pdf_metafile_skia.h b/printing/pdf_metafile_skia.h
index cab518a..6bc1220 100644
--- a/printing/pdf_metafile_skia.h
+++ b/printing/pdf_metafile_skia.h
@@ -36,7 +36,7 @@
 
   // Metafile methods.
   bool Init() override;
-  bool InitFromData(const void* src_buffer, uint32 src_buffer_size) override;
+  bool InitFromData(const void* src_buffer, uint32_t src_buffer_size) override;
 
   bool StartPage(const gfx::Size& page_size,
                  const gfx::Rect& content_area,
@@ -44,8 +44,8 @@
   bool FinishPage() override;
   bool FinishDocument() override;
 
-  uint32 GetDataSize() const override;
-  bool GetData(void* dst_buffer, uint32 dst_buffer_size) const override;
+  uint32_t GetDataSize() const override;
+  bool GetData(void* dst_buffer, uint32_t dst_buffer_size) const override;
 
   gfx::Rect GetPageBounds(unsigned int page_number) const override;
   unsigned int GetPageCount() const override;
diff --git a/printing/print_settings_initializer_mac.cc b/printing/print_settings_initializer_mac.cc
index 7dc41a6..926d6988 100644
--- a/printing/print_settings_initializer_mac.cc
+++ b/printing/print_settings_initializer_mac.cc
@@ -28,7 +28,7 @@
                                                        &resolution_count);
   if (status == noErr) {
     // Resolution indexes are 1-based.
-    for (uint32 i = 1; i <= resolution_count; ++i) {
+    for (uint32_t i = 1; i <= resolution_count; ++i) {
       PMResolution resolution;
       PMPrinterGetIndexedPrinterResolution(printer, i, &resolution);
       if (resolution.hRes > best_resolution.hRes)