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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 m_isOnLine = onLine; | 54 m_isOnLine = onLine; |
55 } | 55 } |
56 | 56 |
57 Page::networkStateChanged(onLine); | 57 Page::networkStateChanged(onLine); |
58 } | 58 } |
59 | 59 |
60 void NetworkStateNotifier::setWebConnectionType(blink::WebConnectionType type) | 60 void NetworkStateNotifier::setWebConnectionType(blink::WebConnectionType type) |
61 { | 61 { |
62 ASSERT(isMainThread()); | 62 ASSERT(isMainThread()); |
| 63 if (m_testUpdatesOnly) |
| 64 return; |
| 65 |
| 66 setWebConnectionTypeImpl(type); |
| 67 } |
| 68 |
| 69 void NetworkStateNotifier::setWebConnectionTypeImpl(blink::WebConnectionType typ
e) |
| 70 { |
| 71 ASSERT(isMainThread()); |
| 72 ASSERT(!m_testUpdatesOnly); |
63 | 73 |
64 MutexLocker locker(m_mutex); | 74 MutexLocker locker(m_mutex); |
65 if (m_type == type) | 75 if (m_type == type) |
66 return; | 76 return; |
67 m_type = type; | 77 m_type = type; |
68 | 78 |
69 for (ObserverListMap::iterator it = m_observers.begin(); it != m_observers.e
nd(); ++it) { | 79 for (ObserverListMap::iterator it = m_observers.begin(); it != m_observers.e
nd(); ++it) { |
70 ExecutionContext* context = it->key; | 80 ExecutionContext* context = it->key; |
71 context->postTask(bind(&NetworkStateNotifier::notifyObserversOnContext,
this, context, type)); | 81 context->postTask(bind(&NetworkStateNotifier::notifyObserversOnContext,
this, context, type)); |
72 } | 82 } |
(...skipping 26 matching lines...) Expand all Loading... |
99 size_t index = observers.find(observer); | 109 size_t index = observers.find(observer); |
100 if (index != kNotFound) { | 110 if (index != kNotFound) { |
101 observers[index] = 0; | 111 observers[index] = 0; |
102 observerList->zeroedObservers.append(index); | 112 observerList->zeroedObservers.append(index); |
103 } | 113 } |
104 | 114 |
105 if (!observerList->iterating && !observerList->zeroedObservers.isEmpty()) | 115 if (!observerList->iterating && !observerList->zeroedObservers.isEmpty()) |
106 collectZeroedObservers(observerList, context); | 116 collectZeroedObservers(observerList, context); |
107 } | 117 } |
108 | 118 |
| 119 void NetworkStateNotifier::setTestUpdatesOnly(bool updatesOnly) |
| 120 { |
| 121 ASSERT(isMainThread()); |
| 122 m_testUpdatesOnly = updatesOnly; |
| 123 } |
| 124 |
| 125 void NetworkStateNotifier::setWebConnectionTypeForTest(blink::WebConnectionType
type) |
| 126 { |
| 127 ASSERT(isMainThread()); |
| 128 ASSERT(m_testUpdatesOnly); |
| 129 setWebConnectionTypeImpl(type); |
| 130 } |
| 131 |
109 void NetworkStateNotifier::notifyObserversOnContext(ExecutionContext* context, b
link::WebConnectionType type) | 132 void NetworkStateNotifier::notifyObserversOnContext(ExecutionContext* context, b
link::WebConnectionType type) |
110 { | 133 { |
111 ObserverList* observerList = lockAndFindObserverList(context); | 134 ObserverList* observerList = lockAndFindObserverList(context); |
112 | 135 |
113 // The context could have been removed before the notification task got to r
un. | 136 // The context could have been removed before the notification task got to r
un. |
114 if (!observerList) | 137 if (!observerList) |
115 return; | 138 return; |
116 | 139 |
117 ASSERT(context->isContextThread()); | 140 ASSERT(context->isContextThread()); |
118 | 141 |
(...skipping 30 matching lines...) Expand all Loading... |
149 | 172 |
150 list->zeroedObservers.clear(); | 173 list->zeroedObservers.clear(); |
151 | 174 |
152 if (list->observers.isEmpty()) { | 175 if (list->observers.isEmpty()) { |
153 MutexLocker locker(m_mutex); | 176 MutexLocker locker(m_mutex); |
154 m_observers.remove(context); // deletes list | 177 m_observers.remove(context); // deletes list |
155 } | 178 } |
156 } | 179 } |
157 | 180 |
158 } // namespace WebCore | 181 } // namespace WebCore |
OLD | NEW |