| 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 "net/nqe/network_qualities_prefs_manager.h" | 5 #include "net/nqe/network_qualities_prefs_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "net/nqe/network_quality_estimator.h" | 15 #include "net/nqe/network_quality_estimator.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // Maximum size of the prefs that hold the qualities of different networks. | 21 // Maximum size of the prefs that hold the qualities of different networks. |
| 22 static const size_t kMaxCacheSize = 3u; | 22 // A single entry in the cache consists of three tuples: |
| 23 // (i) SSID or MCCMNC of the network. SSID is at most 32 characters in length |
| 24 // (but is typically shorter than that). MCCMNC is at most 6 characters |
| 25 // long. |
| 26 // (ii) Connection type of the network as reported by network |
| 27 // change notifier (an enum). |
| 28 // (iii) Effective connection type of the network (an enum). |
| 29 static const size_t kMaxCacheSize = 10u; |
| 23 | 30 |
| 24 // Parses |value| into a map of NetworkIDs and CachedNetworkQualities, | 31 // Parses |value| into a map of NetworkIDs and CachedNetworkQualities, |
| 25 // and returns the map. | 32 // and returns the map. |
| 26 ParsedPrefs ConvertDictionaryValueToMap(const base::DictionaryValue* value) { | 33 ParsedPrefs ConvertDictionaryValueToMap(const base::DictionaryValue* value) { |
| 27 ParsedPrefs read_prefs; | 34 ParsedPrefs read_prefs; |
| 28 | 35 |
| 29 DCHECK_GE(kMaxCacheSize, value->size()); | 36 DCHECK_GE(kMaxCacheSize, value->size()); |
| 30 | 37 |
| 31 for (base::DictionaryValue::Iterator it(*value); !it.IsAtEnd(); | 38 for (base::DictionaryValue::Iterator it(*value); !it.IsAtEnd(); |
| 32 it.Advance()) { | 39 it.Advance()) { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 } | 170 } |
| 164 | 171 |
| 165 ParsedPrefs NetworkQualitiesPrefsManager::ForceReadPrefsForTesting() const { | 172 ParsedPrefs NetworkQualitiesPrefsManager::ForceReadPrefsForTesting() const { |
| 166 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 173 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
| 167 std::unique_ptr<base::DictionaryValue> value( | 174 std::unique_ptr<base::DictionaryValue> value( |
| 168 pref_delegate_->GetDictionaryValue()); | 175 pref_delegate_->GetDictionaryValue()); |
| 169 return ConvertDictionaryValueToMap(value.get()); | 176 return ConvertDictionaryValueToMap(value.get()); |
| 170 } | 177 } |
| 171 | 178 |
| 172 } // namespace net | 179 } // namespace net |
| OLD | NEW |