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

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/browser/browser_process.h"
15 #include "chrome/browser/profiles/profile.h"
stevenjb 2016/10/24 17:14:16 Needed?
kirtika1 2016/10/27 18:15:42 Removed.
16 #include "chrome/common/pref_names.h"
17 #include "chromeos/network/network_state_handler.h"
18 #include "components/prefs/pref_member.h"
19 #include "components/prefs/pref_registry_simple.h"
20 #include "components/prefs/pref_service.h"
21
22 namespace chromeos {
23
24 namespace {
25
26 // Weak pointer. This class is owned by ChromeBrowserMainPartsChromeos.
27 NetworkThrottlingObserver* g_network_throttling_observer = nullptr;
stevenjb 2016/10/24 17:14:16 You shouldn't need this any more.
kirtika1 2016/10/27 18:15:42 Done.
28
29 } // namespace
30
31 NetworkThrottlingObserver::NetworkThrottlingObserver()
32 : weak_ptr_factory_(this) {
33 DCHECK(!g_network_throttling_observer);
34 g_network_throttling_observer = this;
35
36 pref_change_registrar_.Init(g_browser_process->local_state());
stevenjb 2016/10/24 17:14:16 Instead of accessing g_browser_process, pass g_bro
kirtika1 2016/10/27 18:15:42 Done.
37
38 base::Callback<void(const std::string&)> throttle_callback = base::Bind(
39 &NetworkThrottlingObserver::OnPreferenceChanged, base::Unretained(this));
stevenjb 2016/10/24 17:14:16 base::Unretained is dangerous here. If this class
kirtika1 2016/10/27 18:15:42 Done. I could follow your explanation for this sp
40
41 pref_change_registrar_.Add(prefs::kNetworkThrottlingEnabled,
42 throttle_callback);
43 }
44
45 NetworkThrottlingObserver::~NetworkThrottlingObserver() {
46 DCHECK(g_network_throttling_observer);
47 g_network_throttling_observer = nullptr;
48 }
49
50 void NetworkThrottlingObserver::RegisterPrefs(PrefRegistrySimple* registry) {
51 registry->RegisterDictionaryPref(prefs::kNetworkThrottlingEnabled);
52 }
53
54 void NetworkThrottlingObserver::OnPreferenceChanged(
55 const std::string& pref_name) {
56 DCHECK(pref_name == prefs::kNetworkThrottlingEnabled);
57
58 const base::DictionaryValue* throttling_policy =
59 g_browser_process->local_state()->GetDictionary(
60 prefs::kNetworkThrottlingEnabled);
61
62 if (throttling_policy) {
stevenjb 2016/10/24 17:14:16 nit: early exit: if (!throttling_policy) return;
kirtika1 2016/10/27 18:15:42 Done.
63 bool enabled;
64 uint32_t upload_rate, download_rate;
65 throttling_policy->GetBoolean("enabled", &enabled);
66 throttling_policy->GetInteger("upload_rate_kbits",
67 reinterpret_cast<int*>(&upload_rate));
68 throttling_policy->GetInteger("download_rate_kbits",
69 reinterpret_cast<int*>(&download_rate));
70 NetworkHandler::Get()->network_state_handler()->SetNetworkThrottlingStatus(
71 enabled, upload_rate, download_rate);
72 }
73 }
74
75 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698