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

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..fb9c989e82e68219a47689853a12adfc99a64023
--- /dev/null
+++ b/chrome/browser/chromeos/net/network_throttling_observer.cc
@@ -0,0 +1,66 @@
+// Copyright 2014 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 "chrome/browser/profiles/profile.h"
+#include "chrome/common/pref_names.h"
+#include "chromeos/login/login_state.h"
+#include "chromeos/network/device_state.h"
+#include "chromeos/network/network_state_handler.h"
+#include "components/prefs/pref_registry_simple.h"
+
+namespace chromeos {
+
+namespace {
+
+// Weak pointer. This class is owned by ChromeBrowserMainPartsChromeos.
+NetworkThrottlingObserver* g_network_throttling_observer = NULL;
+
+} // namespace
+
+namespace network_throttling_observer {
+
+void RegisterPrefs(PrefRegistrySimple* registry) {
+ registry->RegisterDictionaryPref(prefs::kNetworkThrottlingEnabled);
+}
+}
+
+NetworkThrottlingObserver::NetworkThrottlingObserver()
+ : weak_ptr_factory_(this) {
+ // TODO(kirtika): Running on ChromeOS and user not logged in requirement
+ // borrowed from wake_on_wifi_manager - check if it is really needed here.
+ CHECK(!base::SysInfo::IsRunningOnChromeOS() ||
+ !LoginState::Get()->IsUserLoggedIn());
+ DCHECK(!g_network_throttling_observer);
+
+ g_network_throttling_observer = this;
+}
+
+NetworkThrottlingObserver::~NetworkThrottlingObserver() {
+ DCHECK(g_network_throttling_observer);
+ g_network_throttling_observer = NULL;
+}
+
+// static
+NetworkThrottlingObserver* NetworkThrottlingObserver::Get() {
+ DCHECK(g_network_throttling_observer);
+ return g_network_throttling_observer;
+}
+
+void NetworkThrottlingObserver::OnPreferenceChanged(
+ bool throttling_enabled,
+ uint32_t upload_rate_kbits,
+ uint32_t download_rate_kbits) {
+ NetworkHandler::Get()->network_state_handler()->SetNetworkThrottlingStatus(
+ throttling_enabled, upload_rate_kbits, download_rate_kbits);
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698