OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 } |
| 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. |
| 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; |
| 50 } |
| 51 |
| 52 // static |
| 53 NetworkThrottlingObserver* NetworkThrottlingObserver::Get() { |
| 54 DCHECK(g_network_throttling_observer); |
| 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); |
| 64 } |
| 65 |
| 66 } // namespace chromeos |
OLD | NEW |