chore: use auto to avoid repeating type (#26113)

This commit is contained in:
David Sanders 2020-10-26 11:56:31 -07:00 committed by GitHub
parent f714556a12
commit 4be10523e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 38 additions and 48 deletions

View file

@ -54,8 +54,7 @@ void Debugger::DispatchProtocolMessage(DevToolsAgentHost* agent_host,
base::JSON_REPLACE_INVALID_CHARACTERS); base::JSON_REPLACE_INVALID_CHARACTERS);
if (!parsed_message || !parsed_message->is_dict()) if (!parsed_message || !parsed_message->is_dict())
return; return;
base::DictionaryValue* dict = auto* dict = static_cast<base::DictionaryValue*>(parsed_message.get());
static_cast<base::DictionaryValue*>(parsed_message.get());
int id; int id;
if (!dict->GetInteger("id", &id)) { if (!dict->GetInteger("id", &id)) {
std::string method; std::string method;

View file

@ -77,7 +77,7 @@ gin::WrapperInfo DownloadItem::kWrapperInfo = {gin::kEmbedderNativeGin};
DownloadItem* DownloadItem::FromDownloadItem( DownloadItem* DownloadItem::FromDownloadItem(
download::DownloadItem* download_item) { download::DownloadItem* download_item) {
// ^- say that 7 times fast in a row // ^- say that 7 times fast in a row
UserDataLink* data = static_cast<UserDataLink*>( auto* data = static_cast<UserDataLink*>(
download_item->GetUserData(kElectronApiDownloadItemKey)); download_item->GetUserData(kElectronApiDownloadItemKey));
return data ? data->download_item.get() : nullptr; return data ? data->download_item.get() : nullptr;
} }

View file

@ -58,7 +58,7 @@ LRESULT CALLBACK PowerMonitor::WndProcStatic(HWND hwnd,
UINT message, UINT message,
WPARAM wparam, WPARAM wparam,
LPARAM lparam) { LPARAM lparam) {
PowerMonitor* msg_wnd = auto* msg_wnd =
reinterpret_cast<PowerMonitor*>(GetWindowLongPtr(hwnd, GWLP_USERDATA)); reinterpret_cast<PowerMonitor*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
if (msg_wnd) if (msg_wnd)
return msg_wnd->WndProc(hwnd, message, wparam, lparam); return msg_wnd->WndProc(hwnd, message, wparam, lparam);

View file

@ -1044,7 +1044,7 @@ bool Session::RemoveWordFromSpellCheckerDictionary(const std::string& word) {
// static // static
Session* Session::FromBrowserContext(content::BrowserContext* context) { Session* Session::FromBrowserContext(content::BrowserContext* context) {
UserDataLink* data = auto* data =
static_cast<UserDataLink*>(context->GetUserData(kElectronApiSessionKey)); static_cast<UserDataLink*>(context->GetUserData(kElectronApiSessionKey));
return data ? data->session : nullptr; return data ? data->session : nullptr;
} }

View file

@ -218,7 +218,7 @@ LRESULT CALLBACK SystemPreferences::WndProcStatic(HWND hwnd,
UINT message, UINT message,
WPARAM wparam, WPARAM wparam,
LPARAM lparam) { LPARAM lparam) {
SystemPreferences* msg_wnd = reinterpret_cast<SystemPreferences*>( auto* msg_wnd = reinterpret_cast<SystemPreferences*>(
GetWindowLongPtr(hwnd, GWLP_USERDATA)); GetWindowLongPtr(hwnd, GWLP_USERDATA));
if (msg_wnd) if (msg_wnd)
return msg_wnd->WndProc(hwnd, message, wparam, lparam); return msg_wnd->WndProc(hwnd, message, wparam, lparam);

View file

@ -3081,7 +3081,7 @@ gin::Handle<WebContents> WebContents::CreateAndTake(
WebContents* WebContents::From(content::WebContents* web_contents) { WebContents* WebContents::From(content::WebContents* web_contents) {
if (!web_contents) if (!web_contents)
return nullptr; return nullptr;
UserDataLink* data = static_cast<UserDataLink*>( auto* data = static_cast<UserDataLink*>(
web_contents->GetUserData(kElectronApiWebContentsKey)); web_contents->GetUserData(kElectronApiWebContentsKey));
return data ? data->web_contents.get() : nullptr; return data ? data->web_contents.get() : nullptr;
} }

View file

@ -105,7 +105,7 @@ ProcessIntegrityLevel ProcessMetric::GetIntegrityLevel() const {
} }
auto token_label_bytes = std::make_unique<char[]>(token_info_length); auto token_label_bytes = std::make_unique<char[]>(token_info_length);
TOKEN_MANDATORY_LABEL* token_label = auto* token_label =
reinterpret_cast<TOKEN_MANDATORY_LABEL*>(token_label_bytes.get()); reinterpret_cast<TOKEN_MANDATORY_LABEL*>(token_label_bytes.get());
if (!::GetTokenInformation(token, TokenIntegrityLevel, token_label, if (!::GetTokenInformation(token, TokenIntegrityLevel, token_label,
token_info_length, &token_info_length)) { token_info_length, &token_info_length)) {

View file

@ -922,7 +922,7 @@ ElectronBrowserClient::CreateWindowForPictureInPicture(
#if defined(OS_WIN) #if defined(OS_WIN)
base::string16 app_user_model_id = Browser::Get()->GetAppUserModelID(); base::string16 app_user_model_id = Browser::Get()->GetAppUserModelID();
if (!app_user_model_id.empty()) { if (!app_user_model_id.empty()) {
OverlayWindowViews* overlay_window_view = auto* overlay_window_view =
static_cast<OverlayWindowViews*>(overlay_window.get()); static_cast<OverlayWindowViews*>(overlay_window.get());
ui::win::SetAppIdForWindow(app_user_model_id, ui::win::SetAppIdForWindow(app_user_model_id,
overlay_window_view->GetNativeWindow() overlay_window_view->GetNativeWindow()

View file

@ -153,9 +153,8 @@ void ElectronDownloadManagerDelegate::OnDownloadSaveDialogDone(
if (!canceled) { if (!canceled) {
if (result.Get("filePath", &path)) { if (result.Get("filePath", &path)) {
// Remember the last selected download directory. // Remember the last selected download directory.
ElectronBrowserContext* browser_context = auto* browser_context = static_cast<ElectronBrowserContext*>(
static_cast<ElectronBrowserContext*>( download_manager_->GetBrowserContext());
download_manager_->GetBrowserContext());
browser_context->prefs()->SetFilePath(prefs::kDownloadDefaultDirectory, browser_context->prefs()->SetFilePath(prefs::kDownloadDefaultDirectory,
path.DirName()); path.DirName());
@ -211,9 +210,8 @@ bool ElectronDownloadManagerDelegate::DetermineDownloadTarget(
return true; return true;
} }
ElectronBrowserContext* browser_context = auto* browser_context = static_cast<ElectronBrowserContext*>(
static_cast<ElectronBrowserContext*>( download_manager_->GetBrowserContext());
download_manager_->GetBrowserContext());
base::FilePath default_download_path = base::FilePath default_download_path =
browser_context->prefs()->GetFilePath(prefs::kDownloadDefaultDirectory); browser_context->prefs()->GetFilePath(prefs::kDownloadDefaultDirectory);

View file

@ -1384,8 +1384,7 @@ void NativeWindowViews::OnWidgetBoundsChanged(views::Widget* changed_widget,
int width_delta = new_bounds.width() - widget_size_.width(); int width_delta = new_bounds.width() - widget_size_.width();
int height_delta = new_bounds.height() - widget_size_.height(); int height_delta = new_bounds.height() - widget_size_.height();
for (NativeBrowserView* item : browser_views()) { for (NativeBrowserView* item : browser_views()) {
NativeBrowserViewViews* native_view = auto* native_view = static_cast<NativeBrowserViewViews*>(item);
static_cast<NativeBrowserViewViews*>(item);
native_view->SetAutoResizeProportions(widget_size_); native_view->SetAutoResizeProportions(widget_size_);
native_view->AutoResize(new_bounds, width_delta, height_delta); native_view->AutoResize(new_bounds, width_delta, height_delta);
} }
@ -1453,7 +1452,7 @@ bool NativeWindowViews::ShouldDescendIntoChildForEventHandling(
// And the events on border for dragging resizable frameless window. // And the events on border for dragging resizable frameless window.
if (!has_frame() && CanResize()) { if (!has_frame() && CanResize()) {
FramelessView* frame = auto* frame =
static_cast<FramelessView*>(widget()->non_client_view()->frame_view()); static_cast<FramelessView*>(widget()->non_client_view()->frame_view());
return frame->ResizingBorderHitTest(location) == HTNOWHERE; return frame->ResizingBorderHitTest(location) == HTNOWHERE;
} }

View file

@ -397,7 +397,7 @@ LRESULT CALLBACK NativeWindowViews::SubclassProc(HWND hwnd,
LPARAM l_param, LPARAM l_param,
UINT_PTR subclass_id, UINT_PTR subclass_id,
DWORD_PTR ref_data) { DWORD_PTR ref_data) {
NativeWindowViews* window = reinterpret_cast<NativeWindowViews*>(ref_data); auto* window = reinterpret_cast<NativeWindowViews*>(ref_data);
switch (msg) { switch (msg) {
case WM_MOUSELEAVE: { case WM_MOUSELEAVE: {
// When input is forwarded to underlying windows, this message is posted. // When input is forwarded to underlying windows, this message is posted.

View file

@ -96,8 +96,7 @@ void PlatformNotificationService::DisplayNotification(
// See: https://notifications.spec.whatwg.org/#showing-a-notification // See: https://notifications.spec.whatwg.org/#showing-a-notification
presenter->CloseNotificationWithId(notification_id); presenter->CloseNotificationWithId(notification_id);
NotificationDelegateImpl* delegate = auto* delegate = new NotificationDelegateImpl(notification_id);
new NotificationDelegateImpl(notification_id);
auto notification = presenter->CreateNotification(delegate, notification_id); auto notification = presenter->CreateNotification(delegate, notification_id);
if (notification) { if (notification) {

View file

@ -382,8 +382,7 @@ void OffScreenRenderWidgetHostView::TakeFallbackContentFrom(
content::RenderWidgetHostView* view) { content::RenderWidgetHostView* view) {
DCHECK(!static_cast<content::RenderWidgetHostViewBase*>(view) DCHECK(!static_cast<content::RenderWidgetHostViewBase*>(view)
->IsRenderWidgetHostViewChildFrame()); ->IsRenderWidgetHostViewChildFrame());
OffScreenRenderWidgetHostView* view_osr = auto* view_osr = static_cast<OffScreenRenderWidgetHostView*>(view);
static_cast<OffScreenRenderWidgetHostView*>(view);
SetBackgroundColor(view_osr->background_color_); SetBackgroundColor(view_osr->background_color_);
if (GetDelegatedFrameHost() && view_osr->GetDelegatedFrameHost()) { if (GetDelegatedFrameHost() && view_osr->GetDelegatedFrameHost()) {
GetDelegatedFrameHost()->TakeFallbackContentFrom( GetDelegatedFrameHost()->TakeFallbackContentFrom(

View file

@ -126,15 +126,13 @@ OffScreenWebContentsView::CreateViewForWidget(
content::RenderWidgetHostViewBase* content::RenderWidgetHostViewBase*
OffScreenWebContentsView::CreateViewForChildWidget( OffScreenWebContentsView::CreateViewForChildWidget(
content::RenderWidgetHost* render_widget_host) { content::RenderWidgetHost* render_widget_host) {
content::WebContentsImpl* web_contents_impl = auto* web_contents_impl =
static_cast<content::WebContentsImpl*>(web_contents_); static_cast<content::WebContentsImpl*>(web_contents_);
OffScreenRenderWidgetHostView* view = auto* view = static_cast<OffScreenRenderWidgetHostView*>(
static_cast<OffScreenRenderWidgetHostView*>( web_contents_impl->GetOuterWebContents()
web_contents_impl->GetOuterWebContents() ? web_contents_impl->GetOuterWebContents()->GetRenderWidgetHostView()
? web_contents_impl->GetOuterWebContents() : web_contents_impl->GetRenderWidgetHostView());
->GetRenderWidgetHostView()
: web_contents_impl->GetRenderWidgetHostView());
return new OffScreenRenderWidgetHostView(transparent_, painting_, return new OffScreenRenderWidgetHostView(transparent_, painting_,
view->GetFrameRate(), callback_, view->GetFrameRate(), callback_,

View file

@ -44,7 +44,7 @@ base::UnguessableToken DecodeToken(base::StringPiece input) {
return base::UnguessableToken(); return base::UnguessableToken();
} }
const uint64_t* data = reinterpret_cast<const uint64_t*>(buffer.data()); const auto* data = reinterpret_cast<const uint64_t*>(buffer.data());
return base::UnguessableToken::Deserialize(data[0], data[1]); return base::UnguessableToken::Deserialize(data[0], data[1]);
} }

View file

@ -73,7 +73,7 @@ void AutofillPopupView::Show() {
// The widget is destroyed by the corresponding NativeWidget, so we use // The widget is destroyed by the corresponding NativeWidget, so we use
// a weak pointer to hold the reference and don't have to worry about // a weak pointer to hold the reference and don't have to worry about
// deletion. // deletion.
views::Widget* widget = new views::Widget; auto* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
params.delegate = this; params.delegate = this;
params.parent = parent_widget_->GetNativeView(); params.parent = parent_widget_->GetNativeView();

View file

@ -89,7 +89,7 @@ InspectableWebContentsViewViews::InspectableWebContentsViewViews(
title_(base::ASCIIToUTF16("Developer Tools")) { title_(base::ASCIIToUTF16("Developer Tools")) {
if (!inspectable_web_contents_->IsGuest() && if (!inspectable_web_contents_->IsGuest() &&
inspectable_web_contents_->GetWebContents()->GetNativeView()) { inspectable_web_contents_->GetWebContents()->GetNativeView()) {
views::WebView* contents_web_view = new views::WebView(nullptr); auto* contents_web_view = new views::WebView(nullptr);
contents_web_view->SetWebContents( contents_web_view->SetWebContents(
inspectable_web_contents_->GetWebContents()); inspectable_web_contents_->GetWebContents());
contents_web_view_ = contents_web_view; contents_web_view_ = contents_web_view;

View file

@ -272,7 +272,7 @@ void MenuBar::ButtonPressed(views::Button* source, const ui::Event& event) {
} }
// Deleted in MenuDelegate::OnMenuClosed // Deleted in MenuDelegate::OnMenuClosed
MenuDelegate* menu_delegate = new MenuDelegate(this); auto* menu_delegate = new MenuDelegate(this);
menu_delegate->RunMenu( menu_delegate->RunMenu(
menu_model_->GetSubmenuModelAt(id), source, menu_model_->GetSubmenuModelAt(id), source,
event.IsKeyEvent() ? ui::MENU_SOURCE_KEYBOARD : ui::MENU_SOURCE_MOUSE); event.IsKeyEvent() ? ui::MENU_SOURCE_KEYBOARD : ui::MENU_SOURCE_MOUSE);

View file

@ -39,7 +39,7 @@ void MenuDelegate::RunMenu(ElectronMenuModel* model,
id_ = button->tag(); id_ = button->tag();
adapter_ = std::make_unique<MenuModelAdapter>(model); adapter_ = std::make_unique<MenuModelAdapter>(model);
views::MenuItemView* item = new views::MenuItemView(this); auto* item = new views::MenuItemView(this);
static_cast<MenuModelAdapter*>(adapter_.get())->BuildMenu(item); static_cast<MenuModelAdapter*>(adapter_.get())->BuildMenu(item);
menu_runner_ = std::make_unique<views::MenuRunner>( menu_runner_ = std::make_unique<views::MenuRunner>(

View file

@ -89,7 +89,7 @@ NotifyIcon* NotifyIconHost::CreateNotifyIcon(base::Optional<UUID> guid) {
if (guid.has_value()) { if (guid.has_value()) {
for (NotifyIcons::const_iterator i(notify_icons_.begin()); for (NotifyIcons::const_iterator i(notify_icons_.begin());
i != notify_icons_.end(); ++i) { i != notify_icons_.end(); ++i) {
NotifyIcon* current_win_icon = static_cast<NotifyIcon*>(*i); auto* current_win_icon = static_cast<NotifyIcon*>(*i);
if (current_win_icon->guid() == guid.value()) { if (current_win_icon->guid() == guid.value()) {
LOG(WARNING) LOG(WARNING)
<< "Guid already in use. Existing tray entry will be replaced."; << "Guid already in use. Existing tray entry will be replaced.";
@ -97,7 +97,7 @@ NotifyIcon* NotifyIconHost::CreateNotifyIcon(base::Optional<UUID> guid) {
} }
} }
NotifyIcon* notify_icon = auto* notify_icon =
new NotifyIcon(this, NextIconId(), window_, kNotifyIconMessage, new NotifyIcon(this, NextIconId(), window_, kNotifyIconMessage,
guid.has_value() ? guid.value() : GUID_DEFAULT); guid.has_value() ? guid.value() : GUID_DEFAULT);
@ -121,7 +121,7 @@ LRESULT CALLBACK NotifyIconHost::WndProcStatic(HWND hwnd,
UINT message, UINT message,
WPARAM wparam, WPARAM wparam,
LPARAM lparam) { LPARAM lparam) {
NotifyIconHost* msg_wnd = auto* msg_wnd =
reinterpret_cast<NotifyIconHost*>(GetWindowLongPtr(hwnd, GWLP_USERDATA)); reinterpret_cast<NotifyIconHost*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
if (msg_wnd) if (msg_wnd)
return msg_wnd->WndProc(hwnd, message, wparam, lparam); return msg_wnd->WndProc(hwnd, message, wparam, lparam);
@ -137,7 +137,7 @@ LRESULT CALLBACK NotifyIconHost::WndProc(HWND hwnd,
// We need to reset all of our icons because the taskbar went away. // We need to reset all of our icons because the taskbar went away.
for (NotifyIcons::const_iterator i(notify_icons_.begin()); for (NotifyIcons::const_iterator i(notify_icons_.begin());
i != notify_icons_.end(); ++i) { i != notify_icons_.end(); ++i) {
NotifyIcon* win_icon = static_cast<NotifyIcon*>(*i); auto* win_icon = static_cast<NotifyIcon*>(*i);
win_icon->ResetIcon(); win_icon->ResetIcon();
} }
return TRUE; return TRUE;
@ -147,7 +147,7 @@ LRESULT CALLBACK NotifyIconHost::WndProc(HWND hwnd,
// Find the selected status icon. // Find the selected status icon.
for (NotifyIcons::const_iterator i(notify_icons_.begin()); for (NotifyIcons::const_iterator i(notify_icons_.begin());
i != notify_icons_.end(); ++i) { i != notify_icons_.end(); ++i) {
NotifyIcon* current_win_icon = static_cast<NotifyIcon*>(*i); auto* current_win_icon = static_cast<NotifyIcon*>(*i);
if (current_win_icon->icon_id() == wparam) { if (current_win_icon->icon_id() == wparam) {
win_icon = current_win_icon; win_icon = current_win_icon;
break; break;

View file

@ -108,7 +108,7 @@ void ElectronBindings::ActivateUVLoop(v8::Isolate* isolate) {
// static // static
void ElectronBindings::OnCallNextTick(uv_async_t* handle) { void ElectronBindings::OnCallNextTick(uv_async_t* handle) {
ElectronBindings* self = static_cast<ElectronBindings*>(handle->data); auto* self = static_cast<ElectronBindings*>(handle->data);
for (std::list<node::Environment*>::const_iterator it = for (std::list<node::Environment*>::const_iterator it =
self->pending_next_ticks_.begin(); self->pending_next_ticks_.begin();
it != self->pending_next_ticks_.end(); ++it) { it != self->pending_next_ticks_.end(); ++it) {

View file

@ -55,7 +55,7 @@ void CallTranslater(v8::Local<v8::External> external,
} }
} }
TranslaterHolder* holder = static_cast<TranslaterHolder*>(external->Value()); auto* holder = static_cast<TranslaterHolder*>(external->Value());
holder->translater.Run(args); holder->translater.Run(args);
// Free immediately for one-time callback. // Free immediately for one-time callback.

View file

@ -64,8 +64,7 @@ void WrappableBase::InitWith(v8::Isolate* isolate,
// static // static
void WrappableBase::FirstWeakCallback( void WrappableBase::FirstWeakCallback(
const v8::WeakCallbackInfo<WrappableBase>& data) { const v8::WeakCallbackInfo<WrappableBase>& data) {
WrappableBase* wrappable = auto* wrappable = static_cast<WrappableBase*>(data.GetInternalField(0));
static_cast<WrappableBase*>(data.GetInternalField(0));
if (wrappable) { if (wrappable) {
wrappable->wrapper_.Reset(); wrappable->wrapper_.Reset();
data.SetSecondPassCallback(SecondWeakCallback); data.SetSecondPassCallback(SecondWeakCallback);
@ -75,8 +74,7 @@ void WrappableBase::FirstWeakCallback(
// static // static
void WrappableBase::SecondWeakCallback( void WrappableBase::SecondWeakCallback(
const v8::WeakCallbackInfo<WrappableBase>& data) { const v8::WeakCallbackInfo<WrappableBase>& data) {
WrappableBase* wrappable = auto* wrappable = static_cast<WrappableBase*>(data.GetInternalField(0));
static_cast<WrappableBase*>(data.GetInternalField(0));
if (wrappable) if (wrappable)
delete wrappable; delete wrappable;
} }

View file

@ -560,7 +560,7 @@ void NodeBindings::WakeupEmbedThread() {
// static // static
void NodeBindings::EmbedThreadRunner(void* arg) { void NodeBindings::EmbedThreadRunner(void* arg) {
NodeBindings* self = static_cast<NodeBindings*>(arg); auto* self = static_cast<NodeBindings*>(arg);
while (true) { while (true) {
// Wait for the main loop to deal with events. // Wait for the main loop to deal with events.

View file

@ -128,7 +128,7 @@ bool AddImageSkiaRepFromPath(gfx::ImageSkia* image,
return false; return false;
} }
const unsigned char* data = const auto* data =
reinterpret_cast<const unsigned char*>(file_contents.data()); reinterpret_cast<const unsigned char*>(file_contents.data());
size_t size = file_contents.size(); size_t size = file_contents.size();