Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize to c++11 #6423

Merged
merged 6 commits into from Jul 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion atom/app/uv_task_runner.cc
Expand Up @@ -21,7 +21,7 @@ UvTaskRunner::~UvTaskRunner() {
bool UvTaskRunner::PostDelayedTask(const tracked_objects::Location& from_here,
const base::Closure& task,
base::TimeDelta delay) {
uv_timer_t* timer = new uv_timer_t;
auto* timer = new uv_timer_t;
timer->data = this;
uv_timer_init(loop_, timer);
uv_timer_start(timer, UvTaskRunner::OnTimeout, delay.InMilliseconds(), 0);
Expand Down
2 changes: 1 addition & 1 deletion atom/browser/api/atom_api_menu.cc
Expand Up @@ -21,7 +21,7 @@ namespace api {

Menu::Menu(v8::Isolate* isolate)
: model_(new AtomMenuModel(this)),
parent_(NULL) {
parent_(nullptr) {
}

Menu::~Menu() {
Expand Down
8 changes: 4 additions & 4 deletions atom/browser/api/atom_api_session.cc
Expand Up @@ -241,10 +241,10 @@ void OnGetBackend(disk_cache::Backend** backend_ptr,
} else if (action == Session::CacheAction::STATS) {
base::StringPairs stats;
(*backend_ptr)->GetStats(&stats);
for (size_t i = 0; i < stats.size(); ++i) {
if (stats[i].first == "Current size") {
for (const auto& stat : stats) {
if (stat.first == "Current size") {
int current_size;
base::StringToInt(stats[i].second, &current_size);
base::StringToInt(stat.second, &current_size);
RunCallbackInUI(callback, current_size);
break;
}
Expand All @@ -266,7 +266,7 @@ void DoCacheActionInIO(

// Call GetBackend and make the backend's ptr accessable in OnGetBackend.
using BackendPtr = disk_cache::Backend*;
BackendPtr* backend_ptr = new BackendPtr(nullptr);
auto* backend_ptr = new BackendPtr(nullptr);
net::CompletionCallback on_get_backend =
base::Bind(&OnGetBackend, base::Owned(backend_ptr), action, callback);
int rv = http_cache->GetBackend(backend_ptr, on_get_backend);
Expand Down
6 changes: 3 additions & 3 deletions atom/browser/api/atom_api_web_contents.cc
Expand Up @@ -685,10 +685,10 @@ void WebContents::TitleWasSet(content::NavigationEntry* entry,
void WebContents::DidUpdateFaviconURL(
const std::vector<content::FaviconURL>& urls) {
std::set<GURL> unique_urls;
for (auto iter = urls.begin(); iter != urls.end(); ++iter) {
if (iter->icon_type != content::FaviconURL::FAVICON)
for (const auto& iter : urls) {
if (iter.icon_type != content::FaviconURL::FAVICON)
continue;
const GURL& url = iter->icon_url;
const GURL& url = iter.icon_url;
if (url.is_valid())
unique_urls.insert(url);
}
Expand Down
14 changes: 7 additions & 7 deletions atom/browser/api/event.cc
Expand Up @@ -12,8 +12,8 @@
namespace mate {

Event::Event(v8::Isolate* isolate)
: sender_(NULL),
message_(NULL) {
: sender_(nullptr),
message_(nullptr) {
Init(isolate);
}

Expand All @@ -31,8 +31,8 @@ void Event::SetSenderAndMessage(content::WebContents* sender,
}

void Event::WebContentsDestroyed() {
sender_ = NULL;
message_ = NULL;
sender_ = nullptr;
message_ = nullptr;
}

void Event::PreventDefault(v8::Isolate* isolate) {
Expand All @@ -41,13 +41,13 @@ void Event::PreventDefault(v8::Isolate* isolate) {
}

bool Event::SendReply(const base::string16& json) {
if (message_ == NULL || sender_ == NULL)
if (message_ == nullptr || sender_ == nullptr)
return false;

AtomViewHostMsg_Message_Sync::WriteReplyParams(message_, json);
bool success = sender_->Send(message_);
message_ = NULL;
sender_ = NULL;
message_ = nullptr;
sender_ = nullptr;
return success;
}

Expand Down
2 changes: 1 addition & 1 deletion atom/browser/atom_browser_main_parts.cc
Expand Up @@ -32,7 +32,7 @@ void Erase(T* container, typename T::iterator iter) {
}

// static
AtomBrowserMainParts* AtomBrowserMainParts::self_ = NULL;
AtomBrowserMainParts* AtomBrowserMainParts::self_ = nullptr;

AtomBrowserMainParts::AtomBrowserMainParts()
: fake_browser_process_(new BrowserProcess),
Expand Down
10 changes: 5 additions & 5 deletions atom/browser/atom_browser_main_parts_posix.cc
Expand Up @@ -43,7 +43,7 @@ void GracefulShutdownHandler(int signal) {
struct sigaction action;
memset(&action, 0, sizeof(action));
action.sa_handler = SIG_DFL;
RAW_CHECK(sigaction(signal, &action, NULL) == 0);
RAW_CHECK(sigaction(signal, &action, nullptr) == 0);

RAW_CHECK(g_pipe_pid == getpid());
RAW_CHECK(g_shutdown_pipe_write_fd != -1);
Expand Down Expand Up @@ -171,7 +171,7 @@ void AtomBrowserMainParts::HandleSIGCHLD() {
struct sigaction action;
memset(&action, 0, sizeof(action));
action.sa_handler = SIGCHLDHandler;
CHECK_EQ(sigaction(SIGCHLD, &action, NULL), 0);
CHECK_EQ(sigaction(SIGCHLD, &action, nullptr), 0);
}

void AtomBrowserMainParts::HandleShutdownSignals() {
Expand Down Expand Up @@ -211,15 +211,15 @@ void AtomBrowserMainParts::HandleShutdownSignals() {
struct sigaction action;
memset(&action, 0, sizeof(action));
action.sa_handler = SIGTERMHandler;
CHECK_EQ(sigaction(SIGTERM, &action, NULL), 0);
CHECK_EQ(sigaction(SIGTERM, &action, nullptr), 0);
// Also handle SIGINT - when the user terminates the browser via Ctrl+C. If
// the browser process is being debugged, GDB will catch the SIGINT first.
action.sa_handler = SIGINTHandler;
CHECK_EQ(sigaction(SIGINT, &action, NULL), 0);
CHECK_EQ(sigaction(SIGINT, &action, nullptr), 0);
// And SIGHUP, for when the terminal disappears. On shutdown, many Linux
// distros send SIGHUP, SIGTERM, and then SIGKILL.
action.sa_handler = SIGHUPHandler;
CHECK_EQ(sigaction(SIGHUP, &action, NULL), 0);
CHECK_EQ(sigaction(SIGHUP, &action, nullptr), 0);
}

} // namespace atom
15 changes: 7 additions & 8 deletions atom/browser/common_web_contents_delegate.cc
Expand Up @@ -94,7 +94,7 @@ FileSystem CreateFileSystemStruct(
}

base::DictionaryValue* CreateFileSystemValue(const FileSystem& file_system) {
base::DictionaryValue* file_system_value = new base::DictionaryValue();
auto* file_system_value = new base::DictionaryValue();
file_system_value->SetString("fileSystemName", file_system.file_system_name);
file_system_value->SetString("rootURL", file_system.root_url);
file_system_value->SetString("fileSystemPath", file_system.file_system_path);
Expand Down Expand Up @@ -377,7 +377,7 @@ content::SecurityStyle CommonWebContentsDelegate::GetSecurityStyle(
void CommonWebContentsDelegate::DevToolsSaveToFile(
const std::string& url, const std::string& content, bool save_as) {
base::FilePath path;
PathsMap::iterator it = saved_files_.find(url);
auto it = saved_files_.find(url);
if (it != saved_files_.end() && !save_as) {
path = it->second;
} else {
Expand All @@ -402,7 +402,7 @@ void CommonWebContentsDelegate::DevToolsSaveToFile(

void CommonWebContentsDelegate::DevToolsAppendToFile(
const std::string& url, const std::string& content) {
PathsMap::iterator it = saved_files_.find(url);
auto it = saved_files_.find(url);
if (it == saved_files_.end())
return;

Expand Down Expand Up @@ -435,8 +435,8 @@ void CommonWebContentsDelegate::DevToolsRequestFileSystems() {
}

base::ListValue file_system_value;
for (size_t i = 0; i < file_systems.size(); ++i)
file_system_value.Append(CreateFileSystemValue(file_systems[i]));
for (const auto& file_system : file_systems)
file_system_value.Append(CreateFileSystemValue(file_system));
web_contents_->CallClientFunction("DevToolsAPI.fileSystemsLoaded",
&file_system_value, nullptr, nullptr);
}
Expand Down Expand Up @@ -610,9 +610,8 @@ void CommonWebContentsDelegate::OnDevToolsSearchCompleted(
const std::string& file_system_path,
const std::vector<std::string>& file_paths) {
base::ListValue file_paths_value;
for (std::vector<std::string>::const_iterator it(file_paths.begin());
it != file_paths.end(); ++it) {
file_paths_value.AppendString(*it);
for (const auto& file_path : file_paths) {
file_paths_value.AppendString(file_path);
}
base::FundamentalValue request_id_value(request_id);
base::StringValue file_system_path_value(file_system_path);
Expand Down
2 changes: 1 addition & 1 deletion atom/browser/net/asar/asar_protocol_handler.cc
Expand Up @@ -22,7 +22,7 @@ net::URLRequestJob* AsarProtocolHandler::MaybeCreateJob(
net::NetworkDelegate* network_delegate) const {
base::FilePath full_path;
net::FileURLToFilePath(request->url(), &full_path);
URLRequestAsarJob* job = new URLRequestAsarJob(request, network_delegate);
auto* job = new URLRequestAsarJob(request, network_delegate);
job->Initialize(file_task_runner_, full_path);
return job;
}
Expand Down
8 changes: 4 additions & 4 deletions atom/browser/net/asar/url_request_asar_job.cc
Expand Up @@ -111,7 +111,7 @@ void URLRequestAsarJob::Start() {
if (rv != net::ERR_IO_PENDING)
DidOpen(rv);
} else if (type_ == TYPE_FILE) {
FileMetaInfo* meta_info = new FileMetaInfo();
auto* meta_info = new FileMetaInfo();
file_task_runner_->PostTaskAndReply(
FROM_HERE,
base::Bind(&URLRequestAsarJob::FetchMetaInfo, file_path_,
Expand Down Expand Up @@ -183,7 +183,7 @@ bool URLRequestAsarJob::IsRedirectResponse(GURL* location,
net::Filter* URLRequestAsarJob::SetupFilter() const {
// Bug 9936 - .svgz files needs to be decompressed.
return base::LowerCaseEqualsASCII(file_path_.Extension(), ".svgz")
? net::Filter::GZipFactory() : NULL;
? net::Filter::GZipFactory() : nullptr;
}

bool URLRequestAsarJob::GetMimeType(std::string* mime_type) const {
Expand Down Expand Up @@ -224,7 +224,7 @@ int URLRequestAsarJob::GetResponseCode() const {

void URLRequestAsarJob::GetResponseInfo(net::HttpResponseInfo* info) {
std::string status("HTTP/1.1 200 OK");
net::HttpResponseHeaders* headers = new net::HttpResponseHeaders(status);
auto* headers = new net::HttpResponseHeaders(status);

headers->AddHeader(atom::kCORSHeader);
info->headers = headers;
Expand Down Expand Up @@ -338,7 +338,7 @@ void URLRequestAsarJob::DidRead(scoped_refptr<net::IOBuffer> buf, int result) {
DCHECK_GE(remaining_bytes_, 0);
}

buf = NULL;
buf = nullptr;

ReadRawDataComplete(result);
}
Expand Down
6 changes: 3 additions & 3 deletions atom/browser/net/atom_url_request_job_factory.cc
Expand Up @@ -27,7 +27,7 @@ bool AtomURLRequestJobFactory::SetProtocolHandler(
const std::string& scheme,
std::unique_ptr<ProtocolHandler> protocol_handler) {
if (!protocol_handler) {
ProtocolHandlerMap::iterator it = protocol_handler_map_.find(scheme);
auto it = protocol_handler_map_.find(scheme);
if (it == protocol_handler_map_.end())
return false;

Expand Down Expand Up @@ -66,7 +66,7 @@ ProtocolHandler* AtomURLRequestJobFactory::GetProtocolHandler(
const std::string& scheme) const {
DCHECK_CURRENTLY_ON(BrowserThread::IO);

ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(scheme);
auto it = protocol_handler_map_.find(scheme);
if (it == protocol_handler_map_.end())
return nullptr;
return it->second;
Expand All @@ -87,7 +87,7 @@ net::URLRequestJob* AtomURLRequestJobFactory::MaybeCreateJobWithProtocolHandler(
net::NetworkDelegate* network_delegate) const {
DCHECK_CURRENTLY_ON(BrowserThread::IO);

ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(scheme);
auto it = protocol_handler_map_.find(scheme);
if (it == protocol_handler_map_.end())
return nullptr;
return it->second->MaybeCreateJob(request, network_delegate);
Expand Down
2 changes: 1 addition & 1 deletion atom/browser/net/url_request_async_asar_job.cc
Expand Up @@ -40,7 +40,7 @@ void URLRequestAsyncAsarJob::StartAsync(std::unique_ptr<base::Value> options) {

void URLRequestAsyncAsarJob::GetResponseInfo(net::HttpResponseInfo* info) {
std::string status("HTTP/1.1 200 OK");
net::HttpResponseHeaders* headers = new net::HttpResponseHeaders(status);
auto* headers = new net::HttpResponseHeaders(status);

headers->AddHeader(kCORSHeader);
info->headers = headers;
Expand Down
2 changes: 1 addition & 1 deletion atom/browser/net/url_request_buffer_job.cc
Expand Up @@ -72,7 +72,7 @@ void URLRequestBufferJob::GetResponseInfo(net::HttpResponseInfo* info) {
status.append(" ");
status.append(net::GetHttpReasonPhrase(status_code_));
status.append("\0\0", 2);
net::HttpResponseHeaders* headers = new net::HttpResponseHeaders(status);
auto* headers = new net::HttpResponseHeaders(status);

headers->AddHeader(kCORSHeader);

Expand Down
2 changes: 1 addition & 1 deletion atom/browser/net/url_request_string_job.cc
Expand Up @@ -31,7 +31,7 @@ void URLRequestStringJob::StartAsync(std::unique_ptr<base::Value> options) {

void URLRequestStringJob::GetResponseInfo(net::HttpResponseInfo* info) {
std::string status("HTTP/1.1 200 OK");
net::HttpResponseHeaders* headers = new net::HttpResponseHeaders(status);
auto* headers = new net::HttpResponseHeaders(status);

headers->AddHeader(kCORSHeader);

Expand Down
4 changes: 2 additions & 2 deletions atom/browser/relauncher_mac.cc
Expand Up @@ -43,7 +43,7 @@ void RelauncherSynchronizeWithParent() {

struct kevent change = { 0 };
EV_SET(&change, parent_pid, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL);
if (kevent(kq.get(), &change, 1, NULL, 0, NULL) == -1) {
if (kevent(kq.get(), &change, 1, nullptr, 0, nullptr) == -1) {
PLOG(ERROR) << "kevent (add)";
return;
}
Expand All @@ -58,7 +58,7 @@ void RelauncherSynchronizeWithParent() {
// write above to complete. The parent process is now free to exit. Wait for
// that to happen.
struct kevent event;
int events = kevent(kq.get(), NULL, 0, &event, 1, NULL);
int events = kevent(kq.get(), nullptr, 0, &event, 1, nullptr);
if (events != 1) {
if (events < 0) {
PLOG(ERROR) << "kevent (monitor)";
Expand Down
4 changes: 2 additions & 2 deletions atom/browser/ui/accelerator_util.cc
Expand Up @@ -30,9 +30,9 @@ bool StringToAccelerator(const std::string& shortcut,
// Now, parse it into an accelerator.
int modifiers = ui::EF_NONE;
ui::KeyboardCode key = ui::VKEY_UNKNOWN;
for (size_t i = 0; i < tokens.size(); i++) {
for (const auto& token : tokens) {
bool shifted = false;
ui::KeyboardCode code = atom::KeyboardCodeFromStr(tokens[i], &shifted);
ui::KeyboardCode code = atom::KeyboardCodeFromStr(token, &shifted);
if (shifted)
modifiers |= ui::EF_SHIFT_DOWN;
switch (code) {
Expand Down
6 changes: 3 additions & 3 deletions atom/browser/window_list.cc
Expand Up @@ -17,7 +17,7 @@ base::LazyInstance<base::ObserverList<WindowListObserver>>::Leaky
WindowList::observers_ = LAZY_INSTANCE_INITIALIZER;

// static
WindowList* WindowList::instance_ = NULL;
WindowList* WindowList::instance_ = nullptr;

// static
WindowList* WindowList::GetInstance() {
Expand Down Expand Up @@ -70,8 +70,8 @@ void WindowList::RemoveObserver(WindowListObserver* observer) {
// static
void WindowList::CloseAllWindows() {
WindowVector windows = GetInstance()->windows_;
for (size_t i = 0; i < windows.size(); ++i)
windows[i]->Close();
for (const auto& window : windows)
window->Close();
}

WindowList::WindowList() {
Expand Down
6 changes: 3 additions & 3 deletions atom/common/api/atom_api_native_image.cc
Expand Up @@ -63,10 +63,10 @@ float GetScaleFactorFromPath(const base::FilePath& path) {

// We don't try to convert string to float here because it is very very
// expensive.
for (unsigned i = 0; i < node::arraysize(kScaleFactorPairs); ++i) {
if (base::EndsWith(filename, kScaleFactorPairs[i].name,
for (const auto& kScaleFactorPair : kScaleFactorPairs) {
if (base::EndsWith(filename, kScaleFactorPair.name,
base::CompareCase::INSENSITIVE_ASCII))
return kScaleFactorPairs[i].scale;
return kScaleFactorPair.scale;
}

return 1.0f;
Expand Down
2 changes: 1 addition & 1 deletion atom/common/api/atom_bindings.cc
Expand Up @@ -25,7 +25,7 @@ namespace {
struct DummyClass { bool crash; };

void Crash() {
static_cast<DummyClass*>(NULL)->crash = true;
static_cast<DummyClass*>(nullptr)->crash = true;
}

void Hang() {
Expand Down
6 changes: 3 additions & 3 deletions atom/common/asar/archive.cc
Expand Up @@ -41,7 +41,7 @@ bool GetFilesNode(const base::DictionaryValue* root,
// Test for symbol linked directory.
std::string link;
if (dir->GetStringWithoutPathExpansion("link", &link)) {
const base::DictionaryValue* linked_node = NULL;
const base::DictionaryValue* linked_node = nullptr;
if (!GetNodeFromPath(link, root, &linked_node))
return false;
dir = linked_node;
Expand All @@ -60,7 +60,7 @@ bool GetChildNode(const base::DictionaryValue* root,
return true;
}

const base::DictionaryValue* files = NULL;
const base::DictionaryValue* files = nullptr;
return GetFilesNode(root, dir, &files) &&
files->GetDictionaryWithoutPathExpansion(name, out);
}
Expand All @@ -78,7 +78,7 @@ bool GetNodeFromPath(std::string path,
for (size_t delimiter_position = path.find_first_of(kSeparators);
delimiter_position != std::string::npos;
delimiter_position = path.find_first_of(kSeparators)) {
const base::DictionaryValue* child = NULL;
const base::DictionaryValue* child = nullptr;
if (!GetChildNode(root, path.substr(0, delimiter_position), dir, &child))
return false;

Expand Down
2 changes: 1 addition & 1 deletion atom/common/native_mate_converters/callback.cc
Expand Up @@ -123,7 +123,7 @@ v8::Local<v8::Value> CreateFunctionFromTranslater(

v8::Local<v8::FunctionTemplate> call_translater =
v8::Local<v8::FunctionTemplate>::New(isolate, g_call_translater);
TranslaterHolder* holder = new TranslaterHolder;
auto* holder = new TranslaterHolder;
holder->translater = translater;
return BindFunctionWith(isolate,
isolate->GetCurrentContext(),
Expand Down