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

Side by Side Diff: chrome/browser/extensions/api/dial/dial_api.cc

Issue 2750453002: Add DiscoveryNetworkMonitor implementation (Closed)
Patch Set: Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/dial/dial_api.h" 5 #include "chrome/browser/extensions/api/dial/dial_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 254
255 void DialFetchDeviceDescriptionFunction::OnFetchError( 255 void DialFetchDeviceDescriptionFunction::OnFetchError(
256 const std::string& message) { 256 const std::string& message) {
257 // Destroy the DeviceDescriptionFetcher since it still contains a reference 257 // Destroy the DeviceDescriptionFetcher since it still contains a reference
258 // to |this| in its un-invoked callback. 258 // to |this| in its un-invoked callback.
259 device_description_fetcher_.reset(); 259 device_description_fetcher_.reset();
260 SetError(message); 260 SetError(message);
261 SendResponse(false); 261 SendResponse(false);
262 } 262 }
263 263
264 DialGetNetworkIdFunction::DialGetNetworkIdFunction() {}
265
266 DialGetNetworkIdFunction::~DialGetNetworkIdFunction() {}
267
268 bool DialGetNetworkIdFunction::RunAsync() {
269 auto* network_monitor = DiscoveryNetworkMonitor::GetInstance();
270 // If we are the first to call the DiscoveryNetworkMonitor, it will have no
271 // network state. Force a refresh to be sure the network ID is populated.
272 network_monitor->ForceNetworkInfoRefresh(
273 base::Bind(&DialGetNetworkIdFunction::NetworkIdCallback, this));
274 return true;
275 }
276
277 void DialGetNetworkIdFunction::NetworkIdCallback() {
278 const auto* network_monitor = DiscoveryNetworkMonitor::GetInstance();
279 std::string network_id(network_monitor->GetNetworkId());
280 if (network_id.size() == 0) {
281 SetResult(base::MakeUnique<base::Value>(std::string("unknown")));
282 SendResponse(true);
283 return;
284 }
285 SetResult(base::MakeUnique<base::Value>(network_id));
286 SendResponse(true);
287 }
288
264 } // namespace extensions 289 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698