OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_COMMON_NET_FAKE_NETWORK_CHANGE_NOTIFIER_THREAD_H_ | |
6 #define CHROME_COMMON_NET_FAKE_NETWORK_CHANGE_NOTIFIER_THREAD_H_ | |
7 | |
8 // A fake implementation of NetworkChangeNotifierThread used for | |
9 // unit-testing. | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/scoped_ptr.h" | |
13 #include "base/thread.h" | |
14 #include "chrome/common/net/network_change_notifier_thread.h" | |
15 | |
16 namespace net { | |
17 class MockNetworkChangeNotifier; | |
18 } // namespace net | |
19 | |
20 namespace chrome_common_net { | |
21 | |
22 class ThreadBlocker; | |
23 | |
24 class FakeNetworkChangeNotifierThread : public NetworkChangeNotifierThread { | |
25 public: | |
26 FakeNetworkChangeNotifierThread(); | |
27 | |
28 virtual ~FakeNetworkChangeNotifierThread(); | |
29 | |
30 // Starts the thread in a blocked state and initializes the network | |
31 // change notifier. | |
32 void Start(); | |
33 | |
34 // Runs the tasks that are currently blocked. After this call, | |
35 // thread remains in a blocked state. A call to this function is a | |
36 // memory barrier. | |
37 void Pump(); | |
38 | |
39 // Stops the thread. | |
40 void Stop(); | |
41 | |
42 // Trigger an IP address change notification on the owned network | |
43 // change notifier on the owned thread. | |
44 void NotifyIPAddressChange(); | |
45 | |
46 // Implementation of NetworkChangeNotifierThread. | |
47 | |
48 virtual MessageLoop* GetMessageLoop() const; | |
49 | |
50 virtual net::NetworkChangeNotifier* GetNetworkChangeNotifier() const; | |
51 | |
52 private: | |
53 // Used in unit tests. | |
54 friend class FakeNetworkChangeNotifierThreadDestructionObserver; | |
55 | |
56 void NotifyIPAddressChangeOnSourceThread(); | |
57 | |
58 scoped_ptr<net::MockNetworkChangeNotifier> network_change_notifier_; | |
59 base::Thread thread_; | |
60 scoped_ptr<ThreadBlocker> thread_blocker_; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(FakeNetworkChangeNotifierThread); | |
63 }; | |
64 | |
65 } // namespace chrome_common_net | |
66 | |
67 #endif // CHROME_COMMON_NET_FAKE_NETWORK_CHANGE_NOTIFIER_THREAD_H_ | |
OLD | NEW |