| 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_msec != before_.http_rtt_msec || |
| 63 after.transport_rtt_msec != before_.transport_rtt_msec || |
| 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::SetWebNetworkQuality(int http_rtt_msec, |
| 98 int transport_rtt_msec, |
| 99 int downlink_throughput_kbps) { |
| 100 DCHECK(IsMainThread()); |
| 101 ScopedNotifier notifier(*this); |
| 102 { |
| 103 MutexLocker locker(mutex_); |
| 104 state_.http_rtt_msec = http_rtt_msec; |
| 105 state_.transport_rtt_msec = transport_rtt_msec; |
| 106 state_.downlink_throughput_mbps = |
| 107 static_cast<double>(downlink_throughput_kbps) / 1000; |
| 108 } |
| 109 } |
| 110 |
| 94 void NetworkStateNotifier::AddConnectionObserver( | 111 void NetworkStateNotifier::AddConnectionObserver( |
| 95 NetworkStateObserver* observer, | 112 NetworkStateObserver* observer, |
| 96 PassRefPtr<WebTaskRunner> task_runner) { | 113 PassRefPtr<WebTaskRunner> task_runner) { |
| 97 AddObserver(connection_observers_, observer, std::move(task_runner)); | 114 AddObserver(connection_observers_, observer, std::move(task_runner)); |
| 98 } | 115 } |
| 99 | 116 |
| 100 void NetworkStateNotifier::AddOnLineObserver( | 117 void NetworkStateNotifier::AddOnLineObserver( |
| 101 NetworkStateObserver* observer, | 118 NetworkStateObserver* observer, |
| 102 PassRefPtr<WebTaskRunner> task_runner) { | 119 PassRefPtr<WebTaskRunner> task_runner) { |
| 103 AddObserver(on_line_state_observers_, observer, std::move(task_runner)); | 120 AddObserver(on_line_state_observers_, observer, std::move(task_runner)); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 190 |
| 174 for (size_t i = 0; i < observer_list->observers.size(); ++i) { | 191 for (size_t i = 0; i < observer_list->observers.size(); ++i) { |
| 175 // Observers removed during iteration are zeroed out, skip them. | 192 // Observers removed during iteration are zeroed out, skip them. |
| 176 if (!observer_list->observers[i]) | 193 if (!observer_list->observers[i]) |
| 177 continue; | 194 continue; |
| 178 switch (type) { | 195 switch (type) { |
| 179 case ObserverType::ONLINE_STATE: | 196 case ObserverType::ONLINE_STATE: |
| 180 observer_list->observers[i]->OnLineStateChange(state.on_line); | 197 observer_list->observers[i]->OnLineStateChange(state.on_line); |
| 181 continue; | 198 continue; |
| 182 case ObserverType::CONNECTION_TYPE: | 199 case ObserverType::CONNECTION_TYPE: |
| 183 observer_list->observers[i]->ConnectionChange(state.type, | 200 observer_list->observers[i]->ConnectionChange( |
| 184 state.max_bandwidth_mbps); | 201 state.type, state.max_bandwidth_mbps, state.http_rtt_msec, |
| 202 state.transport_rtt_msec, state.downlink_throughput_mbps); |
| 185 continue; | 203 continue; |
| 186 } | 204 } |
| 187 NOTREACHED(); | 205 NOTREACHED(); |
| 188 } | 206 } |
| 189 | 207 |
| 190 observer_list->iterating = false; | 208 observer_list->iterating = false; |
| 191 | 209 |
| 192 if (!observer_list->zeroed_observers.IsEmpty()) | 210 if (!observer_list->zeroed_observers.IsEmpty()) |
| 193 CollectZeroedObservers(*map, observer_list, std::move(task_runner)); | 211 CollectZeroedObservers(*map, observer_list, std::move(task_runner)); |
| 194 } | 212 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 271 |
| 254 list->zeroed_observers.clear(); | 272 list->zeroed_observers.clear(); |
| 255 | 273 |
| 256 if (list->observers.IsEmpty()) { | 274 if (list->observers.IsEmpty()) { |
| 257 MutexLocker locker(mutex_); | 275 MutexLocker locker(mutex_); |
| 258 map.erase(task_runner); // deletes list | 276 map.erase(task_runner); // deletes list |
| 259 } | 277 } |
| 260 } | 278 } |
| 261 | 279 |
| 262 } // namespace blink | 280 } // namespace blink |
| OLD | NEW |