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 <list> | 10 #include <list> |
| 11 #include <memory> |
11 #include <string> | 12 #include <string> |
12 #include <utility> | 13 #include <utility> |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
15 #include "base/base64.h" | 16 #include "base/base64.h" |
16 #include "base/bind.h" | 17 #include "base/bind.h" |
17 #include "base/bind_helpers.h" | 18 #include "base/bind_helpers.h" |
18 #include "base/command_line.h" | 19 #include "base/command_line.h" |
19 #include "base/files/file.h" | 20 #include "base/files/file.h" |
20 #include "base/files/file_path.h" | 21 #include "base/files/file_path.h" |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 friend class base::DeleteHelper<IOThreadImpl>; | 321 friend class base::DeleteHelper<IOThreadImpl>; |
321 | 322 |
322 typedef std::list<scoped_refptr<net::URLRequestContextGetter> > | 323 typedef std::list<scoped_refptr<net::URLRequestContextGetter> > |
323 ContextGetterList; | 324 ContextGetterList; |
324 | 325 |
325 ~IOThreadImpl() override; | 326 ~IOThreadImpl() override; |
326 | 327 |
327 // Adds |entry| to the queue of pending log entries to be sent to the page via | 328 // Adds |entry| to the queue of pending log entries to be sent to the page via |
328 // Javascript. Must be called on the IO Thread. Also creates a delayed task | 329 // Javascript. Must be called on the IO Thread. Also creates a delayed task |
329 // that will call PostPendingEntries, if there isn't one already. | 330 // that will call PostPendingEntries, if there isn't one already. |
330 void AddEntryToQueue(base::Value* entry); | 331 void AddEntryToQueue(std::unique_ptr<base::Value> entry); |
331 | 332 |
332 // Sends all pending entries to the page via Javascript, and clears the list | 333 // Sends all pending entries to the page via Javascript, and clears the list |
333 // of pending entries. Sending multiple entries at once results in a | 334 // of pending entries. Sending multiple entries at once results in a |
334 // significant reduction of CPU usage when a lot of events are happening. | 335 // significant reduction of CPU usage when a lot of events are happening. |
335 // Must be called on the IO Thread. | 336 // Must be called on the IO Thread. |
336 void PostPendingEntries(); | 337 void PostPendingEntries(); |
337 | 338 |
338 // Adds entries with the states of ongoing URL requests. | 339 // Adds entries with the states of ongoing URL requests. |
339 void PrePopulateEventList(); | 340 void PrePopulateEventList(); |
340 | 341 |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 extensions::ExtensionSystem* extension_system = | 581 extensions::ExtensionSystem* extension_system = |
581 extensions::ExtensionSystem::Get(profile); | 582 extensions::ExtensionSystem::Get(profile); |
582 if (extension_system) { | 583 if (extension_system) { |
583 ExtensionService* extension_service = extension_system->extension_service(); | 584 ExtensionService* extension_service = extension_system->extension_service(); |
584 if (extension_service) { | 585 if (extension_service) { |
585 std::unique_ptr<const extensions::ExtensionSet> extensions( | 586 std::unique_ptr<const extensions::ExtensionSet> extensions( |
586 extensions::ExtensionRegistry::Get(profile) | 587 extensions::ExtensionRegistry::Get(profile) |
587 ->GenerateInstalledExtensionsSet()); | 588 ->GenerateInstalledExtensionsSet()); |
588 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); | 589 for (extensions::ExtensionSet::const_iterator it = extensions->begin(); |
589 it != extensions->end(); ++it) { | 590 it != extensions->end(); ++it) { |
590 base::DictionaryValue* extension_info = new base::DictionaryValue(); | 591 std::unique_ptr<base::DictionaryValue> extension_info( |
| 592 new base::DictionaryValue()); |
591 bool enabled = extension_service->IsExtensionEnabled((*it)->id()); | 593 bool enabled = extension_service->IsExtensionEnabled((*it)->id()); |
592 extensions::GetExtensionBasicInfo(it->get(), enabled, extension_info); | 594 extensions::GetExtensionBasicInfo(it->get(), enabled, |
593 extension_list->Append(extension_info); | 595 extension_info.get()); |
| 596 extension_list->Append(std::move(extension_info)); |
594 } | 597 } |
595 } | 598 } |
596 } | 599 } |
597 #endif | 600 #endif |
598 SendJavascriptCommand("receivedExtensionInfo", extension_list); | 601 SendJavascriptCommand("receivedExtensionInfo", extension_list); |
599 } | 602 } |
600 | 603 |
601 void NetInternalsMessageHandler::OnGetDataReductionProxyInfo( | 604 void NetInternalsMessageHandler::OnGetDataReductionProxyInfo( |
602 const base::ListValue* list) { | 605 const base::ListValue* list) { |
603 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 606 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 NOTREACHED(); | 1097 NOTREACHED(); |
1095 } | 1098 } |
1096 | 1099 |
1097 net_log()->SetObserverCaptureMode(this, mode); | 1100 net_log()->SetObserverCaptureMode(this, mode); |
1098 } | 1101 } |
1099 | 1102 |
1100 // Note that unlike other methods of IOThreadImpl, this function | 1103 // Note that unlike other methods of IOThreadImpl, this function |
1101 // can be called from ANY THREAD. | 1104 // can be called from ANY THREAD. |
1102 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( | 1105 void NetInternalsMessageHandler::IOThreadImpl::OnAddEntry( |
1103 const net::NetLog::Entry& entry) { | 1106 const net::NetLog::Entry& entry) { |
1104 BrowserThread::PostTask( | 1107 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
1105 BrowserThread::IO, FROM_HERE, | 1108 base::Bind(&IOThreadImpl::AddEntryToQueue, this, |
1106 base::Bind(&IOThreadImpl::AddEntryToQueue, this, entry.ToValue())); | 1109 base::Passed(entry.ToValue()))); |
1107 } | 1110 } |
1108 | 1111 |
1109 // Note that this can be called from ANY THREAD. | 1112 // Note that this can be called from ANY THREAD. |
1110 void NetInternalsMessageHandler::IOThreadImpl::SendJavascriptCommand( | 1113 void NetInternalsMessageHandler::IOThreadImpl::SendJavascriptCommand( |
1111 const std::string& command, | 1114 const std::string& command, |
1112 base::Value* arg) { | 1115 base::Value* arg) { |
1113 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 1116 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
1114 if (handler_.get() && !was_webui_deleted_) { | 1117 if (handler_.get() && !was_webui_deleted_) { |
1115 // We check |handler_| in case it was deleted on the UI thread earlier | 1118 // We check |handler_| in case it was deleted on the UI thread earlier |
1116 // while we were running on the IO thread. | 1119 // while we were running on the IO thread. |
1117 handler_->SendJavascriptCommand(command, arg); | 1120 handler_->SendJavascriptCommand(command, arg); |
1118 } else { | 1121 } else { |
1119 delete arg; | 1122 delete arg; |
1120 } | 1123 } |
1121 return; | 1124 return; |
1122 } | 1125 } |
1123 | 1126 |
1124 if (!BrowserThread::PostTask( | 1127 if (!BrowserThread::PostTask( |
1125 BrowserThread::UI, FROM_HERE, | 1128 BrowserThread::UI, FROM_HERE, |
1126 base::Bind(&IOThreadImpl::SendJavascriptCommand, this, command, arg))) { | 1129 base::Bind(&IOThreadImpl::SendJavascriptCommand, this, command, arg))) { |
1127 // Failed posting the task, avoid leaking. | 1130 // Failed posting the task, avoid leaking. |
1128 delete arg; | 1131 delete arg; |
1129 } | 1132 } |
1130 } | 1133 } |
1131 | 1134 |
1132 void NetInternalsMessageHandler::IOThreadImpl::AddEntryToQueue( | 1135 void NetInternalsMessageHandler::IOThreadImpl::AddEntryToQueue( |
1133 base::Value* entry) { | 1136 std::unique_ptr<base::Value> entry) { |
1134 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1137 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1135 if (!pending_entries_.get()) { | 1138 if (!pending_entries_.get()) { |
1136 pending_entries_.reset(new base::ListValue()); | 1139 pending_entries_.reset(new base::ListValue()); |
1137 BrowserThread::PostDelayedTask( | 1140 BrowserThread::PostDelayedTask( |
1138 BrowserThread::IO, FROM_HERE, | 1141 BrowserThread::IO, FROM_HERE, |
1139 base::Bind(&IOThreadImpl::PostPendingEntries, this), | 1142 base::Bind(&IOThreadImpl::PostPendingEntries, this), |
1140 base::TimeDelta::FromMilliseconds(kNetLogEventDelayMilliseconds)); | 1143 base::TimeDelta::FromMilliseconds(kNetLogEventDelayMilliseconds)); |
1141 } | 1144 } |
1142 pending_entries_->Append(entry); | 1145 pending_entries_->Append(std::move(entry)); |
1143 } | 1146 } |
1144 | 1147 |
1145 void NetInternalsMessageHandler::IOThreadImpl::PostPendingEntries() { | 1148 void NetInternalsMessageHandler::IOThreadImpl::PostPendingEntries() { |
1146 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1149 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1147 if (pending_entries_.get()) | 1150 if (pending_entries_.get()) |
1148 SendJavascriptCommand("receivedLogEntries", pending_entries_.release()); | 1151 SendJavascriptCommand("receivedLogEntries", pending_entries_.release()); |
1149 } | 1152 } |
1150 | 1153 |
1151 void NetInternalsMessageHandler::IOThreadImpl::PrePopulateEventList() { | 1154 void NetInternalsMessageHandler::IOThreadImpl::PrePopulateEventList() { |
1152 // Using a set removes any duplicates. | 1155 // Using a set removes any duplicates. |
(...skipping 26 matching lines...) Expand all Loading... |
1179 //////////////////////////////////////////////////////////////////////////////// | 1182 //////////////////////////////////////////////////////////////////////////////// |
1180 | 1183 |
1181 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) | 1184 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) |
1182 : WebUIController(web_ui) { | 1185 : WebUIController(web_ui) { |
1183 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); | 1186 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); |
1184 | 1187 |
1185 // Set up the chrome://net-internals/ source. | 1188 // Set up the chrome://net-internals/ source. |
1186 Profile* profile = Profile::FromWebUI(web_ui); | 1189 Profile* profile = Profile::FromWebUI(web_ui); |
1187 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); | 1190 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); |
1188 } | 1191 } |
OLD | NEW |