OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/net/network_throttling_observer.h" | 5 #include "chrome/browser/chromeos/net/network_throttling_observer.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 const std::string& pref_name) { | 40 const std::string& pref_name) { |
41 DCHECK(pref_name == prefs::kNetworkThrottlingEnabled); | 41 DCHECK(pref_name == prefs::kNetworkThrottlingEnabled); |
42 | 42 |
43 const base::DictionaryValue* throttling_policy = | 43 const base::DictionaryValue* throttling_policy = |
44 local_state_->GetDictionary(prefs::kNetworkThrottlingEnabled); | 44 local_state_->GetDictionary(prefs::kNetworkThrottlingEnabled); |
45 | 45 |
46 // Default is to disable throttling if the policy is not found. | 46 // Default is to disable throttling if the policy is not found. |
47 bool enabled = false; | 47 bool enabled = false; |
48 uint32_t upload_rate = 0, download_rate = 0; | 48 uint32_t upload_rate = 0, download_rate = 0; |
49 if (throttling_policy) { | 49 if (throttling_policy) { |
50 int upload_rate_read, download_rate_read; | 50 int upload_rate_read = 0; |
| 51 int download_rate_read = 0; |
51 | 52 |
52 throttling_policy->GetBoolean("enabled", &enabled); | 53 throttling_policy->GetBoolean("enabled", &enabled); |
53 | 54 |
54 if (throttling_policy->GetInteger("upload_rate_kbits", &upload_rate_read) && | 55 if (throttling_policy->GetInteger("upload_rate_kbits", &upload_rate_read) && |
55 upload_rate_read > 0) { | 56 upload_rate_read > 0) { |
56 upload_rate = upload_rate_read; | 57 upload_rate = upload_rate_read; |
57 } | 58 } |
58 | 59 |
59 if (throttling_policy->GetInteger("download_rate_kbits", | 60 if (throttling_policy->GetInteger("download_rate_kbits", |
60 &download_rate_read) && | 61 &download_rate_read) && |
61 download_rate_read > 0) { | 62 download_rate_read > 0) { |
62 download_rate = download_rate_read; | 63 download_rate = download_rate_read; |
63 } | 64 } |
64 } | 65 } |
65 NetworkHandler::Get()->network_state_handler()->SetNetworkThrottlingStatus( | 66 NetworkHandler::Get()->network_state_handler()->SetNetworkThrottlingStatus( |
66 enabled, upload_rate, download_rate); | 67 enabled, upload_rate, download_rate); |
67 } | 68 } |
68 | 69 |
69 } // namespace chromeos | 70 } // namespace chromeos |
OLD | NEW |