OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h" | 5 #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 // | 367 // |
368 //////////////////////////////////////////////////////////////////////////////// | 368 //////////////////////////////////////////////////////////////////////////////// |
369 | 369 |
370 NetInternalsMessageHandler::NetInternalsMessageHandler() {} | 370 NetInternalsMessageHandler::NetInternalsMessageHandler() {} |
371 | 371 |
372 NetInternalsMessageHandler::~NetInternalsMessageHandler() { | 372 NetInternalsMessageHandler::~NetInternalsMessageHandler() { |
373 if (proxy_) { | 373 if (proxy_) { |
374 proxy_->OnWebUIDeleted(); | 374 proxy_->OnWebUIDeleted(); |
375 // Notify the handler on the IO thread that the renderer is gone. | 375 // Notify the handler on the IO thread that the renderer is gone. |
376 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 376 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
377 base::Bind(&IOThreadImpl::Detach, proxy_)); | 377 base::BindOnce(&IOThreadImpl::Detach, proxy_)); |
378 } | 378 } |
379 } | 379 } |
380 | 380 |
381 void NetInternalsMessageHandler::RegisterMessages() { | 381 void NetInternalsMessageHandler::RegisterMessages() { |
382 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 382 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
383 | 383 |
384 Profile* profile = Profile::FromWebUI(web_ui()); | 384 Profile* profile = Profile::FromWebUI(web_ui()); |
385 | 385 |
386 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(), | 386 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(), |
387 profile->GetRequestContext()); | 387 profile->GetRequestContext()); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 586 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
587 | 587 |
588 // We need to make a copy of the value in order to pass it over to the IO | 588 // We need to make a copy of the value in order to pass it over to the IO |
589 // thread. |list_copy| will be deleted when the task is destroyed. The called | 589 // thread. |list_copy| will be deleted when the task is destroyed. The called |
590 // |method| cannot take ownership of |list_copy|. | 590 // |method| cannot take ownership of |list_copy|. |
591 base::ListValue* list_copy = | 591 base::ListValue* list_copy = |
592 (list && list->GetSize()) ? list->DeepCopy() : nullptr; | 592 (list && list->GetSize()) ? list->DeepCopy() : nullptr; |
593 | 593 |
594 BrowserThread::PostTask( | 594 BrowserThread::PostTask( |
595 BrowserThread::IO, FROM_HERE, | 595 BrowserThread::IO, FROM_HERE, |
596 base::Bind(method, io_thread, base::Owned(list_copy))); | 596 base::BindOnce(method, io_thread, base::Owned(list_copy))); |
597 } | 597 } |
598 | 598 |
599 void NetInternalsMessageHandler::IOThreadImpl::Detach() { | 599 void NetInternalsMessageHandler::IOThreadImpl::Detach() { |
600 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 600 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
601 // Unregister with network stack to observe events. | 601 // Unregister with network stack to observe events. |
602 if (net_log()) | 602 if (net_log()) |
603 net_log()->DeprecatedRemoveObserver(this); | 603 net_log()->DeprecatedRemoveObserver(this); |
604 } | 604 } |
605 | 605 |
606 void NetInternalsMessageHandler::IOThreadImpl::OnWebUIDeleted() { | 606 void NetInternalsMessageHandler::IOThreadImpl::OnWebUIDeleted() { |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 } | 979 } |
980 | 980 |
981 net_log()->SetObserverCaptureMode(this, mode); | 981 net_log()->SetObserverCaptureMode(this, mode); |
982 } | 982 } |
983 | 983 |
984 // Note that unlike other methods of IOThreadImpl, this function | 984 // Note that unlike other methods of IOThreadImpl, this function |
985 // can be called from ANY THREAD. | 985 // can be called from ANY THREAD. |
986 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( | 986 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( |
987 const net::NetLogEntry& entry) { | 987 const net::NetLogEntry& entry) { |
988 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 988 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
989 base::Bind(&IOThreadImpl::AddEntryToQueue, this, | 989 base::BindOnce(&IOThreadImpl::AddEntryToQueue, this, |
990 base::Passed(entry.ToValue()))); | 990 base::Passed(entry.ToValue()))); |
991 } | 991 } |
992 | 992 |
993 // Note that this can be called from ANY THREAD. | 993 // Note that this can be called from ANY THREAD. |
994 void NetInternalsMessageHandler::IOThreadImpl::SendJavascriptCommand( | 994 void NetInternalsMessageHandler::IOThreadImpl::SendJavascriptCommand( |
995 const std::string& command, | 995 const std::string& command, |
996 std::unique_ptr<base::Value> arg) { | 996 std::unique_ptr<base::Value> arg) { |
997 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 997 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
998 if (handler_ && !was_webui_deleted_) { | 998 if (handler_ && !was_webui_deleted_) { |
999 // We check |handler_| in case it was deleted on the UI thread earlier | 999 // We check |handler_| in case it was deleted on the UI thread earlier |
1000 // while we were running on the IO thread. | 1000 // while we were running on the IO thread. |
1001 handler_->SendJavascriptCommand(command, std::move(arg)); | 1001 handler_->SendJavascriptCommand(command, std::move(arg)); |
1002 } | 1002 } |
1003 return; | 1003 return; |
1004 } | 1004 } |
1005 | 1005 |
1006 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 1006 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
1007 base::Bind(&IOThreadImpl::SendJavascriptCommand, this, | 1007 base::BindOnce(&IOThreadImpl::SendJavascriptCommand, |
1008 command, base::Passed(&arg))); | 1008 this, command, base::Passed(&arg))); |
1009 } | 1009 } |
1010 | 1010 |
1011 void NetInternalsMessageHandler::IOThreadImpl::AddEntryToQueue( | 1011 void NetInternalsMessageHandler::IOThreadImpl::AddEntryToQueue( |
1012 std::unique_ptr<base::Value> entry) { | 1012 std::unique_ptr<base::Value> entry) { |
1013 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1013 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1014 if (!pending_entries_) { | 1014 if (!pending_entries_) { |
1015 pending_entries_.reset(new base::ListValue()); | 1015 pending_entries_.reset(new base::ListValue()); |
1016 BrowserThread::PostDelayedTask( | 1016 BrowserThread::PostDelayedTask( |
1017 BrowserThread::IO, FROM_HERE, | 1017 BrowserThread::IO, FROM_HERE, |
1018 base::Bind(&IOThreadImpl::PostPendingEntries, this), | 1018 base::BindOnce(&IOThreadImpl::PostPendingEntries, this), |
1019 base::TimeDelta::FromMilliseconds(kNetLogEventDelayMilliseconds)); | 1019 base::TimeDelta::FromMilliseconds(kNetLogEventDelayMilliseconds)); |
1020 } | 1020 } |
1021 pending_entries_->Append(std::move(entry)); | 1021 pending_entries_->Append(std::move(entry)); |
1022 } | 1022 } |
1023 | 1023 |
1024 void NetInternalsMessageHandler::IOThreadImpl::PostPendingEntries() { | 1024 void NetInternalsMessageHandler::IOThreadImpl::PostPendingEntries() { |
1025 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1025 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1026 if (pending_entries_) | 1026 if (pending_entries_) |
1027 SendJavascriptCommand("receivedLogEntries", std::move(pending_entries_)); | 1027 SendJavascriptCommand("receivedLogEntries", std::move(pending_entries_)); |
1028 } | 1028 } |
(...skipping 26 matching lines...) Expand all Loading... |
1055 //////////////////////////////////////////////////////////////////////////////// | 1055 //////////////////////////////////////////////////////////////////////////////// |
1056 | 1056 |
1057 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) | 1057 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) |
1058 : WebUIController(web_ui) { | 1058 : WebUIController(web_ui) { |
1059 web_ui->AddMessageHandler(base::MakeUnique<NetInternalsMessageHandler>()); | 1059 web_ui->AddMessageHandler(base::MakeUnique<NetInternalsMessageHandler>()); |
1060 | 1060 |
1061 // Set up the chrome://net-internals/ source. | 1061 // Set up the chrome://net-internals/ source. |
1062 Profile* profile = Profile::FromWebUI(web_ui); | 1062 Profile* profile = Profile::FromWebUI(web_ui); |
1063 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); | 1063 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); |
1064 } | 1064 } |
OLD | NEW |