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

Side by Side Diff: components/wifi_sync/wifi_config_observer_chromeos.cc

Issue 1426393003: NOT FOR REVIEW Base URL: https://chromium.googlesource.com/chromium/src.git@submit-4.5-split-wcss
Patch Set: Created 5 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright 2015 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 "components/wifi_sync/wifi_config_observer_chromeos.h"
6
7 #include "base/location.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h"
11 #include "chromeos/network/managed_network_configuration_handler.h"
12 #include "chromeos/network/network_configuration_handler.h"
13 #include "chromeos/network/network_state.h"
14 #include "chromeos/network/network_state_handler.h"
15 #include "components/wifi_sync/wifi_credential.h"
16 #include "components/wifi_sync/wifi_credential_syncable_service.h"
17 #include "components/wifi_sync/wifi_security_class.h"
18 #include "third_party/cros_system_api/dbus/service_constants.h"
19
20 namespace wifi_sync {
21
22 WifiConfigObserverChromeOs::WifiConfigObserverChromeOs(
23 const std::string& user_hash,
24 chromeos::ManagedNetworkConfigurationHandler* managed_net_config_handler,
25 chromeos::NetworkConfigurationHandler* network_configuration_handler,
26 chromeos::NetworkStateHandler* network_state_handler)
27 : user_hash_(user_hash),
28 managed_network_configuration_handler_(managed_net_config_handler),
29 network_configuration_handler_(network_configuration_handler),
30 network_state_handler_(network_state_handler) {
31 LOG(ERROR) << "*** QUICHE: " << __func__;
32 DCHECK(managed_network_configuration_handler_);
33 DCHECK(network_configuration_handler_);
34 DCHECK(network_state_handler_);
35 network_configuration_handler_->AddObserver(this);
36 network_state_handler_->AddObserver(this, FROM_HERE);
37 }
38
39 WifiConfigObserverChromeOs::~WifiConfigObserverChromeOs() {
40 LOG(ERROR) << "*** QUICHE: " << __func__;
41 for (const WifiCredential& credential
42 : credentials_awaiting_syncable_service_) {
43 // TODO(quiche): Report event to UMA.
44 LOG(WARNING) << "No syncable_service_; did not sync "
45 << credential.ToString();
46 }
47
48 network_state_handler_->RemoveObserver(this, FROM_HERE);
49 network_configuration_handler_->RemoveObserver(this);
50 }
51
52 void WifiConfigObserverChromeOs::StartSyncing(
53 base::WeakPtr<WifiCredentialSyncableService> syncable_service) {
54 LOG(ERROR) << "*** QUICHE: " << __func__;
55 DCHECK(syncable_service);
56 DCHECK(!syncable_service_);
57 syncable_service_ = syncable_service;
58 for (const WifiCredential& credential
59 : credentials_awaiting_syncable_service_)
60 syncable_service_->AddToSyncedNetworks(credential);
61 credentials_awaiting_syncable_service_.clear();
62 }
63
64 void WifiConfigObserverChromeOs::StopSyncing() {
65 LOG(ERROR) << "*** QUICHE: " << __func__;
66 syncable_service_.reset();
67 }
68
69 // Note: This function is not called when a network is created from
70 // scan results. We handle such networks via OnPropertiesSet and/or
71 // OnConfigurationProfileChanged.
72 void WifiConfigObserverChromeOs::OnConfigurationCreated(
73 const std::string& service_path,
74 const std::string& profile_path,
75 const base::DictionaryValue& properties,
76 NetworkConfigurationObserver::Source source) {
77 LOG(ERROR) << "*** QUICHE: " << __func__;
78 std::string guid;
79 if (!properties.GetStringWithoutPathExpansion(shill::kGuidProperty, &guid)) {
80 LOG(ERROR) << "Failed to read GUID for " << service_path;
81 return;
82 }
83 ProcessProperties(guid, properties, source);
84 }
85
86 void WifiConfigObserverChromeOs::OnConfigurationRemoved(
87 const std::string& service_path,
88 const std::string& guid,
89 NetworkConfigurationObserver::Source source) {
90 LOG(ERROR) << "*** QUICHE: " << __func__;
91 if (source != SOURCE_USER_ACTION)
92 return;
93 // TODO(quiche): send this up to |syncable_service|. crbug.com/431439
94 NOTIMPLEMENTED();
95 }
96
97 void WifiConfigObserverChromeOs::OnPropertiesSet(
98 const std::string& service_path,
99 const std::string& guid,
100 const base::DictionaryValue& set_properties,
101 NetworkConfigurationObserver::Source source) {
102 LOG(ERROR) << "*** QUICHE: " << __func__;
103 ProcessProperties(guid, set_properties, source);
104 }
105
106 // XXX may happen after NetworkConnectionStateChanged
107 void WifiConfigObserverChromeOs::OnConfigurationProfileChanged(
108 const std::string& service_path,
109 const std::string& profile_path,
110 NetworkConfigurationObserver::Source source) {
111 LOG(ERROR) << "*** QUICHE: " << __func__;
112 // TODO(quiche): Consider removing this network from sync, if the
113 // new profile is not the user's profile, and is not the default
114 // profile.
115 // XXX need |source| check
116 const chromeos::NetworkState* network =
117 network_state_handler_->GetNetworkState(service_path);
118 if (!network) {
119 LOG(ERROR) << "Failed to get NetworkState for " << service_path;
120 return;
121 }
122 user_configured_service_guids_.insert(network->guid());
123 TryToSyncNetwork(network);
124 }
125
126 void WifiConfigObserverChromeOs::NetworkConnectionStateChanged(
127 const chromeos::NetworkState* network) {
128 LOG(ERROR) << "*** QUICHE: " << __func__;
129 DCHECK(network);
130
131 if (user_configured_service_guids_.find(network->guid()) ==
132 user_configured_service_guids_.end())
133 return;
134
135 TryToSyncNetwork(network);
136 }
137
138 // Private methods.
139
140 void WifiConfigObserverChromeOs::ProcessProperties(
141 const std::string& guid,
142 const base::DictionaryValue& service_properties,
143 NetworkConfigurationObserver::Source source) {
144 LOG(ERROR) << "*** QUICHE: " << __func__;
145 if (source != SOURCE_USER_ACTION) {
146 // XXX Determine if we need to filter this for only
147 // passphrase changes. We would need to do so if, e.g., we get a
148 // OnPropertiesSet call for MNCH auto-generating a GUID.
149 user_configured_service_guids_.erase(guid);
150 guid_to_passphrase_.erase(guid);
151 return;
152 }
153 user_configured_service_guids_.insert(guid);
154 SavePassphraseForService(guid, service_properties);
155 }
156
157 void WifiConfigObserverChromeOs::SavePassphraseForService(
158 const std::string& guid,
159 const base::DictionaryValue& service_properties) {
160 LOG(ERROR) << "*** QUICHE: " << __func__;
161 if (!service_properties.HasKey(shill::kPassphraseProperty))
162 return;
163
164 std::string passphrase;
165 if (!service_properties.GetStringWithoutPathExpansion(
166 shill::kPassphraseProperty, &passphrase)) {
167 NOTREACHED() << "Property " << shill::kPassphraseProperty
168 << " for service with guid " << guid
169 << " is not a string";
170 return;
171 }
172
173 guid_to_passphrase_[guid] = passphrase;
174 }
175
176 void WifiConfigObserverChromeOs::TryToSyncNetwork(
177 const chromeos::NetworkState* network) {
178 LOG(ERROR) << "*** QUICHE: " << __func__;
179 const std::string device_policy_id = "";
180 ::onc::ONCSource onc_source;
181 if (managed_network_configuration_handler_->FindPolicyByGUID(
182 device_policy_id, network->guid(), &onc_source) ||
183 managed_network_configuration_handler_->FindPolicyByGUID(
184 user_hash_, network->guid(), &onc_source))
185 return;
186
187 LOG(ERROR) << "*** QUICHE: " << __func__;
188 if (network->type() != shill::kTypeWifi) // XXX check hdr
189 return;
190
191 LOG(ERROR) << "*** QUICHE: " << __func__ << ": "
192 << "network " << network << " "
193 << "path " << network->path() << " "
194 << "connection state " << network->connection_state();
195 if (!network->IsConnectedState())
196 return; // Wait until we complete the connection.
197
198 LOG(ERROR) << "*** QUICHE: " << __func__;
199 WifiSecurityClass security_class =
200 WifiSecurityClassFromShillSecurity(network->security_class());
201 if (!WifiSecurityClassIsSyncable(security_class))
202 return;
203
204 LOG(ERROR) << "*** QUICHE: " << __func__;
205 std::string passphrase;
206 if (WifiSecurityClassSupportsPassphrases(security_class)) {
207 const auto guid_to_passphrase_it =
208 guid_to_passphrase_.find(network->guid());
209 if (guid_to_passphrase_it != guid_to_passphrase_.end()) {
210 passphrase = guid_to_passphrase_it->second;
211 } else if (WifiSecurityClassRequiresPassphrase(security_class)) {
212 LOG(ERROR) << "Required passphrase is missing; skipping sync";
213 return;
214 }
215 }
216 guid_to_passphrase_.erase(network->guid());
217
218 LOG(ERROR) << "*** QUICHE: " << __func__;
219 scoped_ptr<WifiCredential> credential =
220 WifiCredential::Create(network->raw_ssid(), security_class, passphrase);
221 if (!credential) {
222 LOG(ERROR) << "Failed to create credential; skipping sync";
223 return;
224 }
225
226 LOG(ERROR) << "*** QUICHE: " << __func__;
227 if (syncable_service_)
228 syncable_service_->AddToSyncedNetworks(*credential);
229 else
230 credentials_awaiting_syncable_service_.push_back(*credential);
231
232 // user_configured_service_guids_.erase(network->guid());
233 }
234
235 } // namespace wifi_sync
OLDNEW
« no previous file with comments | « components/wifi_sync/wifi_config_observer_chromeos.h ('k') | components/wifi_sync/wifi_config_observer_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698