Browse Source

Merge pull request #9076 from electron/cleanup-cpp

Cleanup cpp codebase
Kevin Sawicki 8 years ago
parent
commit
f5a75c4e87

+ 1 - 1
atom/app/atom_content_client.cc

@@ -44,7 +44,7 @@ content::PepperPluginInfo CreatePepperFlashInfo(const base::FilePath& path,
 
   std::vector<std::string> flash_version_numbers = base::SplitString(
       version, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
-  if (flash_version_numbers.size() < 1)
+  if (flash_version_numbers.empty())
     flash_version_numbers.push_back("11");
   // |SplitString()| puts in an empty string given an empty string. :(
   else if (flash_version_numbers[0].empty())

+ 4 - 4
atom/browser/api/atom_api_app.cc

@@ -427,7 +427,7 @@ void OnClientCertificateSelected(
 
   auto certs = net::X509Certificate::CreateCertificateListFromBytes(
       data.c_str(), data.length(), net::X509Certificate::FORMAT_AUTO);
-  if (certs.size() > 0)
+  if (!certs.empty())
     delegate->ContinueWithCertificate(certs[0].get());
 }
 
@@ -520,7 +520,7 @@ void App::OnQuit() {
   int exitCode = AtomBrowserMainParts::Get()->GetExitCode();
   Emit("quit", exitCode);
 
-  if (process_singleton_.get()) {
+  if (process_singleton_) {
     process_singleton_->Cleanup();
     process_singleton_.reset();
   }
@@ -695,7 +695,7 @@ std::string App::GetLocale() {
 
 bool App::MakeSingleInstance(
     const ProcessSingleton::NotificationCallback& callback) {
-  if (process_singleton_.get())
+  if (process_singleton_)
     return false;
 
   base::FilePath user_dir;
@@ -716,7 +716,7 @@ bool App::MakeSingleInstance(
 }
 
 void App::ReleaseSingleInstance() {
-  if (process_singleton_.get()) {
+  if (process_singleton_) {
     process_singleton_->Cleanup();
     process_singleton_.reset();
   }

+ 1 - 1
atom/browser/api/atom_api_auto_updater.cc

@@ -88,7 +88,7 @@ void AutoUpdater::SetFeedURL(const std::string& url, mate::Arguments* args) {
 void AutoUpdater::QuitAndInstall() {
   // If we don't have any window then quitAndInstall immediately.
   WindowList* window_list = WindowList::GetInstance();
-  if (window_list->size() == 0) {
+  if (window_list->empty()) {
     auto_updater::AutoUpdater::QuitAndInstall();
     return;
   }

+ 7 - 6
atom/browser/api/atom_api_dialog.cc

@@ -78,13 +78,14 @@ void ShowMessageBox(int type,
   if (mate::Converter<atom::MessageBoxCallback>::FromV8(args->isolate(),
                                                         peek,
                                                         &callback)) {
-    atom::ShowMessageBox(window, (atom::MessageBoxType)type, buttons,
-                         default_id, cancel_id, options, title, message, detail,
-                         checkbox_label, checkbox_checked, icon, callback);
+    atom::ShowMessageBox(window, static_cast<atom::MessageBoxType>(type),
+                         buttons, default_id, cancel_id, options, title,
+                         message, detail, checkbox_label, checkbox_checked,
+                         icon, callback);
   } else {
-    int chosen = atom::ShowMessageBox(window, (atom::MessageBoxType)type,
-                                      buttons, default_id, cancel_id,
-                                      options, title, message, detail, icon);
+    int chosen = atom::ShowMessageBox(
+        window, static_cast<atom::MessageBoxType>(type), buttons, default_id,
+        cancel_id, options, title, message, detail, icon);
     args->Return(chosen);
   }
 }

+ 1 - 1
atom/browser/api/atom_api_session.cc

@@ -233,7 +233,7 @@ class ResolveProxyHelper {
  public:
   ResolveProxyHelper(AtomBrowserContext* browser_context,
                      const GURL& url,
-                     Session::ResolveProxyCallback callback)
+                     const Session::ResolveProxyCallback& callback)
       : callback_(callback),
         original_thread_(base::ThreadTaskRunnerHandle::Get()) {
     scoped_refptr<net::URLRequestContextGetter> context_getter =

+ 1 - 1
atom/browser/api/atom_api_web_contents.cc

@@ -240,7 +240,7 @@ content::ServiceWorkerContext* GetServiceWorkerContext(
 }
 
 // Called when CapturePage is done.
-void OnCapturePageDone(base::Callback<void(const gfx::Image&)> callback,
+void OnCapturePageDone(const base::Callback<void(const gfx::Image&)>& callback,
                        const SkBitmap& bitmap,
                        content::ReadbackResponse response) {
   callback.Run(gfx::Image::CreateFrom1xBitmap(bitmap));

+ 1 - 1
atom/browser/auto_updater_mac.mm

@@ -27,7 +27,7 @@ namespace {
 bool g_update_available = false;
 std::string update_url_ = "";
 
-}
+} // namespace
 
 std::string AutoUpdater::GetFeedURL() {
   return update_url_;

+ 2 - 2
atom/browser/browser.cc

@@ -44,7 +44,7 @@ void Browser::Quit() {
     return;
 
   atom::WindowList* window_list = atom::WindowList::GetInstance();
-  if (window_list->size() == 0)
+  if (window_list->empty())
     NotifyAndShutdown();
 
   window_list->CloseAllWindows();
@@ -66,7 +66,7 @@ void Browser::Exit(mate::Arguments* args) {
 
     // Must destroy windows before quitting, otherwise bad things can happen.
     atom::WindowList* window_list = atom::WindowList::GetInstance();
-    if (window_list->size() == 0) {
+    if (window_list->empty()) {
       Shutdown();
     } else {
       // Unlike Quit(), we do not ask to close window, but destroy the window

+ 1 - 1
atom/browser/browser.h

@@ -102,7 +102,7 @@ class Browser : public WindowListObserver {
     std::vector<base::string16> args;
   };
   void SetLoginItemSettings(LoginItemSettings settings);
-  LoginItemSettings GetLoginItemSettings(LoginItemSettings options);
+  LoginItemSettings GetLoginItemSettings(const LoginItemSettings& options);
 
 #if defined(OS_MACOSX)
   // Hide the application.

+ 1 - 1
atom/browser/browser_linux.cc

@@ -64,7 +64,7 @@ void Browser::SetLoginItemSettings(LoginItemSettings settings) {
 }
 
 Browser::LoginItemSettings Browser::GetLoginItemSettings(
-    LoginItemSettings options) {
+    const LoginItemSettings& options) {
   return LoginItemSettings();
 }
 

+ 5 - 4
atom/browser/browser_mac.mm

@@ -64,8 +64,9 @@ bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
   // On macOS, we can't query the default, but the handlers list seems to put
   // Apple's defaults first, so we'll use the first option that isn't our bundle
   CFStringRef other = nil;
-  for (CFIndex i = 0; i < CFArrayGetCount(bundleList); i++) {
-    other = (CFStringRef)CFArrayGetValueAtIndex(bundleList, i);
+  for (CFIndex i = 0; i < CFArrayGetCount(bundleList); ++i) {
+    other = base::mac::CFCast<CFStringRef>(CFArrayGetValueAtIndex(bundleList,
+                                                                  i));
     if (![identifier isEqualToString: (__bridge NSString *)other]) {
       break;
     }
@@ -152,7 +153,7 @@ bool Browser::ContinueUserActivity(const std::string& type,
 }
 
 Browser::LoginItemSettings Browser::GetLoginItemSettings(
-    LoginItemSettings options) {
+    const LoginItemSettings& options) {
   LoginItemSettings settings;
   settings.open_at_login = base::mac::CheckLoginItemStatus(
       &settings.open_as_hidden);
@@ -179,7 +180,7 @@ std::string Browser::GetExecutableFileProductName() const {
 
 int Browser::DockBounce(BounceType type) {
   return [[AtomApplication sharedApplication]
-      requestUserAttention:(NSRequestUserAttentionType)type];
+      requestUserAttention:static_cast<NSRequestUserAttentionType>(type)];
 }
 
 void Browser::DockCancelBounce(int request_id) {

+ 1 - 1
atom/browser/browser_win.cc

@@ -287,7 +287,7 @@ void Browser::SetLoginItemSettings(LoginItemSettings settings) {
 }
 
 Browser::LoginItemSettings Browser::GetLoginItemSettings(
-    LoginItemSettings options) {
+    const LoginItemSettings& options) {
   LoginItemSettings settings;
   base::string16 keyPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
   base::win::RegKey key(HKEY_CURRENT_USER, keyPath.c_str(), KEY_ALL_ACCESS);

+ 1 - 1
atom/browser/common_web_contents_delegate.cc

@@ -338,7 +338,7 @@ void CommonWebContentsDelegate::DevToolsRequestFileSystems() {
   }
 
   std::vector<FileSystem> file_systems;
-  for (auto file_system_path : file_system_paths) {
+  for (const auto& file_system_path : file_system_paths) {
     base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system_path);
     std::string file_system_id = RegisterFileSystem(GetDevToolsWebContents(),
                                                     path);

+ 7 - 7
atom/browser/native_window_mac.mm

@@ -1290,7 +1290,7 @@ void NativeWindowMac::SetProgressBar(double progress, const NativeWindow::Progre
   NSDockTile* dock_tile = [NSApp dockTile];
 
   // For the first time API invoked, we need to create a ContentView in DockTile.
-  if (dock_tile.contentView == NULL) {
+  if (dock_tile.contentView == nullptr) {
     NSImageView* image_view = [[NSImageView alloc] init];
     [image_view setImage:[NSApp applicationIconImage]];
     [dock_tile setContentView:image_view];
@@ -1386,22 +1386,22 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
     // they are available in the minimum SDK version
     if (type == "selection") {
       // NSVisualEffectMaterialSelection
-      vibrancyType = (NSVisualEffectMaterial) 4;
+      vibrancyType = static_cast<NSVisualEffectMaterial>(4);
     } else if (type == "menu") {
       // NSVisualEffectMaterialMenu
-      vibrancyType = (NSVisualEffectMaterial) 5;
+      vibrancyType = static_cast<NSVisualEffectMaterial>(5);
     } else if (type == "popover") {
       // NSVisualEffectMaterialPopover
-      vibrancyType = (NSVisualEffectMaterial) 6;
+      vibrancyType = static_cast<NSVisualEffectMaterial>(6);
     } else if (type == "sidebar") {
       // NSVisualEffectMaterialSidebar
-      vibrancyType = (NSVisualEffectMaterial) 7;
+      vibrancyType = static_cast<NSVisualEffectMaterial>(7);
     } else if (type == "medium-light") {
       // NSVisualEffectMaterialMediumLight
-      vibrancyType = (NSVisualEffectMaterial) 8;
+      vibrancyType = static_cast<NSVisualEffectMaterial>(8);
     } else if (type == "ultra-dark") {
       // NSVisualEffectMaterialUltraDark
-      vibrancyType = (NSVisualEffectMaterial) 9;
+      vibrancyType = static_cast<NSVisualEffectMaterial>(9);
     }
   }
 

+ 1 - 1
atom/browser/net/atom_cert_verifier.cc

@@ -50,7 +50,7 @@ class CertVerifierRequest : public AtomCertVerifier::Request {
         first_response_(true),
         weak_ptr_factory_(this) {}
 
-  ~CertVerifierRequest() {
+  ~CertVerifierRequest() override {
     cert_verifier_->RemoveRequest(params_);
     default_verifier_request_.reset();
     while (!response_list_.empty() && !first_response_) {

+ 1 - 1
atom/browser/net/atom_network_delegate.cc

@@ -402,7 +402,7 @@ void AtomNetworkDelegate::OnListenerResultInIO(
   if (!base::ContainsKey(callbacks_, id))
     return;
 
-  ReadFromResponseObject(*response.get(), out);
+  ReadFromResponseObject(*response, out);
 
   bool cancel = false;
   response->GetBoolean("cancel", &cancel);

+ 1 - 1
atom/browser/node_debugger.cc

@@ -164,7 +164,7 @@ void NodeDebugger::DidRead(net::test_server::StreamListenSocket* socket,
   buffer_.append(data, len);
 
   do {
-    if (buffer_.size() == 0)
+    if (buffer_.empty())
       return;
 
     // Read the "Content-Length" header.

+ 3 - 3
atom/browser/osr/osr_render_widget_host_view.cc

@@ -851,12 +851,12 @@ void OffScreenRenderWidgetHostView::SetupFrameRate(bool force) {
   GetCompositor()->vsync_manager()->SetAuthoritativeVSyncInterval(
       base::TimeDelta::FromMilliseconds(frame_rate_threshold_ms_));
 
-  if (copy_frame_generator_.get()) {
+  if (copy_frame_generator_) {
     copy_frame_generator_->set_frame_rate_threshold_ms(
         frame_rate_threshold_ms_);
   }
 
-  if (begin_frame_timer_.get()) {
+  if (begin_frame_timer_) {
     begin_frame_timer_->SetFrameRateThresholdMs(frame_rate_threshold_ms_);
   } else {
     begin_frame_timer_.reset(new AtomBeginFrameTimer(
@@ -871,7 +871,7 @@ void OffScreenRenderWidgetHostView::Invalidate() {
 
   if (software_output_device_) {
     software_output_device_->OnPaint(bounds_in_pixels);
-  } else if (copy_frame_generator_.get()) {
+  } else if (copy_frame_generator_) {
     copy_frame_generator_->GenerateCopyFrame(true, bounds_in_pixels);
   }
 }

+ 1 - 1
atom/browser/osr/osr_render_widget_host_view_mac.mm

@@ -145,4 +145,4 @@ OffScreenRenderWidgetHostView::GetDelegatedFrameHost() const {
   return browser_compositor_->GetDelegatedFrameHost();
 }
 
-}   // namespace
+} // namespace atom

+ 1 - 1
atom/browser/ui/cocoa/atom_menu_controller.mm

@@ -70,7 +70,7 @@ Role kRolesMap[] = {
   // while its context menu is still open.
   [self cancel];
 
-  model_ = NULL;
+  model_ = nullptr;
   [super dealloc];
 }
 

+ 4 - 4
atom/browser/ui/cocoa/atom_touch_bar.mm

@@ -319,7 +319,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
 - (void)updateColorPicker:(NSColorPickerTouchBarItem*)item
              withSettings:(const mate::PersistentDictionary&)settings {
   std::vector<std::string> colors;
-  if (settings.Get("availableColors", &colors) && colors.size() > 0) {
+  if (settings.Get("availableColors", &colors) && !colors.empty()) {
     NSColorList* color_list  = [[[NSColorList alloc] initWithName:@""] autorelease];
     for (size_t i = 0; i < colors.size(); ++i) {
       [color_list insertColor:[self colorFromHexColorString:colors[i]]
@@ -414,7 +414,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
 
   NSMutableArray* generatedItems = [NSMutableArray array];
   NSMutableArray* identifiers = [self identifiersFromSettings:items];
-  for (NSUInteger i = 0; i < [identifiers count]; i++) {
+  for (NSUInteger i = 0; i < [identifiers count]; ++i) {
     if ([identifiers objectAtIndex:i] != NSTouchBarItemIdentifierOtherItemsProxy) {
       NSTouchBarItem* generatedItem = [self makeItemForIdentifier:[identifiers objectAtIndex:i]];
       if (generatedItem) {
@@ -474,7 +474,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
   settings.Get("segments", &segments);
 
   control.segmentCount = segments.size();
-  for (int i = 0; i < (int)segments.size(); i++) {
+  for (size_t i = 0; i < segments.size(); ++i) {
     std::string label;
     gfx::Image image;
     bool enabled = true;
@@ -581,7 +581,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
   std::vector<mate::PersistentDictionary> items;
   if (!settings.Get("items", &items)) return nil;
 
-  if (index >= (long)items.size()) return nil;
+  if (index >= static_cast<NSInteger>(items.size())) return nil;
 
   mate::PersistentDictionary item = items[index];
 

+ 2 - 2
atom/browser/ui/file_dialog_mac.mm

@@ -154,7 +154,7 @@ void ShowOpenDialog(const DialogSettings& settings,
 
   NSWindow* window = settings.parent_window ?
       settings.parent_window->GetNativeWindow() :
-      NULL;
+      nullptr;
   [dialog beginSheetModalForWindow:window
                  completionHandler:^(NSInteger chosen) {
     if (chosen == NSFileHandlingPanelCancelButton) {
@@ -193,7 +193,7 @@ void ShowSaveDialog(const DialogSettings& settings,
 
   NSWindow* window = settings.parent_window ?
     settings.parent_window->GetNativeWindow() :
-    NULL;
+    nullptr;
   [dialog beginSheetModalForWindow:window
                  completionHandler:^(NSInteger chosen) {
     if (chosen == NSFileHandlingPanelCancelButton) {

+ 9 - 8
atom/browser/web_contents_permission_helper.cc

@@ -66,8 +66,9 @@ void WebContentsPermissionHelper::RequestPermission(
 
 void WebContentsPermissionHelper::RequestFullscreenPermission(
     const base::Callback<void(bool)>& callback) {
-  RequestPermission((content::PermissionType)(PermissionType::FULLSCREEN),
-                    callback);
+  RequestPermission(
+      static_cast<content::PermissionType>(PermissionType::FULLSCREEN),
+      callback);
 }
 
 void WebContentsPermissionHelper::RequestMediaAccessPermission(
@@ -86,17 +87,17 @@ void WebContentsPermissionHelper::RequestWebNotificationPermission(
 
 void WebContentsPermissionHelper::RequestPointerLockPermission(
     bool user_gesture) {
-  RequestPermission((content::PermissionType)(PermissionType::POINTER_LOCK),
-                    base::Bind(&OnPointerLockResponse, web_contents_),
-                    user_gesture);
+  RequestPermission(
+      static_cast<content::PermissionType>(PermissionType::POINTER_LOCK),
+      base::Bind(&OnPointerLockResponse, web_contents_), user_gesture);
 }
 
 void WebContentsPermissionHelper::RequestOpenExternalPermission(
     const base::Callback<void(bool)>& callback,
     bool user_gesture) {
-  RequestPermission((content::PermissionType)(PermissionType::OPEN_EXTERNAL),
-                    callback,
-                    user_gesture);
+  RequestPermission(
+      static_cast<content::PermissionType>(PermissionType::OPEN_EXTERNAL),
+      callback, user_gesture);
 }
 
 }  // namespace atom

+ 1 - 1
atom/browser/web_dialog_helper.cc

@@ -51,7 +51,7 @@ class FileSelectHelper : public base::RefCounted<FileSelectHelper>,
  private:
   friend class base::RefCounted<FileSelectHelper>;
 
-  ~FileSelectHelper() {}
+  ~FileSelectHelper() override {}
 
   void OnOpenDialogDone(bool result, const std::vector<base::FilePath>& paths) {
     std::vector<content::FileChooserFileInfo> file_info;

+ 1 - 1
atom/browser/window_list.cc

@@ -46,7 +46,7 @@ void WindowList::RemoveWindow(NativeWindow* window) {
   for (WindowListObserver& observer : observers_.Get())
     observer.OnWindowRemoved(window);
 
-  if (windows.size() == 0) {
+  if (windows.empty()) {
     for (WindowListObserver& observer : observers_.Get())
       observer.OnWindowAllClosed();
   }

+ 5 - 3
atom/common/native_mate_converters/content_converter.cc

@@ -168,11 +168,13 @@ v8::Local<v8::Value> Converter<content::PermissionType>::ToV8(
       break;
   }
 
-  if (val == (content::PermissionType)(PermissionType::POINTER_LOCK))
+  if (val == static_cast<content::PermissionType>(PermissionType::POINTER_LOCK))
     return StringToV8(isolate, "pointerLock");
-  else if (val == (content::PermissionType)(PermissionType::FULLSCREEN))
+  else if (val ==
+           static_cast<content::PermissionType>(PermissionType::FULLSCREEN))
     return StringToV8(isolate, "fullscreen");
-  else if (val == (content::PermissionType)(PermissionType::OPEN_EXTERNAL))
+  else if (val ==
+           static_cast<content::PermissionType>(PermissionType::OPEN_EXTERNAL))
     return StringToV8(isolate, "openExternal");
 
   return StringToV8(isolate, "unknown");

+ 9 - 7
atom/common/platform_util_mac.mm

@@ -11,6 +11,7 @@
 #include "base/files/file_path.h"
 #include "base/files/file_util.h"
 #include "base/logging.h"
+#include "base/mac/foundation_util.h"
 #include "base/mac/mac_logging.h"
 #include "base/mac/scoped_aedesc.h"
 #include "base/strings/stringprintf.h"
@@ -71,10 +72,10 @@ std::string MessageForOSStatus(OSStatus status, const char* default_message) {
 // thread safe, including LSGetApplicationForURL (> 10.2) and
 // NSWorkspace#openURLs.
 std::string OpenURL(NSURL* ns_url, bool activate) {
-  CFURLRef openingApp = NULL;
-  OSStatus status = LSGetApplicationForURL((CFURLRef)ns_url,
+  CFURLRef openingApp = nullptr;
+  OSStatus status = LSGetApplicationForURL(base::mac::NSToCFCast(ns_url),
                                            kLSRolesAll,
-                                           NULL,
+                                           nullptr,
                                            &openingApp);
   if (status != noErr)
     return MessageForOSStatus(status, "Failed to open");
@@ -156,7 +157,7 @@ bool OpenItem(const base::FilePath& full_path) {
 
   // Create the list of files (only ever one) to open.
   base::mac::ScopedAEDesc<AEDescList> fileList;
-  status = AECreateList(NULL,  // factoringPtr
+  status = AECreateList(nullptr,  // factoringPtr
                         0,  // factoredSize
                         false,  // isRecord
                         fileList.OutPointer());  // resultList
@@ -167,7 +168,8 @@ bool OpenItem(const base::FilePath& full_path) {
 
   // Add the single path to the file list.  C-style cast to avoid both a
   // static_cast and a const_cast to get across the toll-free bridge.
-  CFURLRef pathURLRef = (CFURLRef)[NSURL fileURLWithPath:path_string];
+  CFURLRef pathURLRef = base::mac::NSToCFCast(
+      [NSURL fileURLWithPath:path_string]);
   FSRef pathRef;
   if (CFURLGetFSRef(pathURLRef, &pathRef)) {
     status = AEPutPtr(fileList.OutPointer(),  // theAEDescList
@@ -202,8 +204,8 @@ bool OpenItem(const base::FilePath& full_path) {
                   kAENoReply + kAEAlwaysInteract,  // sendMode
                   kAENormalPriority,  // sendPriority
                   kAEDefaultTimeout,  // timeOutInTicks
-                  NULL, // idleProc
-                  NULL);  // filterProc
+                  nullptr, // idleProc
+                  nullptr);  // filterProc
   if (status != noErr) {
     OSSTATUS_LOG(WARNING, status)
         << "Could not send AE to Finder in OpenItem()";

+ 1 - 1
atom/renderer/atom_sandboxed_renderer_client.cc

@@ -238,7 +238,7 @@ void AtomSandboxedRendererClient::WillReleaseScriptContext(
 
 void AtomSandboxedRendererClient::InvokeIpcCallback(
     v8::Handle<v8::Context> context,
-    std::string callback_name,
+    const std::string& callback_name,
     std::vector<v8::Handle<v8::Value>> args) {
   auto isolate = context->GetIsolate();
   auto binding_key = mate::ConvertToV8(isolate, kIpcKey)->ToString();

+ 1 - 1
atom/renderer/atom_sandboxed_renderer_client.h

@@ -21,7 +21,7 @@ class AtomSandboxedRendererClient : public RendererClientBase {
   void WillReleaseScriptContext(
       v8::Handle<v8::Context> context, content::RenderFrame* render_frame);
   void InvokeIpcCallback(v8::Handle<v8::Context> context,
-                         std::string callback_name,
+                         const std::string& callback_name,
                          std::vector<v8::Handle<v8::Value>> args);
   // content::ContentRendererClient:
   void RenderFrameCreated(content::RenderFrame*) override;