Index: chrome/browser/extensions/api/gcd_private/gcd_private_api.cc |
diff --git a/chrome/browser/extensions/api/gcd_private/gcd_private_api.cc b/chrome/browser/extensions/api/gcd_private/gcd_private_api.cc |
index 3f7355747bc6e147d8d0f656d662b9876daa52e1..bc64a016176b3ba11be3873f238415c2b89cfdfd 100644 |
--- a/chrome/browser/extensions/api/gcd_private/gcd_private_api.cc |
+++ b/chrome/browser/extensions/api/gcd_private/gcd_private_api.cc |
@@ -23,13 +23,13 @@ namespace gcd_private = api::gcd_private; |
namespace { |
-scoped_ptr<Event> MakeCloudDeviceStateChangedEvent( |
+scoped_ptr<Event> MakeLocalDeviceStateChangedEvent( |
bool available, |
const gcd_private::GCDDevice& device) { |
scoped_ptr<base::ListValue> params = |
- gcd_private::OnCloudDeviceStateChanged::Create(available, device); |
+ gcd_private::OnLocalDeviceStateChanged::Create(available, device); |
scoped_ptr<Event> event(new Event( |
- gcd_private::OnCloudDeviceStateChanged::kEventName, params.Pass())); |
+ gcd_private::OnLocalDeviceStateChanged::kEventName, params.Pass())); |
return event.Pass(); |
} |
@@ -73,7 +73,7 @@ GcdPrivateAPI::GcdPrivateAPI(content::BrowserContext* context) |
: num_device_listeners_(0), browser_context_(context) { |
DCHECK(browser_context_); |
EventRouter::Get(context)->RegisterObserver( |
- this, gcd_private::OnCloudDeviceStateChanged::kEventName); |
+ this, gcd_private::OnLocalDeviceStateChanged::kEventName); |
} |
GcdPrivateAPI::~GcdPrivateAPI() { |
@@ -120,7 +120,7 @@ void GcdPrivateAPI::OnListenerAdded(const EventListenerInfo& details) { |
i++) { |
EventRouter::Get(browser_context_)->DispatchEventToExtension( |
details.extension_id, |
- MakeCloudDeviceStateChangedEvent(true, *i->second)); |
+ MakeLocalDeviceStateChangedEvent(true, *i->second)); |
} |
} |
@@ -154,7 +154,7 @@ void GcdPrivateAPI::DeviceChanged( |
known_devices_[device->id_string] = device; |
EventRouter::Get(browser_context_) |
- ->BroadcastEvent(MakeCloudDeviceStateChangedEvent(true, *device)); |
+ ->BroadcastEvent(MakeLocalDeviceStateChangedEvent(true, *device)); |
} |
void GcdPrivateAPI::DeviceRemoved(const std::string& name) { |
@@ -164,7 +164,7 @@ void GcdPrivateAPI::DeviceRemoved(const std::string& name) { |
known_devices_.erase(found); |
EventRouter::Get(browser_context_) |
- ->BroadcastEvent(MakeCloudDeviceStateChangedEvent(false, *device)); |
+ ->BroadcastEvent(MakeLocalDeviceStateChangedEvent(false, *device)); |
} |
void GcdPrivateAPI::DeviceCacheFlushed() { |
@@ -172,7 +172,7 @@ void GcdPrivateAPI::DeviceCacheFlushed() { |
i != known_devices_.end(); |
i++) { |
EventRouter::Get(browser_context_) |
- ->BroadcastEvent(MakeCloudDeviceStateChangedEvent(false, *i->second)); |
+ ->BroadcastEvent(MakeLocalDeviceStateChangedEvent(false, *i->second)); |
} |
known_devices_.clear(); |
@@ -200,10 +200,19 @@ void GcdPrivateAPI::OnBootstrappingDeviceUpdate( |
} |
EventRouter::Get(browser_context_) |
- ->BroadcastEvent(MakeCloudDeviceStateChangedEvent(available, *device)); |
+ ->BroadcastEvent(MakeLocalDeviceStateChangedEvent(available, *device)); |
} |
#endif // ENABLE_WIFI_BOOTSTRAPPING |
+bool GcdPrivateAPI::QueryForDevices() { |
+ if (!privet_device_lister_) |
+ return false; |
+ |
+ privet_device_lister_->DiscoverNewDevices(true); |
+ |
+ return true; |
+} |
+ |
// static |
void GcdPrivateAPI::SetGCDApiFlowFactoryForTests( |
GCDApiFlowFactoryForTests* factory) { |
@@ -285,4 +294,28 @@ void GcdPrivateGetCloudDeviceListFunction::CheckListingDone() { |
Release(); |
} |
+GcdPrivateQueryForNewLocalDevicesFunction:: |
+ GcdPrivateQueryForNewLocalDevicesFunction() { |
+} |
+ |
+GcdPrivateQueryForNewLocalDevicesFunction:: |
+ ~GcdPrivateQueryForNewLocalDevicesFunction() { |
+} |
+ |
+bool GcdPrivateQueryForNewLocalDevicesFunction::RunSync() { |
+ GcdPrivateAPI* gcd_api = |
+ BrowserContextKeyedAPIFactory<GcdPrivateAPI>::Get(GetProfile()); |
+ |
+ if (!gcd_api) |
+ return false; |
+ |
+ if (!gcd_api->QueryForDevices()) { |
+ error_ = |
+ "You must first subscribe to onLocalDeviceStateChanged notifications"; |
+ return false; |
+ } |
+ |
+ return true; |
+} |
+ |
} // namespace extensions |