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

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

Issue 7027040: Implement A/B experiment for anti-DDoS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 6 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
OLDNEW
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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/base64.h" 13 #include "base/base64.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/memory/singleton.h" 16 #include "base/memory/singleton.h"
17 #include "base/message_loop.h" 17 #include "base/message_loop.h"
18 #include "base/metrics/field_trial.h" // TODO(joi): Remove after experiment.
18 #include "base/path_service.h" 19 #include "base/path_service.h"
19 #include "base/string_number_conversions.h" 20 #include "base/string_number_conversions.h"
20 #include "base/string_piece.h" 21 #include "base/string_piece.h"
21 #include "base/string_split.h" 22 #include "base/string_split.h"
22 #include "base/string_util.h" 23 #include "base/string_util.h"
23 #include "base/utf_string_conversions.h" 24 #include "base/utf_string_conversions.h"
24 #include "base/values.h" 25 #include "base/values.h"
25 #include "chrome/browser/browser_process.h" 26 #include "chrome/browser/browser_process.h"
26 #include "chrome/browser/io_thread.h" 27 #include "chrome/browser/io_thread.h"
27 #include "chrome/browser/net/chrome_net_log.h" 28 #include "chrome/browser/net/chrome_net_log.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 const Value* value); 171 const Value* value);
171 172
172 // NotificationObserver implementation. 173 // NotificationObserver implementation.
173 virtual void Observe(NotificationType type, 174 virtual void Observe(NotificationType type,
174 const NotificationSource& source, 175 const NotificationSource& source,
175 const NotificationDetails& details); 176 const NotificationDetails& details);
176 177
177 // Javascript message handlers. 178 // Javascript message handlers.
178 void OnRendererReady(const ListValue* list); 179 void OnRendererReady(const ListValue* list);
179 void OnEnableHttpThrottling(const ListValue* list); 180 void OnEnableHttpThrottling(const ListValue* list);
181 void OnDisableThrottlingExperiments(const ListValue* list);
180 #ifdef OS_CHROMEOS 182 #ifdef OS_CHROMEOS
181 void OnRefreshSystemLogs(const ListValue* list); 183 void OnRefreshSystemLogs(const ListValue* list);
182 void OnGetSystemLog(const ListValue* list); 184 void OnGetSystemLog(const ListValue* list);
183 #endif 185 #endif
184 186
185 // SelectFileDialog::Listener implementation 187 // SelectFileDialog::Listener implementation
186 virtual void FileSelected(const FilePath& path, int index, void* params); 188 virtual void FileSelected(const FilePath& path, int index, void* params);
187 virtual void FileSelectionCanceled(void* params); 189 virtual void FileSelectionCanceled(void* params);
188 190
189 // The only callback handled on the UI thread. As it needs to access fields 191 // The only callback handled on the UI thread. As it needs to access fields
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 CancelableRequestConsumer consumer_; 267 CancelableRequestConsumer consumer_;
266 // Libcros request handle. 268 // Libcros request handle.
267 CancelableRequestProvider::Handle syslogs_request_id_; 269 CancelableRequestProvider::Handle syslogs_request_id_;
268 }; 270 };
269 #endif 271 #endif
270 272
271 // The pref member about whether HTTP throttling is enabled, which needs to 273 // The pref member about whether HTTP throttling is enabled, which needs to
272 // be accessed on the UI thread. 274 // be accessed on the UI thread.
273 BooleanPrefMember http_throttling_enabled_; 275 BooleanPrefMember http_throttling_enabled_;
274 276
277 // The pref member that determines whether experimentation on HTTP throttling
278 // is allowed (this becomes false once the user explicitly sets the
279 // feature to on or off).
280 BooleanPrefMember http_throttling_may_experiment_;
281
275 // OnRendererReady invokes this callback to do the part of message handling 282 // OnRendererReady invokes this callback to do the part of message handling
276 // that needs to happen on the IO thread. 283 // that needs to happen on the IO thread.
277 scoped_ptr<WebUI::MessageCallback> renderer_ready_io_callback_; 284 scoped_ptr<WebUI::MessageCallback> renderer_ready_io_callback_;
278 285
279 // This is the "real" message handler, which lives on the IO thread. 286 // This is the "real" message handler, which lives on the IO thread.
280 scoped_refptr<IOThreadImpl> proxy_; 287 scoped_refptr<IOThreadImpl> proxy_;
281 288
282 #ifdef OS_CHROMEOS 289 #ifdef OS_CHROMEOS
283 // Class that handles getting and filtering system logs. 290 // Class that handles getting and filtering system logs.
284 scoped_ptr<SystemLogsGetter> syslogs_getter_; 291 scoped_ptr<SystemLogsGetter> syslogs_getter_;
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 NewRunnableMethod(proxy_.get(), &IOThreadImpl::Detach)); 545 NewRunnableMethod(proxy_.get(), &IOThreadImpl::Detach));
539 } 546 }
540 if (select_log_file_dialog_) 547 if (select_log_file_dialog_)
541 select_log_file_dialog_->ListenerDestroyed(); 548 select_log_file_dialog_->ListenerDestroyed();
542 } 549 }
543 550
544 WebUIMessageHandler* NetInternalsMessageHandler::Attach(WebUI* web_ui) { 551 WebUIMessageHandler* NetInternalsMessageHandler::Attach(WebUI* web_ui) {
545 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
546 553
547 PrefService* pref_service = web_ui->GetProfile()->GetPrefs(); 554 PrefService* pref_service = web_ui->GetProfile()->GetPrefs();
548 http_throttling_enabled_.Init(prefs::kHttpThrottlingEnabled, pref_service, 555 http_throttling_enabled_.Init(
549 this); 556 prefs::kHttpThrottlingEnabled, pref_service, this);
557 http_throttling_may_experiment_.Init(
558 prefs::kHttpThrottlingMayExperiment, pref_service, NULL);
550 559
551 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(), 560 proxy_ = new IOThreadImpl(this->AsWeakPtr(), g_browser_process->io_thread(),
552 web_ui->GetProfile()->GetRequestContext()); 561 web_ui->GetProfile()->GetRequestContext());
553 #ifdef OS_CHROMEOS 562 #ifdef OS_CHROMEOS
554 syslogs_getter_.reset(new SystemLogsGetter(this, 563 syslogs_getter_.reset(new SystemLogsGetter(this,
555 chromeos::SystemAccess::GetInstance())); 564 chromeos::SystemAccess::GetInstance()));
556 #endif 565 #endif
557 renderer_ready_io_callback_.reset( 566 renderer_ready_io_callback_.reset(
558 proxy_->CreateCallback(&IOThreadImpl::OnRendererReady)); 567 proxy_->CreateCallback(&IOThreadImpl::OnRendererReady));
559 568
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 "getSystemLog", 671 "getSystemLog",
663 NewCallback(this, &NetInternalsMessageHandler::OnGetSystemLog)); 672 NewCallback(this, &NetInternalsMessageHandler::OnGetSystemLog));
664 #endif 673 #endif
665 web_ui_->RegisterMessageCallback( 674 web_ui_->RegisterMessageCallback(
666 "setLogLevel", 675 "setLogLevel",
667 proxy_->CreateCallback(&IOThreadImpl::OnSetLogLevel)); 676 proxy_->CreateCallback(&IOThreadImpl::OnSetLogLevel));
668 677
669 web_ui_->RegisterMessageCallback( 678 web_ui_->RegisterMessageCallback(
670 "enableHttpThrottling", 679 "enableHttpThrottling",
671 NewCallback(this, &NetInternalsMessageHandler::OnEnableHttpThrottling)); 680 NewCallback(this, &NetInternalsMessageHandler::OnEnableHttpThrottling));
681 web_ui_->RegisterMessageCallback(
682 "disableThrottlingExperiments",
683 NewCallback(
684 this,
685 &NetInternalsMessageHandler::OnDisableThrottlingExperiments));
672 } 686 }
673 687
674 void NetInternalsMessageHandler::CallJavascriptFunction( 688 void NetInternalsMessageHandler::CallJavascriptFunction(
675 const std::wstring& function_name, 689 const std::wstring& function_name,
676 const Value* value) { 690 const Value* value) {
677 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 691 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
678 if (value) { 692 if (value) {
679 web_ui_->CallJavascriptFunction(WideToASCII(function_name), *value); 693 web_ui_->CallJavascriptFunction(WideToASCII(function_name), *value);
680 } else { 694 } else {
681 web_ui_->CallJavascriptFunction(WideToASCII(function_name)); 695 web_ui_->CallJavascriptFunction(WideToASCII(function_name));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 727
714 bool enable = false; 728 bool enable = false;
715 if (!list->GetBoolean(0, &enable)) { 729 if (!list->GetBoolean(0, &enable)) {
716 NOTREACHED(); 730 NOTREACHED();
717 return; 731 return;
718 } 732 }
719 733
720 http_throttling_enabled_.SetValue(enable); 734 http_throttling_enabled_.SetValue(enable);
721 } 735 }
722 736
737 void NetInternalsMessageHandler::OnDisableThrottlingExperiments(
yzshen1 2011/06/08 00:56:51 The logic within this method can be put in the met
Jói 2011/06/08 16:44:47 You're right. I thought this method was also used
738 const ListValue* list) {
739 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
740
741 if (http_throttling_may_experiment_.GetValue()) {
742 http_throttling_may_experiment_.SetValue(false);
743
744 // Disable the ongoing trial so that histograms after this point
745 // show as being in the "Default" group of the trial.
746 base::FieldTrial* trial = base::FieldTrialList::Find("ThrottlingEnabled");
747 if (trial)
748 trial->Disable();
yzshen1 2011/06/08 00:56:51 It may be better to move the part of disabling the
Jói 2011/06/08 16:44:47 I can't do that because that method gets called no
yzshen1 2011/06/08 16:55:54 Makes sense. Thanks for explaining. On 2011/06/08
749 }
750 }
751
723 //////////////////////////////////////////////////////////////////////////////// 752 ////////////////////////////////////////////////////////////////////////////////
724 // 753 //
725 // NetInternalsMessageHandler::ReadLogFileTask 754 // NetInternalsMessageHandler::ReadLogFileTask
726 // 755 //
727 //////////////////////////////////////////////////////////////////////////////// 756 ////////////////////////////////////////////////////////////////////////////////
728 757
729 NetInternalsMessageHandler::ReadLogFileTask::ReadLogFileTask( 758 NetInternalsMessageHandler::ReadLogFileTask::ReadLogFileTask(
730 IOThreadImpl* proxy, const FilePath& path) 759 IOThreadImpl* proxy, const FilePath& path)
731 : proxy_(proxy), path_(path) { 760 : proxy_(proxy), path_(path) {
732 } 761 }
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 //////////////////////////////////////////////////////////////////////////////// 1661 ////////////////////////////////////////////////////////////////////////////////
1633 1662
1634 NetInternalsUI::NetInternalsUI(TabContents* contents) : ChromeWebUI(contents) { 1663 NetInternalsUI::NetInternalsUI(TabContents* contents) : ChromeWebUI(contents) {
1635 AddMessageHandler((new NetInternalsMessageHandler())->Attach(this)); 1664 AddMessageHandler((new NetInternalsMessageHandler())->Attach(this));
1636 1665
1637 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); 1666 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource();
1638 1667
1639 // Set up the chrome://net-internals/ source. 1668 // Set up the chrome://net-internals/ source.
1640 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); 1669 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source);
1641 } 1670 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698