| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 : notifier_(notifier) { | 51 : notifier_(notifier) { |
| 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.http_rtt != before_.http_rtt || |
| 63 after.transport_rtt != before_.transport_rtt || |
| 64 after.downlink_throughput_mbps != before_.downlink_throughput_mbps) && |
| 62 before_.connection_initialized) { | 65 before_.connection_initialized) { |
| 63 notifier_.NotifyObservers(notifier_.connection_observers_, | 66 notifier_.NotifyObservers(notifier_.connection_observers_, |
| 64 ObserverType::CONNECTION_TYPE, after); | 67 ObserverType::CONNECTION_TYPE, after); |
| 65 } | 68 } |
| 66 if (after.on_line != before_.on_line && before_.on_line_initialized) { | 69 if (after.on_line != before_.on_line && before_.on_line_initialized) { |
| 67 notifier_.NotifyObservers(notifier_.on_line_state_observers_, | 70 notifier_.NotifyObservers(notifier_.on_line_state_observers_, |
| 68 ObserverType::ONLINE_STATE, after); | 71 ObserverType::ONLINE_STATE, after); |
| 69 } | 72 } |
| 70 } | 73 } |
| 71 | 74 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 84 DCHECK(IsMainThread()); | 87 DCHECK(IsMainThread()); |
| 85 ScopedNotifier notifier(*this); | 88 ScopedNotifier notifier(*this); |
| 86 { | 89 { |
| 87 MutexLocker locker(mutex_); | 90 MutexLocker locker(mutex_); |
| 88 state_.connection_initialized = true; | 91 state_.connection_initialized = true; |
| 89 state_.type = type; | 92 state_.type = type; |
| 90 state_.max_bandwidth_mbps = max_bandwidth_mbps; | 93 state_.max_bandwidth_mbps = max_bandwidth_mbps; |
| 91 } | 94 } |
| 92 } | 95 } |
| 93 | 96 |
| 97 void NetworkStateNotifier::SetNetworkQuality(TimeDelta http_rtt, |
| 98 TimeDelta transport_rtt, |
| 99 int downlink_throughput_kbps) { |
| 100 DCHECK(IsMainThread()); |
| 101 ScopedNotifier notifier(*this); |
| 102 { |
| 103 MutexLocker locker(mutex_); |
| 104 |
| 105 state_.http_rtt = base::nullopt; |
| 106 state_.transport_rtt = base::nullopt; |
| 107 state_.downlink_throughput_mbps = base::nullopt; |
| 108 |
| 109 if (http_rtt.InMilliseconds() >= 0) |
| 110 state_.http_rtt = http_rtt; |
| 111 |
| 112 if (transport_rtt.InMilliseconds() >= 0) |
| 113 state_.transport_rtt = transport_rtt; |
| 114 |
| 115 if (downlink_throughput_kbps >= 0) { |
| 116 state_.downlink_throughput_mbps = |
| 117 static_cast<double>(downlink_throughput_kbps) / 1000; |
| 118 } |
| 119 } |
| 120 } |
| 121 |
| 94 void NetworkStateNotifier::AddConnectionObserver( | 122 void NetworkStateNotifier::AddConnectionObserver( |
| 95 NetworkStateObserver* observer, | 123 NetworkStateObserver* observer, |
| 96 PassRefPtr<WebTaskRunner> task_runner) { | 124 PassRefPtr<WebTaskRunner> task_runner) { |
| 97 AddObserver(connection_observers_, observer, std::move(task_runner)); | 125 AddObserver(connection_observers_, observer, std::move(task_runner)); |
| 98 } | 126 } |
| 99 | 127 |
| 100 void NetworkStateNotifier::AddOnLineObserver( | 128 void NetworkStateNotifier::AddOnLineObserver( |
| 101 NetworkStateObserver* observer, | 129 NetworkStateObserver* observer, |
| 102 PassRefPtr<WebTaskRunner> task_runner) { | 130 PassRefPtr<WebTaskRunner> task_runner) { |
| 103 AddObserver(on_line_state_observers_, observer, std::move(task_runner)); | 131 AddObserver(on_line_state_observers_, observer, std::move(task_runner)); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 201 |
| 174 for (size_t i = 0; i < observer_list->observers.size(); ++i) { | 202 for (size_t i = 0; i < observer_list->observers.size(); ++i) { |
| 175 // Observers removed during iteration are zeroed out, skip them. | 203 // Observers removed during iteration are zeroed out, skip them. |
| 176 if (!observer_list->observers[i]) | 204 if (!observer_list->observers[i]) |
| 177 continue; | 205 continue; |
| 178 switch (type) { | 206 switch (type) { |
| 179 case ObserverType::ONLINE_STATE: | 207 case ObserverType::ONLINE_STATE: |
| 180 observer_list->observers[i]->OnLineStateChange(state.on_line); | 208 observer_list->observers[i]->OnLineStateChange(state.on_line); |
| 181 continue; | 209 continue; |
| 182 case ObserverType::CONNECTION_TYPE: | 210 case ObserverType::CONNECTION_TYPE: |
| 183 observer_list->observers[i]->ConnectionChange(state.type, | 211 observer_list->observers[i]->ConnectionChange( |
| 184 state.max_bandwidth_mbps); | 212 state.type, state.max_bandwidth_mbps, state.http_rtt, |
| 213 state.transport_rtt, state.downlink_throughput_mbps); |
| 185 continue; | 214 continue; |
| 186 } | 215 } |
| 187 NOTREACHED(); | 216 NOTREACHED(); |
| 188 } | 217 } |
| 189 | 218 |
| 190 observer_list->iterating = false; | 219 observer_list->iterating = false; |
| 191 | 220 |
| 192 if (!observer_list->zeroed_observers.IsEmpty()) | 221 if (!observer_list->zeroed_observers.IsEmpty()) |
| 193 CollectZeroedObservers(*map, observer_list, std::move(task_runner)); | 222 CollectZeroedObservers(*map, observer_list, std::move(task_runner)); |
| 194 } | 223 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 282 |
| 254 list->zeroed_observers.clear(); | 283 list->zeroed_observers.clear(); |
| 255 | 284 |
| 256 if (list->observers.IsEmpty()) { | 285 if (list->observers.IsEmpty()) { |
| 257 MutexLocker locker(mutex_); | 286 MutexLocker locker(mutex_); |
| 258 map.erase(task_runner); // deletes list | 287 map.erase(task_runner); // deletes list |
| 259 } | 288 } |
| 260 } | 289 } |
| 261 | 290 |
| 262 } // namespace blink | 291 } // namespace blink |
| OLD | NEW |