Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: chrome/browser/ui/webui/net_internals/net_internals_ui.cc

Issue 10185003: Remove net-internals page for throttling, introduce flag for extension devs instead. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix JavaScript presubmit. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/net_internals/main.js ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <list> 8 #include <list>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // Note that the WebUI infrastructure runs on the UI thread, therefore all of 239 // Note that the WebUI infrastructure runs on the UI thread, therefore all of
240 // this class's methods are expected to run on the UI thread. 240 // this class's methods are expected to run on the UI thread.
241 // 241 //
242 // Since the network code we want to run lives on the IO thread, we proxy 242 // Since the network code we want to run lives on the IO thread, we proxy
243 // almost everything over to NetInternalsMessageHandler::IOThreadImpl, which 243 // almost everything over to NetInternalsMessageHandler::IOThreadImpl, which
244 // runs on the IO thread. 244 // runs on the IO thread.
245 // 245 //
246 // TODO(eroman): Can we start on the IO thread to begin with? 246 // TODO(eroman): Can we start on the IO thread to begin with?
247 class NetInternalsMessageHandler 247 class NetInternalsMessageHandler
248 : public WebUIMessageHandler, 248 : public WebUIMessageHandler,
249 public base::SupportsWeakPtr<NetInternalsMessageHandler>, 249 public base::SupportsWeakPtr<NetInternalsMessageHandler> {
250 public content::NotificationObserver {
251 public: 250 public:
252 NetInternalsMessageHandler(); 251 NetInternalsMessageHandler();
253 virtual ~NetInternalsMessageHandler(); 252 virtual ~NetInternalsMessageHandler();
254 253
255 // WebUIMessageHandler implementation. 254 // WebUIMessageHandler implementation.
256 virtual void RegisterMessages() OVERRIDE; 255 virtual void RegisterMessages() OVERRIDE;
257 256
258 // Calls g_browser.receive in the renderer, passing in |command| and |arg|. 257 // Calls g_browser.receive in the renderer, passing in |command| and |arg|.
259 // Takes ownership of |arg|. If the renderer is displaying a log file, the 258 // Takes ownership of |arg|. If the renderer is displaying a log file, the
260 // message will be ignored. 259 // message will be ignored.
261 void SendJavascriptCommand(const std::string& command, Value* arg); 260 void SendJavascriptCommand(const std::string& command, Value* arg);
262 261
263 // content::NotificationObserver implementation.
264 virtual void Observe(int type,
265 const content::NotificationSource& source,
266 const content::NotificationDetails& details) OVERRIDE;
267
268 // Javascript message handlers. 262 // Javascript message handlers.
269 void OnRendererReady(const ListValue* list); 263 void OnRendererReady(const ListValue* list);
270 void OnEnableHttpThrottling(const ListValue* list);
271 void OnClearBrowserCache(const ListValue* list); 264 void OnClearBrowserCache(const ListValue* list);
272 void OnGetPrerenderInfo(const ListValue* list); 265 void OnGetPrerenderInfo(const ListValue* list);
273 #ifdef OS_CHROMEOS 266 #ifdef OS_CHROMEOS
274 void OnRefreshSystemLogs(const ListValue* list); 267 void OnRefreshSystemLogs(const ListValue* list);
275 void OnGetSystemLog(const ListValue* list); 268 void OnGetSystemLog(const ListValue* list);
276 void OnImportONCFile(const ListValue* list); 269 void OnImportONCFile(const ListValue* list);
277 void OnStoreDebugLogs(const ListValue* list); 270 void OnStoreDebugLogs(const ListValue* list);
278 void OnStoreDebugLogsCompleted(const FilePath& log_path, bool succeeded); 271 void OnStoreDebugLogsCompleted(const FilePath& log_path, bool succeeded);
279 void OnSetNetworkDebugMode(const ListValue* list); 272 void OnSetNetworkDebugMode(const ListValue* list);
280 void OnSetNetworkDebugModeCompleted(const std::string& subsystem, 273 void OnSetNetworkDebugModeCompleted(const std::string& subsystem,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 std::list<SystemLogRequest> requests_; 325 std::list<SystemLogRequest> requests_;
333 scoped_ptr<chromeos::system::LogDictionaryType> logs_; 326 scoped_ptr<chromeos::system::LogDictionaryType> logs_;
334 bool logs_received_; 327 bool logs_received_;
335 bool logs_requested_; 328 bool logs_requested_;
336 CancelableRequestConsumer consumer_; 329 CancelableRequestConsumer consumer_;
337 // Libcros request handle. 330 // Libcros request handle.
338 CancelableRequestProvider::Handle syslogs_request_id_; 331 CancelableRequestProvider::Handle syslogs_request_id_;
339 }; 332 };
340 #endif 333 #endif
341 334
342 // The pref member about whether HTTP throttling is enabled, which needs to
343 // be accessed on the UI thread.
344 BooleanPrefMember http_throttling_enabled_;
345
346 // This is the "real" message handler, which lives on the IO thread. 335 // This is the "real" message handler, which lives on the IO thread.
347 scoped_refptr<IOThreadImpl> proxy_; 336 scoped_refptr<IOThreadImpl> proxy_;
348 337
349 base::WeakPtr<prerender::PrerenderManager> prerender_manager_; 338 base::WeakPtr<prerender::PrerenderManager> prerender_manager_;
350 339
351 #ifdef OS_CHROMEOS 340 #ifdef OS_CHROMEOS
352 // Class that handles getting and filtering system logs. 341 // Class that handles getting and filtering system logs.
353 scoped_ptr<SystemLogsGetter> syslogs_getter_; 342 scoped_ptr<SystemLogsGetter> syslogs_getter_;
354 #endif 343 #endif
355 344
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 // Notify the handler on the IO thread that the renderer is gone. 495 // Notify the handler on the IO thread that the renderer is gone.
507 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 496 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
508 base::Bind(&IOThreadImpl::Detach, proxy_.get())); 497 base::Bind(&IOThreadImpl::Detach, proxy_.get()));
509 } 498 }
510 } 499 }
511 500
512 void NetInternalsMessageHandler::RegisterMessages() { 501 void NetInternalsMessageHandler::RegisterMessages() {
513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
514 503
515 Profile* profile = Profile::FromWebUI(web_ui()); 504 Profile* profile = Profile::FromWebUI(web_ui());
516 PrefService* pref_service = profile->GetPrefs();
517 http_throttling_enabled_.Init(
518 prefs::kHttpThrottlingEnabled, pref_service, this);
519 505
520 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(), 506 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(),
521 profile->GetRequestContext()); 507 profile->GetRequestContext());
522 #ifdef OS_CHROMEOS 508 #ifdef OS_CHROMEOS
523 syslogs_getter_.reset(new SystemLogsGetter(this, 509 syslogs_getter_.reset(new SystemLogsGetter(this,
524 chromeos::system::SyslogsProvider::GetInstance())); 510 chromeos::system::SyslogsProvider::GetInstance()));
525 #endif 511 #endif
526 512
527 prerender::PrerenderManager* prerender_manager = 513 prerender::PrerenderManager* prerender_manager =
528 prerender::PrerenderManagerFactory::GetForProfile(profile); 514 prerender::PrerenderManagerFactory::GetForProfile(profile);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 603
618 web_ui()->RegisterMessageCallback( 604 web_ui()->RegisterMessageCallback(
619 "getHttpPipeliningStatus", 605 "getHttpPipeliningStatus",
620 base::Bind(&IOThreadImpl::CallbackHelper, 606 base::Bind(&IOThreadImpl::CallbackHelper,
621 &IOThreadImpl::OnGetHttpPipeliningStatus, proxy_)); 607 &IOThreadImpl::OnGetHttpPipeliningStatus, proxy_));
622 web_ui()->RegisterMessageCallback( 608 web_ui()->RegisterMessageCallback(
623 "setLogLevel", 609 "setLogLevel",
624 base::Bind(&IOThreadImpl::CallbackHelper, 610 base::Bind(&IOThreadImpl::CallbackHelper,
625 &IOThreadImpl::OnSetLogLevel, proxy_)); 611 &IOThreadImpl::OnSetLogLevel, proxy_));
626 web_ui()->RegisterMessageCallback( 612 web_ui()->RegisterMessageCallback(
627 "enableHttpThrottling",
628 base::Bind(&NetInternalsMessageHandler::OnEnableHttpThrottling,
629 base::Unretained(this)));
630 web_ui()->RegisterMessageCallback(
631 "clearBrowserCache", 613 "clearBrowserCache",
632 base::Bind(&NetInternalsMessageHandler::OnClearBrowserCache, 614 base::Bind(&NetInternalsMessageHandler::OnClearBrowserCache,
633 base::Unretained(this))); 615 base::Unretained(this)));
634 web_ui()->RegisterMessageCallback( 616 web_ui()->RegisterMessageCallback(
635 "getPrerenderInfo", 617 "getPrerenderInfo",
636 base::Bind(&NetInternalsMessageHandler::OnGetPrerenderInfo, 618 base::Bind(&NetInternalsMessageHandler::OnGetPrerenderInfo,
637 base::Unretained(this))); 619 base::Unretained(this)));
638 #ifdef OS_CHROMEOS 620 #ifdef OS_CHROMEOS
639 web_ui()->RegisterMessageCallback( 621 web_ui()->RegisterMessageCallback(
640 "refreshSystemLogs", 622 "refreshSystemLogs",
(...skipping 27 matching lines...) Expand all
668 if (value.get()) { 650 if (value.get()) {
669 web_ui()->CallJavascriptFunction("g_browser.receive", 651 web_ui()->CallJavascriptFunction("g_browser.receive",
670 *command_value.get(), 652 *command_value.get(),
671 *value.get()); 653 *value.get());
672 } else { 654 } else {
673 web_ui()->CallJavascriptFunction("g_browser.receive", 655 web_ui()->CallJavascriptFunction("g_browser.receive",
674 *command_value.get()); 656 *command_value.get());
675 } 657 }
676 } 658 }
677 659
678 void NetInternalsMessageHandler::Observe(
679 int type,
680 const content::NotificationSource& source,
681 const content::NotificationDetails& details) {
682 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
683 DCHECK_EQ(type, chrome::NOTIFICATION_PREF_CHANGED);
684
685 std::string* pref_name = content::Details<std::string>(details).ptr();
686 if (*pref_name == prefs::kHttpThrottlingEnabled) {
687 SendJavascriptCommand(
688 "receivedHttpThrottlingEnabledPrefChanged",
689 Value::CreateBooleanValue(*http_throttling_enabled_));
690 }
691 }
692
693 void NetInternalsMessageHandler::OnRendererReady(const ListValue* list) { 660 void NetInternalsMessageHandler::OnRendererReady(const ListValue* list) {
694 IOThreadImpl::CallbackHelper(&IOThreadImpl::OnRendererReady, proxy_, list); 661 IOThreadImpl::CallbackHelper(&IOThreadImpl::OnRendererReady, proxy_, list);
695
696 SendJavascriptCommand(
697 "receivedHttpThrottlingEnabledPrefChanged",
698 Value::CreateBooleanValue(*http_throttling_enabled_));
699 }
700
701 void NetInternalsMessageHandler::OnEnableHttpThrottling(const ListValue* list) {
702 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
703
704 bool enable = false;
705 if (!list->GetBoolean(0, &enable)) {
706 NOTREACHED();
707 return;
708 }
709
710 http_throttling_enabled_.SetValue(enable);
711 } 662 }
712 663
713 void NetInternalsMessageHandler::OnClearBrowserCache(const ListValue* list) { 664 void NetInternalsMessageHandler::OnClearBrowserCache(const ListValue* list) {
714 BrowsingDataRemover* remover = 665 BrowsingDataRemover* remover =
715 new BrowsingDataRemover(Profile::FromWebUI(web_ui()), 666 new BrowsingDataRemover(Profile::FromWebUI(web_ui()),
716 BrowsingDataRemover::EVERYTHING, 667 BrowsingDataRemover::EVERYTHING,
717 base::Time()); 668 base::Time());
718 remover->Remove(BrowsingDataRemover::REMOVE_CACHE); 669 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
719 // BrowsingDataRemover deletes itself. 670 // BrowsingDataRemover deletes itself.
720 } 671 }
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after
1723 1674
1724 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) 1675 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui)
1725 : WebUIController(web_ui) { 1676 : WebUIController(web_ui) {
1726 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); 1677 web_ui->AddMessageHandler(new NetInternalsMessageHandler());
1727 1678
1728 // Set up the chrome://net-internals/ source. 1679 // Set up the chrome://net-internals/ source.
1729 Profile* profile = Profile::FromWebUI(web_ui); 1680 Profile* profile = Profile::FromWebUI(web_ui);
1730 profile->GetChromeURLDataManager()->AddDataSource( 1681 profile->GetChromeURLDataManager()->AddDataSource(
1731 CreateNetInternalsHTMLSource()); 1682 CreateNetInternalsHTMLSource());
1732 } 1683 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/net_internals/main.js ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698