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