Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "chrome/browser/profiles/profile.h" | |
| 14 #include "chrome/common/pref_names.h" | |
| 15 #include "chromeos/login/login_state.h" | |
| 16 #include "chromeos/network/device_state.h" | |
| 17 #include "chromeos/network/network_state_handler.h" | |
| 18 #include "components/prefs/pref_registry_simple.h" | |
| 19 | |
| 20 namespace chromeos { | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 // Weak pointer. This class is owned by ChromeBrowserMainPartsChromeos. | |
| 25 NetworkThrottlingObserver* g_network_throttling_observer = NULL; | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 namespace network_throttling_observer { | |
| 30 | |
| 31 void RegisterPrefs(PrefRegistrySimple* registry) { | |
| 32 registry->RegisterDictionaryPref(prefs::kNetworkThrottlingEnabled); | |
| 33 } | |
|
stevenjb
2016/10/21 19:41:20
nit: blank line
kirtika1
2016/10/23 00:04:49
Done.
| |
| 34 } | |
| 35 | |
| 36 NetworkThrottlingObserver::NetworkThrottlingObserver() | |
| 37 : weak_ptr_factory_(this) { | |
| 38 // TODO(kirtika): Running on ChromeOS and user not logged in requirement | |
| 39 // borrowed from wake_on_wifi_manager - check if it is really needed here. | |
|
Andrew T Wilson (Slow)
2016/10/21 13:27:30
What is this? What is the purpose here? Let's not
stevenjb
2016/10/21 19:41:20
This should only be necessary if network throttlin
stevenjb
2016/10/21 20:24:00
I see now that the policy code is specifically in
kirtika1
2016/10/23 00:04:49
Done.
| |
| 40 CHECK(!base::SysInfo::IsRunningOnChromeOS() || | |
| 41 !LoginState::Get()->IsUserLoggedIn()); | |
| 42 DCHECK(!g_network_throttling_observer); | |
| 43 | |
| 44 g_network_throttling_observer = this; | |
| 45 } | |
| 46 | |
| 47 NetworkThrottlingObserver::~NetworkThrottlingObserver() { | |
| 48 DCHECK(g_network_throttling_observer); | |
| 49 g_network_throttling_observer = NULL; | |
|
stevenjb
2016/10/21 19:41:20
s/NULL/nullptr (but see other comments)
kirtika1
2016/10/23 00:04:49
Done.
| |
| 50 } | |
| 51 | |
| 52 // static | |
| 53 NetworkThrottlingObserver* NetworkThrottlingObserver::Get() { | |
| 54 DCHECK(g_network_throttling_observer); | |
|
stevenjb
2016/10/21 19:41:20
Use CHECK instead of DCHECK, we want to make sure
kirtika1
2016/10/23 00:04:49
Done.
| |
| 55 return g_network_throttling_observer; | |
| 56 } | |
| 57 | |
| 58 void NetworkThrottlingObserver::OnPreferenceChanged( | |
| 59 bool throttling_enabled, | |
| 60 uint32_t upload_rate_kbits, | |
| 61 uint32_t download_rate_kbits) { | |
| 62 NetworkHandler::Get()->network_state_handler()->SetNetworkThrottlingStatus( | |
| 63 throttling_enabled, upload_rate_kbits, download_rate_kbits); | |
|
stevenjb
2016/10/21 19:41:20
This class isn't really an observer, i.e. it's not
| |
| 64 } | |
| 65 | |
| 66 } // namespace chromeos | |
| OLD | NEW |