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

Unified Diff: chrome/browser/chromeos/net/network_throttling_observer.cc

Issue 2364703002: Add network throttling as an enterprise policy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add network bandwidth throttling as an enterprise policy Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/net/network_throttling_observer.cc
diff --git a/chrome/browser/chromeos/net/network_throttling_observer.cc b/chrome/browser/chromeos/net/network_throttling_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f5abd9d9be6d044ca9834779a5368d61409f572a
--- /dev/null
+++ b/chrome/browser/chromeos/net/network_throttling_observer.cc
@@ -0,0 +1,67 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/net/network_throttling_observer.h"
+
+#include <memory>
+#include <string>
+
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "base/sys_info.h"
+#include "base/values.h"
+#include "chrome/common/pref_names.h"
+#include "chromeos/network/network_state_handler.h"
+#include "components/prefs/pref_member.h"
+#include "components/prefs/pref_registry_simple.h"
+#include "components/prefs/pref_service.h"
+
+namespace chromeos {
+
+NetworkThrottlingObserver::NetworkThrottlingObserver(PrefService* local_state)
+ : local_state_(local_state) {
+ pref_change_registrar_.Init(local_state_);
+
+ base::Callback<void(const std::string&)> throttle_callback = base::Bind(
+ &NetworkThrottlingObserver::OnPreferenceChanged, base::Unretained(this));
+
+ pref_change_registrar_.Add(prefs::kNetworkThrottlingEnabled,
+ throttle_callback);
+}
+
+NetworkThrottlingObserver::~NetworkThrottlingObserver() {}
+
+void NetworkThrottlingObserver::RegisterPrefs(PrefRegistrySimple* registry) {
+ registry->RegisterDictionaryPref(prefs::kNetworkThrottlingEnabled);
+}
+
+void NetworkThrottlingObserver::OnPreferenceChanged(
+ const std::string& pref_name) {
+ DCHECK(pref_name == prefs::kNetworkThrottlingEnabled);
+
+ const base::DictionaryValue* throttling_policy =
+ local_state_->GetDictionary(prefs::kNetworkThrottlingEnabled);
+
+ // Default is to disable throttling if the policy is not found.
+ bool enabled = false;
+ uint32_t upload_rate = 0, download_rate = 0;
+ if (throttling_policy) {
+ int upload_rate_read, download_rate_read;
+
+ throttling_policy->GetBoolean("enabled", &enabled);
+
+ if (throttling_policy->GetInteger("upload_rate_kbits", &upload_rate_read) &&
Andrew T Wilson (Slow) 2016/10/28 20:36:01 If you have a multi-line if statement, you need to
+ upload_rate_read > 0)
+ upload_rate = upload_rate_read;
+
+ if (throttling_policy->GetInteger("download_rate_kbits",
+ &download_rate_read) &&
+ download_rate_read > 0)
+ download_rate = download_rate_read;
+ }
+ NetworkHandler::Get()->network_state_handler()->SetNetworkThrottlingStatus(
+ enabled, upload_rate, download_rate);
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698