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

Side by Side Diff: chromeos/network/network_handler.cc

Issue 14729017: Add NetworkHandler to own network handlers in src/chromeos/network (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 #include "chromeos/network/network_handler.h"
6
7 #include "chromeos/dbus/dbus_thread_manager.h"
8 #include "chromeos/login/login_state.h"
9 #include "chromeos/network/cert_loader.h"
10 #include "chromeos/network/geolocation_handler.h"
11 #include "chromeos/network/managed_network_configuration_handler.h"
12 #include "chromeos/network/network_configuration_handler.h"
13 #include "chromeos/network/network_event_log.h"
14 #include "chromeos/network/network_profile_handler.h"
15 #include "chromeos/network/network_profile_observer.h"
16 #include "chromeos/network/network_state_handler.h"
17 #include "chromeos/network/network_state_handler_observer.h"
18
19 namespace chromeos {
20
21 static NetworkHandler* g_network_handler = NULL;
22
23 class NetworkHandler::LoginStateInitializer {
24 public:
25 LoginStateInitializer() {
26 LoginState::Initialize();
27 }
28 ~LoginStateInitializer() {
29 LoginState::Shutdown();
30 }
31 };
32
33 NetworkHandler::NetworkHandler()
34 : test_cert_loader_(NULL),
35 test_network_state_handler_(NULL),
36 test_network_profile_handler_(NULL),
37 test_network_configuration_handler_(NULL),
38 test_managed_network_configuration_handler_(NULL),
39 test_geolocation_handler_(NULL) {
40 CHECK(DBusThreadManager::IsInitialized());
41
42 if (!LoginState::IsInitialized())
43 login_state_initializer_.reset(new LoginStateInitializer());
44
45 network_event_log::Initialize();
46
47 cert_loader_.reset(new CertLoader);
pneubeck (no reviews) 2013/05/13 09:17:06 I'd suggest to use explicit passing of the mutual
stevenjb 2013/05/13 23:49:35 See meta comment
48 network_state_handler_.reset(new NetworkStateHandler());
49 network_profile_handler_.reset(new NetworkProfileHandler());
50 network_configuration_handler_.reset(new NetworkConfigurationHandler());
51 managed_network_configuration_handler_.reset(
52 new ManagedNetworkConfigurationHandler());
53 geolocation_handler_.reset(new GeolocationHandler());
54 }
55
56 NetworkHandler::~NetworkHandler() {
57 network_event_log::Shutdown();
58 }
59
60 void NetworkHandler::Init() {
61 network_state_handler_->InitShillPropertyHandler();
62 managed_network_configuration_handler_->Init();
63 geolocation_handler_->Init();
64 }
65
66 // static
67 void NetworkHandler::Initialize() {
68 CHECK(!g_network_handler);
69 g_network_handler = new NetworkHandler();
70 g_network_handler->Init();
71 }
72
73 // static
74 void NetworkHandler::Shutdown() {
75 CHECK(g_network_handler);
76 delete g_network_handler;
77 g_network_handler = NULL;
78 }
79
80 // static
81 NetworkHandler* NetworkHandler::Get() {
82 CHECK(g_network_handler)
83 << "NetworkHandler::Get() called before Initialize()";
84 return g_network_handler;
85 }
86
87 // static
88 bool NetworkHandler::IsInitialized() {
89 return g_network_handler;
90 }
91
92 CertLoader* NetworkHandler::cert_loader() {
93 if (test_cert_loader_)
94 return test_cert_loader_;
95 return cert_loader_.get();
96 }
97
98 NetworkStateHandler* NetworkHandler::network_state_handler() {
99 if (test_network_state_handler_)
100 return test_network_state_handler_;
101 return network_state_handler_.get();
102 }
103
104 NetworkProfileHandler* NetworkHandler::network_profile_handler() {
105 if (test_network_profile_handler_)
106 return test_network_profile_handler_;
107 return network_profile_handler_.get();
108 }
109
110 NetworkConfigurationHandler* NetworkHandler::network_configuration_handler() {
111 if (test_network_configuration_handler_)
112 return test_network_configuration_handler_;
113 return network_configuration_handler_.get();
114 }
115
116 ManagedNetworkConfigurationHandler*
117 NetworkHandler::managed_network_configuration_handler() {
118 if (test_managed_network_configuration_handler_)
119 return test_managed_network_configuration_handler_;
120 return managed_network_configuration_handler_.get();
121 }
122
123 GeolocationHandler* NetworkHandler::geolocation_handler() {
124 if (test_geolocation_handler_)
125 return test_geolocation_handler_;
126 return geolocation_handler_.get();
127 }
128
129 void NetworkHandler::SetCertLoaderForTest(CertLoader* cert_loader) {
130 test_cert_loader_ = cert_loader;
131 // Copy any existing observers to the test handler.
132 if (cert_loader_.get()) {
133 ObserverList<CertLoader::Observer>::Iterator iter(cert_loader_->observers_);
134 CertLoader::Observer* observer;
135 while ((observer = iter.GetNext()) != NULL) {
136 test_cert_loader_->AddObserver(observer);
pneubeck (no reviews) 2013/05/13 09:17:06 I think, in this state, the Set*ForTest methods wi
stevenjb 2013/05/13 23:49:35 If we exclusively use global accessors, then only
137 }
138 }
139 }
140
141 void NetworkHandler::SetNetworkStateHandlerForTest(
142 NetworkStateHandler* network_state_handler) {
143 test_network_state_handler_ = network_state_handler;
144 // Copy any existing observers to the test handler.
145 if (network_state_handler_.get()) {
146 ObserverList<NetworkStateHandlerObserver>::Iterator iter(
147 network_state_handler_->observers_);
148 NetworkStateHandlerObserver* observer;
149 while ((observer = iter.GetNext()) != NULL) {
150 test_network_state_handler_->AddObserver(observer);
151 }
152 }
153 }
154
155 void NetworkHandler::SetNetworkProfileHandlerForTest(
156 NetworkProfileHandler* network_profile_handler) {
157 test_network_profile_handler_ = network_profile_handler;
158 // Copy any existing observers to the test handler.
159 if (network_profile_handler_.get()) {
160 ObserverList<NetworkProfileObserver>::Iterator iter(
161 network_profile_handler_->observers_);
162 NetworkProfileObserver* observer;
163 while ((observer = iter.GetNext()) != NULL) {
164 test_network_profile_handler_->AddObserver(observer);
165 }
166 }
167 }
168
169 void NetworkHandler::SetNetworkConfigurationHandlerForTest(
170 NetworkConfigurationHandler* network_configuration_handler) {
171 test_network_configuration_handler_ = network_configuration_handler;
172 }
173
174 void NetworkHandler::SetManagedNetworkConfigurationHandlerForTest(
175 ManagedNetworkConfigurationHandler* managed_network_configuration_handler) {
176 test_managed_network_configuration_handler_ =
177 managed_network_configuration_handler;
178 }
179
180 void NetworkHandler::SetGeolocationHandlerForTest(
181 GeolocationHandler* geolocation_handler) {
182 test_geolocation_handler_ = geolocation_handler;
183 }
184
185 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698