Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: Source/core/page/NetworkStateNotifier.h

Issue 1054803006: Removing unnecessary blink::prefix (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Source/core/page/NetworkStateNotifier.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 26 matching lines...) Expand all
37 namespace blink { 37 namespace blink {
38 38
39 class ExecutionContext; 39 class ExecutionContext;
40 40
41 class CORE_EXPORT NetworkStateNotifier { 41 class CORE_EXPORT NetworkStateNotifier {
42 WTF_MAKE_NONCOPYABLE(NetworkStateNotifier); WTF_MAKE_FAST_ALLOCATED(NetworkS tateNotifier); 42 WTF_MAKE_NONCOPYABLE(NetworkStateNotifier); WTF_MAKE_FAST_ALLOCATED(NetworkS tateNotifier);
43 public: 43 public:
44 class NetworkStateObserver { 44 class NetworkStateObserver {
45 public: 45 public:
46 // Will be called on the thread of the context passed in addObserver. 46 // Will be called on the thread of the context passed in addObserver.
47 virtual void connectionTypeChange(blink::WebConnectionType) = 0; 47 virtual void connectionTypeChange(WebConnectionType) = 0;
48 }; 48 };
49 49
50 NetworkStateNotifier() 50 NetworkStateNotifier()
51 : m_isOnLine(true) 51 : m_isOnLine(true)
52 , m_type(blink::ConnectionTypeOther) 52 , m_type(ConnectionTypeOther)
53 , m_testUpdatesOnly(false) 53 , m_testUpdatesOnly(false)
54 { 54 {
55 } 55 }
56 56
57 bool onLine() const 57 bool onLine() const
58 { 58 {
59 MutexLocker locker(m_mutex); 59 MutexLocker locker(m_mutex);
60 return m_isOnLine; 60 return m_isOnLine;
61 } 61 }
62 62
63 void setOnLine(bool); 63 void setOnLine(bool);
64 64
65 blink::WebConnectionType connectionType() const 65 WebConnectionType connectionType() const
66 { 66 {
67 MutexLocker locker(m_mutex); 67 MutexLocker locker(m_mutex);
68 return m_type; 68 return m_type;
69 } 69 }
70 70
71 void setWebConnectionType(blink::WebConnectionType); 71 void setWebConnectionType(WebConnectionType);
72 72
73 // Must be called on the context's thread. An added observer must be removed 73 // Must be called on the context's thread. An added observer must be removed
74 // before its ExecutionContext is deleted. It's possible for an observer to 74 // before its ExecutionContext is deleted. It's possible for an observer to
75 // be called twice for the same event if it is first removed and then added 75 // be called twice for the same event if it is first removed and then added
76 // during notification. 76 // during notification.
77 void addObserver(NetworkStateObserver*, ExecutionContext*); 77 void addObserver(NetworkStateObserver*, ExecutionContext*);
78 void removeObserver(NetworkStateObserver*, ExecutionContext*); 78 void removeObserver(NetworkStateObserver*, ExecutionContext*);
79 79
80 // The following functions are for testing purposes. 80 // The following functions are for testing purposes.
81 81
82 // When true, setWebConnectionType calls are ignored and only setWebConnecti onTypeForTest 82 // When true, setWebConnectionType calls are ignored and only setWebConnecti onTypeForTest
83 // can update the connection type. This is used for layout tests (see crbug. com/377736). 83 // can update the connection type. This is used for layout tests (see crbug. com/377736).
84 void setTestUpdatesOnly(bool); 84 void setTestUpdatesOnly(bool);
85 // Tests should call this as it will change the type regardless of the value of m_testUpdatesOnly. 85 // Tests should call this as it will change the type regardless of the value of m_testUpdatesOnly.
86 void setWebConnectionTypeForTest(blink::WebConnectionType); 86 void setWebConnectionTypeForTest(WebConnectionType);
87 87
88 private: 88 private:
89 struct ObserverList { 89 struct ObserverList {
90 ObserverList() 90 ObserverList()
91 : iterating(false) 91 : iterating(false)
92 { 92 {
93 } 93 }
94 bool iterating; 94 bool iterating;
95 Vector<NetworkStateObserver*> observers; 95 Vector<NetworkStateObserver*> observers;
96 Vector<size_t> zeroedObservers; // Indices in observers that are 0. 96 Vector<size_t> zeroedObservers; // Indices in observers that are 0.
97 }; 97 };
98 98
99 void setWebConnectionTypeImpl(blink::WebConnectionType); 99 void setWebConnectionTypeImpl(WebConnectionType);
100 100
101 using ObserverListMap = HashMap<ExecutionContext*, OwnPtr<ObserverList>>; 101 using ObserverListMap = HashMap<ExecutionContext*, OwnPtr<ObserverList>>;
102 102
103 void notifyObserversOnContext(blink::WebConnectionType, ExecutionContext*); 103 void notifyObserversOnContext(WebConnectionType, ExecutionContext*);
104 104
105 ObserverList* lockAndFindObserverList(ExecutionContext*); 105 ObserverList* lockAndFindObserverList(ExecutionContext*);
106 106
107 // Removed observers are nulled out in the list in case the list is being 107 // Removed observers are nulled out in the list in case the list is being
108 // iterated over. Once done iterating, call this to clean up nulled 108 // iterated over. Once done iterating, call this to clean up nulled
109 // observers. 109 // observers.
110 void collectZeroedObservers(ObserverList*, ExecutionContext*); 110 void collectZeroedObservers(ObserverList*, ExecutionContext*);
111 111
112 mutable Mutex m_mutex; 112 mutable Mutex m_mutex;
113 bool m_isOnLine; 113 bool m_isOnLine;
114 blink::WebConnectionType m_type; 114 WebConnectionType m_type;
115 ObserverListMap m_observers; 115 ObserverListMap m_observers;
116 bool m_testUpdatesOnly; 116 bool m_testUpdatesOnly;
117 }; 117 };
118 118
119 CORE_EXPORT NetworkStateNotifier& networkStateNotifier(); 119 CORE_EXPORT NetworkStateNotifier& networkStateNotifier();
120 120
121 } // namespace blink 121 } // namespace blink
122 122
123 #endif // NetworkStateNotifier_h 123 #endif // NetworkStateNotifier_h
OLDNEW
« no previous file with comments | « no previous file | Source/core/page/NetworkStateNotifier.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698