Merge pull request #6423 from electron/modernize-to-c11

Modernize to c++11
This commit is contained in:
Cheng Zhao 2016-07-11 09:03:03 +09:00 committed by GitHub
commit eae69f9728
27 changed files with 73 additions and 74 deletions

View file

@ -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);

View file

@ -21,7 +21,7 @@ namespace api {
Menu::Menu(v8::Isolate* isolate)
: model_(new AtomMenuModel(this)),
parent_(NULL) {
parent_(nullptr) {
}
Menu::~Menu() {

View file

@ -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;
}
@ -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);

View file

@ -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);
}

View file

@ -12,8 +12,8 @@
namespace mate {
Event::Event(v8::Isolate* isolate)
: sender_(NULL),
message_(NULL) {
: sender_(nullptr),
message_(nullptr) {
Init(isolate);
}
@ -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) {
@ -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;
}

View file

@ -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),

View file

@ -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);
@ -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() {
@ -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

View file

@ -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);
@ -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 {
@ -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;
@ -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);
}
@ -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);

View file

@ -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;
}

View file

@ -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_,
@ -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 {
@ -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;
@ -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);
}

View file

@ -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;
@ -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;
@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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);

View file

@ -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;
}
@ -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)";

View file

@ -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) {

View file

@ -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() {
@ -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() {

View file

@ -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;

View file

@ -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() {

View file

@ -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;
@ -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);
}
@ -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;

View file

@ -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(),

View file

@ -55,7 +55,7 @@ class V8ValueConverter::FromV8ValueState {
// hash. Different hash obviously means different objects, but two objects
// in a couple of thousands could have the same identity hash.
std::pair<Iterator, Iterator> range = unique_map_.equal_range(hash);
for (Iterator it = range.first; it != range.second; ++it) {
for (auto it = range.first; it != range.second; ++it) {
// Operator == for handles actually compares the underlying objects.
if (it->second == handle)
return false;
@ -162,7 +162,7 @@ v8::Local<v8::Value> V8ValueConverter::ToV8Array(
v8::Local<v8::Array> result(v8::Array::New(isolate, val->GetSize()));
for (size_t i = 0; i < val->GetSize(); ++i) {
const base::Value* child = NULL;
const base::Value* child = nullptr;
CHECK(val->Get(i, &child));
v8::Local<v8::Value> child_v8 = ToV8ValueImpl(isolate, child);
@ -214,7 +214,7 @@ base::Value* V8ValueConverter::FromV8ValueImpl(
FromV8ValueState::Level state_level(state);
if (state->HasReachedMaxRecursionDepth())
return NULL;
return nullptr;
if (val->IsNull())
return base::Value::CreateNullValue().release();
@ -235,7 +235,7 @@ base::Value* V8ValueConverter::FromV8ValueImpl(
if (val->IsUndefined())
// JSON.stringify ignores undefined.
return NULL;
return nullptr;
if (val->IsDate()) {
v8::Date* date = v8::Date::Cast(*val);
@ -265,7 +265,7 @@ base::Value* V8ValueConverter::FromV8ValueImpl(
if (val->IsFunction()) {
if (!function_allowed_)
// JSON.stringify refuses to convert function(){}.
return NULL;
return nullptr;
return FromV8Object(val->ToObject(), state, isolate);
}
@ -278,7 +278,7 @@ base::Value* V8ValueConverter::FromV8ValueImpl(
}
LOG(ERROR) << "Unexpected v8 value type encountered.";
return NULL;
return nullptr;
}
base::Value* V8ValueConverter::FromV8Array(
@ -295,7 +295,7 @@ base::Value* V8ValueConverter::FromV8Array(
val->CreationContext() != isolate->GetCurrentContext())
scope.reset(new v8::Context::Scope(val->CreationContext()));
base::ListValue* result = new base::ListValue();
auto* result = new base::ListValue();
// Only fields with integer keys are carried over to the ListValue.
for (uint32_t i = 0; i < val->Length(); ++i) {

View file

@ -54,7 +54,8 @@ void NodeBindingsMac::PollEvents() {
// Wait for new libuv events.
int r;
do {
r = select(fd + 1, &readset, NULL, NULL, timeout == -1 ? NULL : &tv);
r = select(fd + 1, &readset, nullptr, nullptr,
timeout == -1 ? nullptr : &tv);
} while (r == -1 && errno == EINTR);
}

View file

@ -20,11 +20,11 @@ namespace {
RenderView* GetCurrentRenderView() {
WebLocalFrame* frame = WebLocalFrame::frameForCurrentContext();
if (!frame)
return NULL;
return nullptr;
WebView* view = frame->view();
if (!view)
return NULL; // can happen during closing.
return nullptr; // can happen during closing.
return RenderView::FromWebView(view);
}
@ -33,7 +33,7 @@ void Send(mate::Arguments* args,
const base::string16& channel,
const base::ListValue& arguments) {
RenderView* render_view = GetCurrentRenderView();
if (render_view == NULL)
if (render_view == nullptr)
return;
bool success = render_view->Send(new AtomViewHostMsg_Message(
@ -49,7 +49,7 @@ base::string16 SendSync(mate::Arguments* args,
base::string16 json;
RenderView* render_view = GetCurrentRenderView();
if (render_view == NULL)
if (render_view == nullptr)
return json;
IPC::SyncMessage* message = new AtomViewHostMsg_Message_Sync(

View file

@ -39,7 +39,7 @@ class ScriptExecutionCallback : public blink::WebScriptExecutionCallback {
explicit ScriptExecutionCallback(const CompletionCallback& callback)
: callback_(callback) {}
~ScriptExecutionCallback() {}
~ScriptExecutionCallback() override {}
void completed(
const blink::WebVector<v8::Local<v8::Value>>& result) override {

View file

@ -132,10 +132,10 @@ void AtomRenderViewObserver::DraggableRegionsChanged(blink::WebFrame* frame) {
blink::WebVector<blink::WebDraggableRegion> webregions =
frame->document().draggableRegions();
std::vector<DraggableRegion> regions;
for (size_t i = 0; i < webregions.size(); ++i) {
for (const auto& webregion : webregions) {
DraggableRegion region;
region.bounds = webregions[i].bounds;
region.draggable = webregions[i].draggable;
region.bounds = webregion.bounds;
region.draggable = webregion.draggable;
regions.push_back(region);
}
Send(new AtomViewHostMsg_UpdateDraggableRegions(routing_id(), regions));

View file

@ -58,8 +58,7 @@ bool AtomContentUtilityClient::OnMessageReceived(
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
for (Handlers::iterator it = handlers_.begin();
!handled && it != handlers_.end(); ++it) {
for (auto it = handlers_.begin(); !handled && it != handlers_.end(); ++it) {
handled = (*it)->OnMessageReceived(message);
}