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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/dial/dial_api.cc
diff --git a/chrome/browser/extensions/api/dial/dial_api.cc b/chrome/browser/extensions/api/dial/dial_api.cc
index e97f90fa0b260780ad189b0ce32a5c585dd4c248..6b59f29df083377b7a12061143e5f69b45d23708 100644
--- a/chrome/browser/extensions/api/dial/dial_api.cc
+++ b/chrome/browser/extensions/api/dial/dial_api.cc
@@ -261,4 +261,29 @@ void DialFetchDeviceDescriptionFunction::OnFetchError(
SendResponse(false);
}
+DialGetNetworkIdFunction::DialGetNetworkIdFunction() {}
+
+DialGetNetworkIdFunction::~DialGetNetworkIdFunction() {}
+
+bool DialGetNetworkIdFunction::RunAsync() {
+ auto* network_monitor = DiscoveryNetworkMonitor::GetInstance();
+ // If we are the first to call the DiscoveryNetworkMonitor, it will have no
+ // network state. Force a refresh to be sure the network ID is populated.
+ network_monitor->ForceNetworkInfoRefresh(
+ base::Bind(&DialGetNetworkIdFunction::NetworkIdCallback, this));
+ return true;
+}
+
+void DialGetNetworkIdFunction::NetworkIdCallback() {
+ const auto* network_monitor = DiscoveryNetworkMonitor::GetInstance();
+ std::string network_id(network_monitor->GetNetworkId());
+ if (network_id.size() == 0) {
+ SetResult(base::MakeUnique<base::Value>(std::string("unknown")));
+ SendResponse(true);
+ return;
+ }
+ SetResult(base::MakeUnique<base::Value>(network_id));
+ SendResponse(true);
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698