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

Side by Side 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, 1 month 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/net/network_throttling_observer.h"
6
7 #include <memory>
8 #include <string>
9
10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h"
12 #include "base/sys_info.h"
13 #include "base/values.h"
14 #include "chrome/common/pref_names.h"
15 #include "chromeos/network/network_state_handler.h"
16 #include "components/prefs/pref_member.h"
17 #include "components/prefs/pref_registry_simple.h"
18 #include "components/prefs/pref_service.h"
19
20 namespace chromeos {
21
22 NetworkThrottlingObserver::NetworkThrottlingObserver(PrefService* local_state)
23 : local_state_(local_state) {
24 pref_change_registrar_.Init(local_state_);
25
26 base::Callback<void(const std::string&)> throttle_callback = base::Bind(
27 &NetworkThrottlingObserver::OnPreferenceChanged, base::Unretained(this));
28
29 pref_change_registrar_.Add(prefs::kNetworkThrottlingEnabled,
30 throttle_callback);
31 }
32
33 NetworkThrottlingObserver::~NetworkThrottlingObserver() {}
34
35 void NetworkThrottlingObserver::RegisterPrefs(PrefRegistrySimple* registry) {
36 registry->RegisterDictionaryPref(prefs::kNetworkThrottlingEnabled);
37 }
38
39 void NetworkThrottlingObserver::OnPreferenceChanged(
40 const std::string& pref_name) {
41 DCHECK(pref_name == prefs::kNetworkThrottlingEnabled);
42
43 const base::DictionaryValue* throttling_policy =
44 local_state_->GetDictionary(prefs::kNetworkThrottlingEnabled);
45
46 // Default is to disable throttling if the policy is not found.
47 bool enabled = false;
48 uint32_t upload_rate = 0, download_rate = 0;
Lei Zhang 2016/10/29 16:04:04 nit: 1 declaration per line please
kirtika1 2016/10/29 21:26:38 Done.
49 if (throttling_policy) {
50 int upload_rate_read, download_rate_read;
51
52 throttling_policy->GetBoolean("enabled", &enabled);
53
54 if (throttling_policy->GetInteger("upload_rate_kbits", &upload_rate_read) &&
55 upload_rate_read > 0) {
56 upload_rate = upload_rate_read;
57 }
58
59 if (throttling_policy->GetInteger("download_rate_kbits",
60 &download_rate_read) &&
61 download_rate_read > 0) {
62 download_rate = download_rate_read;
63 }
64 }
65 NetworkHandler::Get()->network_state_handler()->SetNetworkThrottlingStatus(
66 enabled, upload_rate, download_rate);
67 }
68
69 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698