| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_ui.h" | 5 #include "chrome/browser/ui/webui/net_internals_ui.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #include "net/http/http_network_session.h" | 55 #include "net/http/http_network_session.h" |
| 56 #include "net/http/http_stream_factory.h" | 56 #include "net/http/http_stream_factory.h" |
| 57 #include "net/proxy/proxy_service.h" | 57 #include "net/proxy/proxy_service.h" |
| 58 #include "net/url_request/url_request_context.h" | 58 #include "net/url_request/url_request_context.h" |
| 59 #include "net/url_request/url_request_context_getter.h" | 59 #include "net/url_request/url_request_context_getter.h" |
| 60 #include "ui/base/l10n/l10n_util.h" | 60 #include "ui/base/l10n/l10n_util.h" |
| 61 #include "ui/base/resource/resource_bundle.h" | 61 #include "ui/base/resource/resource_bundle.h" |
| 62 | 62 |
| 63 #ifdef OS_CHROMEOS | 63 #ifdef OS_CHROMEOS |
| 64 #include "chrome/browser/chromeos/cros/cros_library.h" | 64 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 65 #include "chrome/browser/chromeos/system_access.h" | 65 #include "chrome/browser/chromeos/system/syslogs_provider.h" |
| 66 #endif | 66 #endif |
| 67 #ifdef OS_WIN | 67 #ifdef OS_WIN |
| 68 #include "chrome/browser/net/service_providers_win.h" | 68 #include "chrome/browser/net/service_providers_win.h" |
| 69 #endif | 69 #endif |
| 70 | 70 |
| 71 namespace { | 71 namespace { |
| 72 | 72 |
| 73 // Delay between when an event occurs and when it is passed to the Javascript | 73 // Delay between when an event occurs and when it is passed to the Javascript |
| 74 // page. All events that occur during this period are grouped together and | 74 // page. All events that occur during this period are grouped together and |
| 75 // sent to the page at once, which reduces context switching and CPU usage. | 75 // sent to the page at once, which reduces context switching and CPU usage. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 // Class that is used for getting network related ChromeOS logs. | 186 // Class that is used for getting network related ChromeOS logs. |
| 187 // Logs are fetched from ChromeOS libcros on user request, and only when we | 187 // Logs are fetched from ChromeOS libcros on user request, and only when we |
| 188 // don't yet have a copy of logs. If a copy is present, we send back data from | 188 // don't yet have a copy of logs. If a copy is present, we send back data from |
| 189 // it, else we save request and answer to it when we get logs from libcros. | 189 // it, else we save request and answer to it when we get logs from libcros. |
| 190 // If needed, we also send request for system logs to libcros. | 190 // If needed, we also send request for system logs to libcros. |
| 191 // Logs refresh has to be done explicitly, by deleting old logs and then | 191 // Logs refresh has to be done explicitly, by deleting old logs and then |
| 192 // loading them again. | 192 // loading them again. |
| 193 class SystemLogsGetter { | 193 class SystemLogsGetter { |
| 194 public: | 194 public: |
| 195 SystemLogsGetter(NetInternalsMessageHandler* handler, | 195 SystemLogsGetter(NetInternalsMessageHandler* handler, |
| 196 chromeos::SystemAccess* system_access); | 196 chromeos::system::SyslogsProvider* syslogs_provider); |
| 197 ~SystemLogsGetter(); | 197 ~SystemLogsGetter(); |
| 198 | 198 |
| 199 // Deletes logs copy we currently have, and resets logs_requested and | 199 // Deletes logs copy we currently have, and resets logs_requested and |
| 200 // logs_received flags. | 200 // logs_received flags. |
| 201 void DeleteSystemLogs(); | 201 void DeleteSystemLogs(); |
| 202 // Starts log fetching. If logs copy is present, requested logs are sent | 202 // Starts log fetching. If logs copy is present, requested logs are sent |
| 203 // back. | 203 // back. |
| 204 // If syslogs load request hasn't been sent to libcros yet, we do that now, | 204 // If syslogs load request hasn't been sent to libcros yet, we do that now, |
| 205 // and postpone sending response. | 205 // and postpone sending response. |
| 206 // Request data is specified by args: | 206 // Request data is specified by args: |
| 207 // $1 : key of the log we are interested in. | 207 // $1 : key of the log we are interested in. |
| 208 // $2 : string used to identify request. | 208 // $2 : string used to identify request. |
| 209 void RequestSystemLog(const ListValue* args); | 209 void RequestSystemLog(const ListValue* args); |
| 210 // Requests logs from libcros, but only if we don't have a copy. | 210 // Requests logs from libcros, but only if we don't have a copy. |
| 211 void LoadSystemLogs(); | 211 void LoadSystemLogs(); |
| 212 // Processes callback from libcros containing system logs. Postponed | 212 // Processes callback from libcros containing system logs. Postponed |
| 213 // request responses are sent. | 213 // request responses are sent. |
| 214 void OnSystemLogsLoaded(chromeos::LogDictionaryType* sys_info, | 214 void OnSystemLogsLoaded(chromeos::system::LogDictionaryType* sys_info, |
| 215 std::string* ignored_content); | 215 std::string* ignored_content); |
| 216 | 216 |
| 217 private: | 217 private: |
| 218 // Struct we save postponed log request in. | 218 // Struct we save postponed log request in. |
| 219 struct SystemLogRequest { | 219 struct SystemLogRequest { |
| 220 std::string log_key; | 220 std::string log_key; |
| 221 std::string cell_id; | 221 std::string cell_id; |
| 222 }; | 222 }; |
| 223 | 223 |
| 224 // Processes request. | 224 // Processes request. |
| 225 void SendLogs(const SystemLogRequest& request); | 225 void SendLogs(const SystemLogRequest& request); |
| 226 | 226 |
| 227 NetInternalsMessageHandler* handler_; | 227 NetInternalsMessageHandler* handler_; |
| 228 chromeos::SystemAccess* system_access_; | 228 chromeos::system::SyslogsProvider* syslogs_provider_; |
| 229 // List of postponed requests. | 229 // List of postponed requests. |
| 230 std::list<SystemLogRequest> requests_; | 230 std::list<SystemLogRequest> requests_; |
| 231 scoped_ptr<chromeos::LogDictionaryType> logs_; | 231 scoped_ptr<chromeos::system::LogDictionaryType> logs_; |
| 232 bool logs_received_; | 232 bool logs_received_; |
| 233 bool logs_requested_; | 233 bool logs_requested_; |
| 234 CancelableRequestConsumer consumer_; | 234 CancelableRequestConsumer consumer_; |
| 235 // Libcros request handle. | 235 // Libcros request handle. |
| 236 CancelableRequestProvider::Handle syslogs_request_id_; | 236 CancelableRequestProvider::Handle syslogs_request_id_; |
| 237 }; | 237 }; |
| 238 #endif | 238 #endif |
| 239 | 239 |
| 240 // The pref member about whether HTTP throttling is enabled, which needs to | 240 // The pref member about whether HTTP throttling is enabled, which needs to |
| 241 // be accessed on the UI thread. | 241 // be accessed on the UI thread. |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 PrefService* pref_service = web_ui->GetProfile()->GetPrefs(); | 518 PrefService* pref_service = web_ui->GetProfile()->GetPrefs(); |
| 519 http_throttling_enabled_.Init( | 519 http_throttling_enabled_.Init( |
| 520 prefs::kHttpThrottlingEnabled, pref_service, this); | 520 prefs::kHttpThrottlingEnabled, pref_service, this); |
| 521 http_throttling_may_experiment_.Init( | 521 http_throttling_may_experiment_.Init( |
| 522 prefs::kHttpThrottlingMayExperiment, pref_service, NULL); | 522 prefs::kHttpThrottlingMayExperiment, pref_service, NULL); |
| 523 | 523 |
| 524 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(), | 524 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(), |
| 525 web_ui->GetProfile()->GetRequestContext()); | 525 web_ui->GetProfile()->GetRequestContext()); |
| 526 #ifdef OS_CHROMEOS | 526 #ifdef OS_CHROMEOS |
| 527 syslogs_getter_.reset(new SystemLogsGetter(this, | 527 syslogs_getter_.reset(new SystemLogsGetter(this, |
| 528 chromeos::SystemAccess::GetInstance())); | 528 chromeos::system::SyslogsProvider::GetInstance())); |
| 529 #endif | 529 #endif |
| 530 renderer_ready_io_callback_.reset( | 530 renderer_ready_io_callback_.reset( |
| 531 proxy_->CreateCallback(&IOThreadImpl::OnRendererReady)); | 531 proxy_->CreateCallback(&IOThreadImpl::OnRendererReady)); |
| 532 | 532 |
| 533 prerender::PrerenderManager* prerender_manager = | 533 prerender::PrerenderManager* prerender_manager = |
| 534 web_ui->GetProfile()->GetPrerenderManager(); | 534 web_ui->GetProfile()->GetPrerenderManager(); |
| 535 if (prerender_manager) { | 535 if (prerender_manager) { |
| 536 prerender_manager_ = prerender_manager->AsWeakPtr(); | 536 prerender_manager_ = prerender_manager->AsWeakPtr(); |
| 537 } else { | 537 } else { |
| 538 prerender_manager_ = base::WeakPtr<prerender::PrerenderManager>(); | 538 prerender_manager_ = base::WeakPtr<prerender::PrerenderManager>(); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 | 703 |
| 704 #ifdef OS_CHROMEOS | 704 #ifdef OS_CHROMEOS |
| 705 //////////////////////////////////////////////////////////////////////////////// | 705 //////////////////////////////////////////////////////////////////////////////// |
| 706 // | 706 // |
| 707 // NetInternalsMessageHandler::SystemLogsGetter | 707 // NetInternalsMessageHandler::SystemLogsGetter |
| 708 // | 708 // |
| 709 //////////////////////////////////////////////////////////////////////////////// | 709 //////////////////////////////////////////////////////////////////////////////// |
| 710 | 710 |
| 711 NetInternalsMessageHandler::SystemLogsGetter::SystemLogsGetter( | 711 NetInternalsMessageHandler::SystemLogsGetter::SystemLogsGetter( |
| 712 NetInternalsMessageHandler* handler, | 712 NetInternalsMessageHandler* handler, |
| 713 chromeos::SystemAccess* system_access) | 713 chromeos::system::SyslogsProvider* syslogs_provider) |
| 714 : handler_(handler), | 714 : handler_(handler), |
| 715 system_access_(system_access), | 715 syslogs_provider_(syslogs_provider), |
| 716 logs_(NULL), | 716 logs_(NULL), |
| 717 logs_received_(false), | 717 logs_received_(false), |
| 718 logs_requested_(false) { | 718 logs_requested_(false) { |
| 719 if (!system_access_) | 719 if (!syslogs_provider_) |
| 720 LOG(ERROR) << "System access library not loaded"; | 720 LOG(ERROR) << "System access library not loaded"; |
| 721 } | 721 } |
| 722 | 722 |
| 723 NetInternalsMessageHandler::SystemLogsGetter::~SystemLogsGetter() { | 723 NetInternalsMessageHandler::SystemLogsGetter::~SystemLogsGetter() { |
| 724 DeleteSystemLogs(); | 724 DeleteSystemLogs(); |
| 725 } | 725 } |
| 726 | 726 |
| 727 void NetInternalsMessageHandler::SystemLogsGetter::DeleteSystemLogs() { | 727 void NetInternalsMessageHandler::SystemLogsGetter::DeleteSystemLogs() { |
| 728 if (system_access_ && logs_requested_ && !logs_received_) { | 728 if (syslogs_provider_ && logs_requested_ && !logs_received_) { |
| 729 system_access_->CancelRequest(syslogs_request_id_); | 729 syslogs_provider_->CancelRequest(syslogs_request_id_); |
| 730 } | 730 } |
| 731 logs_requested_ = false; | 731 logs_requested_ = false; |
| 732 logs_received_ = false; | 732 logs_received_ = false; |
| 733 logs_.reset(); | 733 logs_.reset(); |
| 734 } | 734 } |
| 735 | 735 |
| 736 void NetInternalsMessageHandler::SystemLogsGetter::RequestSystemLog( | 736 void NetInternalsMessageHandler::SystemLogsGetter::RequestSystemLog( |
| 737 const ListValue* args) { | 737 const ListValue* args) { |
| 738 if (!logs_requested_) { | 738 if (!logs_requested_) { |
| 739 DCHECK(!logs_received_); | 739 DCHECK(!logs_received_); |
| 740 LoadSystemLogs(); | 740 LoadSystemLogs(); |
| 741 } | 741 } |
| 742 SystemLogRequest log_request; | 742 SystemLogRequest log_request; |
| 743 args->GetString(0, &log_request.log_key); | 743 args->GetString(0, &log_request.log_key); |
| 744 args->GetString(1, &log_request.cell_id); | 744 args->GetString(1, &log_request.cell_id); |
| 745 | 745 |
| 746 if (logs_received_) { | 746 if (logs_received_) { |
| 747 SendLogs(log_request); | 747 SendLogs(log_request); |
| 748 } else { | 748 } else { |
| 749 requests_.push_back(log_request); | 749 requests_.push_back(log_request); |
| 750 } | 750 } |
| 751 } | 751 } |
| 752 | 752 |
| 753 void NetInternalsMessageHandler::SystemLogsGetter::LoadSystemLogs() { | 753 void NetInternalsMessageHandler::SystemLogsGetter::LoadSystemLogs() { |
| 754 if (logs_requested_ || !system_access_) | 754 if (logs_requested_ || !syslogs_provider_) |
| 755 return; | 755 return; |
| 756 logs_requested_ = true; | 756 logs_requested_ = true; |
| 757 syslogs_request_id_ = system_access_->RequestSyslogs( | 757 syslogs_request_id_ = syslogs_provider_->RequestSyslogs( |
| 758 false, // compress logs. | 758 false, // compress logs. |
| 759 chromeos::SystemAccess::SYSLOGS_NETWORK, | 759 chromeos::system::SyslogsProvider::SYSLOGS_NETWORK, |
| 760 &consumer_, | 760 &consumer_, |
| 761 NewCallback( | 761 NewCallback( |
| 762 this, | 762 this, |
| 763 &NetInternalsMessageHandler::SystemLogsGetter::OnSystemLogsLoaded)); | 763 &NetInternalsMessageHandler::SystemLogsGetter::OnSystemLogsLoaded)); |
| 764 } | 764 } |
| 765 | 765 |
| 766 void NetInternalsMessageHandler::SystemLogsGetter::OnSystemLogsLoaded( | 766 void NetInternalsMessageHandler::SystemLogsGetter::OnSystemLogsLoaded( |
| 767 chromeos::LogDictionaryType* sys_info, std::string* ignored_content) { | 767 chromeos::system::LogDictionaryType* sys_info, |
| 768 std::string* ignored_content) { |
| 768 DCHECK(!ignored_content); | 769 DCHECK(!ignored_content); |
| 769 logs_.reset(sys_info); | 770 logs_.reset(sys_info); |
| 770 logs_received_ = true; | 771 logs_received_ = true; |
| 771 for (std::list<SystemLogRequest>::iterator request_it = requests_.begin(); | 772 for (std::list<SystemLogRequest>::iterator request_it = requests_.begin(); |
| 772 request_it != requests_.end(); | 773 request_it != requests_.end(); |
| 773 ++request_it) { | 774 ++request_it) { |
| 774 SendLogs(*request_it); | 775 SendLogs(*request_it); |
| 775 } | 776 } |
| 776 requests_.clear(); | 777 requests_.clear(); |
| 777 } | 778 } |
| 778 | 779 |
| 779 void NetInternalsMessageHandler::SystemLogsGetter::SendLogs( | 780 void NetInternalsMessageHandler::SystemLogsGetter::SendLogs( |
| 780 const SystemLogRequest& request) { | 781 const SystemLogRequest& request) { |
| 781 DictionaryValue* result = new DictionaryValue(); | 782 DictionaryValue* result = new DictionaryValue(); |
| 782 chromeos::LogDictionaryType::iterator log_it = logs_->find(request.log_key); | 783 chromeos::system::LogDictionaryType::iterator log_it = |
| 784 logs_->find(request.log_key); |
| 783 if (log_it != logs_->end()) { | 785 if (log_it != logs_->end()) { |
| 784 if (!log_it->second.empty()) { | 786 if (!log_it->second.empty()) { |
| 785 result->SetString("log", log_it->second); | 787 result->SetString("log", log_it->second); |
| 786 } else { | 788 } else { |
| 787 result->SetString("log", "<no relevant lines found>"); | 789 result->SetString("log", "<no relevant lines found>"); |
| 788 } | 790 } |
| 789 } else { | 791 } else { |
| 790 result->SetString("log", "<invalid log name>"); | 792 result->SetString("log", "<invalid log name>"); |
| 791 } | 793 } |
| 792 result->SetString("cellId", request.cell_id); | 794 result->SetString("cellId", request.cell_id); |
| (...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1594 //////////////////////////////////////////////////////////////////////////////// | 1596 //////////////////////////////////////////////////////////////////////////////// |
| 1595 | 1597 |
| 1596 NetInternalsUI::NetInternalsUI(TabContents* contents) : ChromeWebUI(contents) { | 1598 NetInternalsUI::NetInternalsUI(TabContents* contents) : ChromeWebUI(contents) { |
| 1597 AddMessageHandler((new NetInternalsMessageHandler())->Attach(this)); | 1599 AddMessageHandler((new NetInternalsMessageHandler())->Attach(this)); |
| 1598 | 1600 |
| 1599 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); | 1601 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); |
| 1600 | 1602 |
| 1601 // Set up the chrome://net-internals/ source. | 1603 // Set up the chrome://net-internals/ source. |
| 1602 GetProfile()->GetChromeURLDataManager()->AddDataSource(html_source); | 1604 GetProfile()->GetChromeURLDataManager()->AddDataSource(html_source); |
| 1603 } | 1605 } |
| OLD | NEW |