| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 DCHECK(IsMainThread()); | 52 DCHECK(IsMainThread()); |
| 53 before_ = notifier_.has_override_ ? notifier_.override_ : notifier_.state_; | 53 before_ = notifier_.has_override_ ? notifier_.override_ : notifier_.state_; |
| 54 } | 54 } |
| 55 | 55 |
| 56 NetworkStateNotifier::ScopedNotifier::~ScopedNotifier() { | 56 NetworkStateNotifier::ScopedNotifier::~ScopedNotifier() { |
| 57 DCHECK(IsMainThread()); | 57 DCHECK(IsMainThread()); |
| 58 const NetworkState& after = | 58 const NetworkState& after = |
| 59 notifier_.has_override_ ? notifier_.override_ : notifier_.state_; | 59 notifier_.has_override_ ? notifier_.override_ : notifier_.state_; |
| 60 if ((after.type != before_.type || | 60 if ((after.type != before_.type || |
| 61 after.max_bandwidth_mbps != before_.max_bandwidth_mbps || | 61 after.max_bandwidth_mbps != before_.max_bandwidth_mbps || |
| 62 after.effective_type != before_.effective_type || |
| 62 after.http_rtt != before_.http_rtt || | 63 after.http_rtt != before_.http_rtt || |
| 63 after.transport_rtt != before_.transport_rtt || | 64 after.transport_rtt != before_.transport_rtt || |
| 64 after.downlink_throughput_mbps != before_.downlink_throughput_mbps) && | 65 after.downlink_throughput_mbps != before_.downlink_throughput_mbps) && |
| 65 before_.connection_initialized) { | 66 before_.connection_initialized) { |
| 66 notifier_.NotifyObservers(notifier_.connection_observers_, | 67 notifier_.NotifyObservers(notifier_.connection_observers_, |
| 67 ObserverType::CONNECTION_TYPE, after); | 68 ObserverType::CONNECTION_TYPE, after); |
| 68 } | 69 } |
| 69 if (after.on_line != before_.on_line && before_.on_line_initialized) { | 70 if (after.on_line != before_.on_line && before_.on_line_initialized) { |
| 70 notifier_.NotifyObservers(notifier_.on_line_state_observers_, | 71 notifier_.NotifyObservers(notifier_.on_line_state_observers_, |
| 71 ObserverType::ONLINE_STATE, after); | 72 ObserverType::ONLINE_STATE, after); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 87 DCHECK(IsMainThread()); | 88 DCHECK(IsMainThread()); |
| 88 ScopedNotifier notifier(*this); | 89 ScopedNotifier notifier(*this); |
| 89 { | 90 { |
| 90 MutexLocker locker(mutex_); | 91 MutexLocker locker(mutex_); |
| 91 state_.connection_initialized = true; | 92 state_.connection_initialized = true; |
| 92 state_.type = type; | 93 state_.type = type; |
| 93 state_.max_bandwidth_mbps = max_bandwidth_mbps; | 94 state_.max_bandwidth_mbps = max_bandwidth_mbps; |
| 94 } | 95 } |
| 95 } | 96 } |
| 96 | 97 |
| 97 void NetworkStateNotifier::SetNetworkQuality(TimeDelta http_rtt, | 98 void NetworkStateNotifier::SetNetworkQuality(WebEffectiveConnectionType type, |
| 99 TimeDelta http_rtt, |
| 98 TimeDelta transport_rtt, | 100 TimeDelta transport_rtt, |
| 99 int downlink_throughput_kbps) { | 101 int downlink_throughput_kbps) { |
| 100 DCHECK(IsMainThread()); | 102 DCHECK(IsMainThread()); |
| 101 ScopedNotifier notifier(*this); | 103 ScopedNotifier notifier(*this); |
| 102 { | 104 { |
| 103 MutexLocker locker(mutex_); | 105 MutexLocker locker(mutex_); |
| 104 | 106 |
| 107 state_.effective_type = type; |
| 105 state_.http_rtt = base::nullopt; | 108 state_.http_rtt = base::nullopt; |
| 106 state_.transport_rtt = base::nullopt; | 109 state_.transport_rtt = base::nullopt; |
| 107 state_.downlink_throughput_mbps = base::nullopt; | 110 state_.downlink_throughput_mbps = base::nullopt; |
| 108 | 111 |
| 109 if (http_rtt.InMilliseconds() >= 0) | 112 if (http_rtt.InMilliseconds() >= 0) |
| 110 state_.http_rtt = http_rtt; | 113 state_.http_rtt = http_rtt; |
| 111 | 114 |
| 112 if (transport_rtt.InMilliseconds() >= 0) | 115 if (transport_rtt.InMilliseconds() >= 0) |
| 113 state_.transport_rtt = transport_rtt; | 116 state_.transport_rtt = transport_rtt; |
| 114 | 117 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 for (size_t i = 0; i < observer_list->observers.size(); ++i) { | 205 for (size_t i = 0; i < observer_list->observers.size(); ++i) { |
| 203 // Observers removed during iteration are zeroed out, skip them. | 206 // Observers removed during iteration are zeroed out, skip them. |
| 204 if (!observer_list->observers[i]) | 207 if (!observer_list->observers[i]) |
| 205 continue; | 208 continue; |
| 206 switch (type) { | 209 switch (type) { |
| 207 case ObserverType::ONLINE_STATE: | 210 case ObserverType::ONLINE_STATE: |
| 208 observer_list->observers[i]->OnLineStateChange(state.on_line); | 211 observer_list->observers[i]->OnLineStateChange(state.on_line); |
| 209 continue; | 212 continue; |
| 210 case ObserverType::CONNECTION_TYPE: | 213 case ObserverType::CONNECTION_TYPE: |
| 211 observer_list->observers[i]->ConnectionChange( | 214 observer_list->observers[i]->ConnectionChange( |
| 212 state.type, state.max_bandwidth_mbps, state.http_rtt, | 215 state.type, state.max_bandwidth_mbps, state.effective_type, |
| 213 state.transport_rtt, state.downlink_throughput_mbps); | 216 state.http_rtt, state.transport_rtt, |
| 217 state.downlink_throughput_mbps); |
| 214 continue; | 218 continue; |
| 215 } | 219 } |
| 216 NOTREACHED(); | 220 NOTREACHED(); |
| 217 } | 221 } |
| 218 | 222 |
| 219 observer_list->iterating = false; | 223 observer_list->iterating = false; |
| 220 | 224 |
| 221 if (!observer_list->zeroed_observers.IsEmpty()) | 225 if (!observer_list->zeroed_observers.IsEmpty()) |
| 222 CollectZeroedObservers(*map, observer_list, std::move(task_runner)); | 226 CollectZeroedObservers(*map, observer_list, std::move(task_runner)); |
| 223 } | 227 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 286 |
| 283 list->zeroed_observers.clear(); | 287 list->zeroed_observers.clear(); |
| 284 | 288 |
| 285 if (list->observers.IsEmpty()) { | 289 if (list->observers.IsEmpty()) { |
| 286 MutexLocker locker(mutex_); | 290 MutexLocker locker(mutex_); |
| 287 map.erase(task_runner); // deletes list | 291 map.erase(task_runner); // deletes list |
| 288 } | 292 } |
| 289 } | 293 } |
| 290 | 294 |
| 291 } // namespace blink | 295 } // namespace blink |
| OLD | NEW |