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

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..4cf36562957b7485616f1ac14b58c31308eb8cc2
--- /dev/null
+++ b/chrome/browser/chromeos/net/network_throttling_observer.cc
@@ -0,0 +1,64 @@
+// 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/browser/browser_process.h"
stevenjb 2016/10/27 22:54:38 This dependency should be removed now?
kirtika1 2016/10/27 23:04:11 Done.
+#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), weak_ptr_factory_(this) {
+ pref_change_registrar_.Init(local_state_);
+
+ base::Callback<void(const std::string&)> throttle_callback =
+ base::Bind(&NetworkThrottlingObserver::OnPreferenceChanged,
+ weak_ptr_factory_.GetWeakPtr());
+
+ pref_change_registrar_.Add(prefs::kNetworkThrottlingEnabled,
+ throttle_callback);
+}
+
+NetworkThrottlingObserver::~NetworkThrottlingObserver() {
+ pref_change_registrar_.RemoveAll();
+}
+
+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);
+
+ if (!throttling_policy) {
+ return;
+ }
stevenjb 2016/10/27 22:54:38 nit: {} not needed
kirtika1 2016/10/27 23:04:11 Done.
+ bool enabled;
+ uint32_t upload_rate, download_rate;
+ throttling_policy->GetBoolean("enabled", &enabled);
+ throttling_policy->GetInteger("upload_rate_kbits",
+ reinterpret_cast<int*>(&upload_rate));
+ throttling_policy->GetInteger("download_rate_kbits",
+ reinterpret_cast<int*>(&download_rate));
+ NetworkHandler::Get()->network_state_handler()->SetNetworkThrottlingStatus(
+ enabled, upload_rate, download_rate);
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698