Add API stubs for GCD device commands.

Changed registration API to work for one network at once.
Fixed comments.
Replaced argument GCDDevice with just string id.

BUG=383167
R=alexsemenov@chromium.org, asargent@chromium.org, asvitkine@chromium.org, noamsml@chromium.org

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=282099

Review URL: https://codereview.chromium.org/363883002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282273 0039d316-1c4b-4281-b951-d872f2087c98
parent f917df27
...@@ -23,22 +23,29 @@ namespace gcd_private = api::gcd_private; ...@@ -23,22 +23,29 @@ namespace gcd_private = api::gcd_private;
namespace { namespace {
scoped_ptr<Event> MakeCloudDeviceStateChangedEvent(
bool available,
const gcd_private::GCDDevice& device) {
scoped_ptr<base::ListValue> params =
gcd_private::OnCloudDeviceStateChanged::Create(available, device);
scoped_ptr<Event> event(new Event(
gcd_private::OnCloudDeviceStateChanged::kEventName, params.Pass()));
return event.Pass();
}
const int kNumRequestsNeeded = 2; const int kNumRequestsNeeded = 2;
const char kIDPrefixCloudPrinter[] = "cloudprint:"; const char kIDPrefixCloudPrinter[] = "cloudprint:";
const char kIDPrefixGcd[] = "gcd:"; const char kIDPrefixGcd[] = "gcd:";
const char kIDPrefixMdns[] = "mdns:"; const char kIDPrefixMdns[] = "mdns:";
scoped_ptr<Event> MakeDeviceStateChangedEvent(
const gcd_private::GCDDevice& device) {
scoped_ptr<base::ListValue> params =
gcd_private::OnDeviceStateChanged::Create(device);
scoped_ptr<Event> event(
new Event(gcd_private::OnDeviceStateChanged::kEventName, params.Pass()));
return event.Pass();
}
scoped_ptr<Event> MakeDeviceRemovedEvent(const std::string& device) {
scoped_ptr<base::ListValue> params =
gcd_private::OnDeviceRemoved::Create(device);
scoped_ptr<Event> event(
new Event(gcd_private::OnDeviceRemoved::kEventName, params.Pass()));
return event.Pass();
}
GcdPrivateAPI::GCDApiFlowFactoryForTests* g_gcd_api_flow_factory = NULL; GcdPrivateAPI::GCDApiFlowFactoryForTests* g_gcd_api_flow_factory = NULL;
base::LazyInstance<BrowserContextKeyedAPIFactory<GcdPrivateAPI> > g_factory = base::LazyInstance<BrowserContextKeyedAPIFactory<GcdPrivateAPI> > g_factory =
...@@ -69,8 +76,10 @@ GcdPrivateAPI::GcdPrivateAPI(content::BrowserContext* context) ...@@ -69,8 +76,10 @@ GcdPrivateAPI::GcdPrivateAPI(content::BrowserContext* context)
: num_device_listeners_(0), browser_context_(context) { : num_device_listeners_(0), browser_context_(context) {
DCHECK(browser_context_); DCHECK(browser_context_);
if (EventRouter::Get(context)) { if (EventRouter::Get(context)) {
EventRouter::Get(context)->RegisterObserver( EventRouter::Get(context)
this, gcd_private::OnCloudDeviceStateChanged::kEventName); ->RegisterObserver(this, gcd_private::OnDeviceStateChanged::kEventName);
EventRouter::Get(context)
->RegisterObserver(this, gcd_private::OnDeviceRemoved::kEventName);
} }
} }
...@@ -87,31 +96,36 @@ GcdPrivateAPI::GetFactoryInstance() { ...@@ -87,31 +96,36 @@ GcdPrivateAPI::GetFactoryInstance() {
} }
void GcdPrivateAPI::OnListenerAdded(const EventListenerInfo& details) { void GcdPrivateAPI::OnListenerAdded(const EventListenerInfo& details) {
num_device_listeners_++; if (details.event_name == gcd_private::OnDeviceStateChanged::kEventName ||
details.event_name == gcd_private::OnDeviceRemoved::kEventName) {
if (num_device_listeners_ == 1) { num_device_listeners_++;
service_discovery_client_ =
local_discovery::ServiceDiscoverySharedClient::GetInstance(); if (num_device_listeners_ == 1) {
privet_device_lister_.reset(new local_discovery::PrivetDeviceListerImpl( service_discovery_client_ =
service_discovery_client_.get(), this)); local_discovery::ServiceDiscoverySharedClient::GetInstance();
privet_device_lister_->Start(); privet_device_lister_.reset(new local_discovery::PrivetDeviceListerImpl(
} service_discovery_client_.get(), this));
privet_device_lister_->Start();
}
for (GCDDeviceMap::iterator i = known_devices_.begin(); for (GCDDeviceMap::iterator i = known_devices_.begin();
i != known_devices_.end(); i != known_devices_.end();
i++) { i++) {
EventRouter::Get(browser_context_)->DispatchEventToExtension( EventRouter::Get(browser_context_)->DispatchEventToExtension(
details.extension_id, details.extension_id, MakeDeviceStateChangedEvent(*i->second));
MakeCloudDeviceStateChangedEvent(true, *i->second)); }
} }
} }
void GcdPrivateAPI::OnListenerRemoved(const EventListenerInfo& details) { void GcdPrivateAPI::OnListenerRemoved(const EventListenerInfo& details) {
num_device_listeners_--; if (details.event_name == gcd_private::OnDeviceStateChanged::kEventName ||
details.event_name == gcd_private::OnDeviceRemoved::kEventName) {
num_device_listeners_--;
if (num_device_listeners_ == 0) { if (num_device_listeners_ == 0) {
privet_device_lister_.reset(); privet_device_lister_.reset();
service_discovery_client_ = NULL; service_discovery_client_ = NULL;
}
} }
} }
...@@ -121,17 +135,17 @@ void GcdPrivateAPI::DeviceChanged( ...@@ -121,17 +135,17 @@ void GcdPrivateAPI::DeviceChanged(
const local_discovery::DeviceDescription& description) { const local_discovery::DeviceDescription& description) {
linked_ptr<gcd_private::GCDDevice> device(new gcd_private::GCDDevice); linked_ptr<gcd_private::GCDDevice> device(new gcd_private::GCDDevice);
device->setup_type = gcd_private::SETUP_TYPE_MDNS; device->setup_type = gcd_private::SETUP_TYPE_MDNS;
device->id_string = kIDPrefixMdns + name; device->device_id = kIDPrefixMdns + name;
device->device_type = description.type; device->device_type = description.type;
device->device_name = description.name; device->device_name = description.name;
device->device_description = description.description; device->device_description = description.description;
if (!description.id.empty()) if (!description.id.empty())
device->cloud_id.reset(new std::string(description.id)); device->cloud_id.reset(new std::string(description.id));
known_devices_[device->id_string] = device; known_devices_[device->device_id] = device;
EventRouter::Get(browser_context_) EventRouter::Get(browser_context_)
->BroadcastEvent(MakeCloudDeviceStateChangedEvent(true, *device)); ->BroadcastEvent(MakeDeviceStateChangedEvent(*device));
} }
void GcdPrivateAPI::DeviceRemoved(const std::string& name) { void GcdPrivateAPI::DeviceRemoved(const std::string& name) {
...@@ -140,7 +154,7 @@ void GcdPrivateAPI::DeviceRemoved(const std::string& name) { ...@@ -140,7 +154,7 @@ void GcdPrivateAPI::DeviceRemoved(const std::string& name) {
known_devices_.erase(found); known_devices_.erase(found);
EventRouter::Get(browser_context_) EventRouter::Get(browser_context_)
->BroadcastEvent(MakeCloudDeviceStateChangedEvent(false, *device)); ->BroadcastEvent(MakeDeviceRemovedEvent(device->device_id));
} }
void GcdPrivateAPI::DeviceCacheFlushed() { void GcdPrivateAPI::DeviceCacheFlushed() {
...@@ -148,7 +162,7 @@ void GcdPrivateAPI::DeviceCacheFlushed() { ...@@ -148,7 +162,7 @@ void GcdPrivateAPI::DeviceCacheFlushed() {
i != known_devices_.end(); i != known_devices_.end();
i++) { i++) {
EventRouter::Get(browser_context_) EventRouter::Get(browser_context_)
->BroadcastEvent(MakeCloudDeviceStateChangedEvent(false, *i->second)); ->BroadcastEvent(MakeDeviceRemovedEvent(i->second->device_id));
} }
known_devices_.clear(); known_devices_.clear();
...@@ -216,9 +230,9 @@ void GcdPrivateGetCloudDeviceListFunction::CheckListingDone() { ...@@ -216,9 +230,9 @@ void GcdPrivateGetCloudDeviceListFunction::CheckListingDone() {
linked_ptr<gcd_private::GCDDevice> device(new gcd_private::GCDDevice); linked_ptr<gcd_private::GCDDevice> device(new gcd_private::GCDDevice);
device->setup_type = gcd_private::SETUP_TYPE_CLOUD; device->setup_type = gcd_private::SETUP_TYPE_CLOUD;
if (i->type == local_discovery::kGCDTypePrinter) { if (i->type == local_discovery::kGCDTypePrinter) {
device->id_string = kIDPrefixCloudPrinter + i->id; device->device_id = kIDPrefixCloudPrinter + i->id;
} else { } else {
device->id_string = kIDPrefixGcd + i->id; device->device_id = kIDPrefixGcd + i->id;
} }
device->cloud_id.reset(new std::string(i->id)); device->cloud_id.reset(new std::string(i->id));
...@@ -235,6 +249,18 @@ void GcdPrivateGetCloudDeviceListFunction::CheckListingDone() { ...@@ -235,6 +249,18 @@ void GcdPrivateGetCloudDeviceListFunction::CheckListingDone() {
Release(); Release();
} }
GcdPrivateQueryForNewLocalDevicesFunction::
GcdPrivateQueryForNewLocalDevicesFunction() {
}
GcdPrivateQueryForNewLocalDevicesFunction::
~GcdPrivateQueryForNewLocalDevicesFunction() {
}
bool GcdPrivateQueryForNewLocalDevicesFunction::RunSync() {
return false;
}
GcdPrivateStartSetupFunction::GcdPrivateStartSetupFunction() { GcdPrivateStartSetupFunction::GcdPrivateStartSetupFunction() {
} }
...@@ -245,23 +271,23 @@ bool GcdPrivateStartSetupFunction::RunAsync() { ...@@ -245,23 +271,23 @@ bool GcdPrivateStartSetupFunction::RunAsync() {
return false; return false;
} }
GcdPrivateSetWiFiNetworksFunction::GcdPrivateSetWiFiNetworksFunction() { GcdPrivateSetWiFiNetworkFunction::GcdPrivateSetWiFiNetworkFunction() {
} }
GcdPrivateSetWiFiNetworksFunction::~GcdPrivateSetWiFiNetworksFunction() { GcdPrivateSetWiFiNetworkFunction::~GcdPrivateSetWiFiNetworkFunction() {
} }
bool GcdPrivateSetWiFiNetworksFunction::RunAsync() { bool GcdPrivateSetWiFiNetworkFunction::RunAsync() {
return false; return false;
} }
GcdPrivateSetWiFiCredentialsFunction::GcdPrivateSetWiFiCredentialsFunction() { GcdPrivateSetWiFiPasswordFunction::GcdPrivateSetWiFiPasswordFunction() {
} }
GcdPrivateSetWiFiCredentialsFunction::~GcdPrivateSetWiFiCredentialsFunction() { GcdPrivateSetWiFiPasswordFunction::~GcdPrivateSetWiFiPasswordFunction() {
} }
bool GcdPrivateSetWiFiCredentialsFunction::RunAsync() { bool GcdPrivateSetWiFiPasswordFunction::RunAsync() {
return false; return false;
} }
...@@ -285,4 +311,56 @@ bool GcdPrivateStopSetupFunction::RunAsync() { ...@@ -285,4 +311,56 @@ bool GcdPrivateStopSetupFunction::RunAsync() {
return false; return false;
} }
GcdPrivateGetCommandDefinitionsFunction::
GcdPrivateGetCommandDefinitionsFunction() {
}
GcdPrivateGetCommandDefinitionsFunction::
~GcdPrivateGetCommandDefinitionsFunction() {
}
bool GcdPrivateGetCommandDefinitionsFunction::RunAsync() {
return false;
}
GcdPrivateInsertCommandFunction::GcdPrivateInsertCommandFunction() {
}
GcdPrivateInsertCommandFunction::~GcdPrivateInsertCommandFunction() {
}
bool GcdPrivateInsertCommandFunction::RunAsync() {
return false;
}
GcdPrivateGetCommandFunction::GcdPrivateGetCommandFunction() {
}
GcdPrivateGetCommandFunction::~GcdPrivateGetCommandFunction() {
}
bool GcdPrivateGetCommandFunction::RunAsync() {
return false;
}
GcdPrivateCancelCommandFunction::GcdPrivateCancelCommandFunction() {
}
GcdPrivateCancelCommandFunction::~GcdPrivateCancelCommandFunction() {
}
bool GcdPrivateCancelCommandFunction::RunAsync() {
return false;
}
GcdPrivateGetCommandsListFunction::GcdPrivateGetCommandsListFunction() {
}
GcdPrivateGetCommandsListFunction::~GcdPrivateGetCommandsListFunction() {
}
bool GcdPrivateGetCommandsListFunction::RunAsync() {
return false;
}
} // namespace extensions } // namespace extensions
...@@ -98,7 +98,7 @@ class GcdPrivateGetCloudDeviceListFunction ...@@ -98,7 +98,7 @@ class GcdPrivateGetCloudDeviceListFunction
}; };
class GcdPrivateQueryForNewLocalDevicesFunction class GcdPrivateQueryForNewLocalDevicesFunction
: public ChromeAsyncExtensionFunction { : public ChromeSyncExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("gcdPrivate.queryForNewLocalDevices", DECLARE_EXTENSION_FUNCTION("gcdPrivate.queryForNewLocalDevices",
GCDPRIVATE_QUERYFORNEWLOCALDEVICES) GCDPRIVATE_QUERYFORNEWLOCALDEVICES)
...@@ -108,8 +108,8 @@ class GcdPrivateQueryForNewLocalDevicesFunction ...@@ -108,8 +108,8 @@ class GcdPrivateQueryForNewLocalDevicesFunction
protected: protected:
virtual ~GcdPrivateQueryForNewLocalDevicesFunction(); virtual ~GcdPrivateQueryForNewLocalDevicesFunction();
// AsyncExtensionFunction overrides. // SyncExtensionFunction overrides.
virtual bool RunAsync() OVERRIDE; virtual bool RunSync() OVERRIDE;
}; };
class GcdPrivateStartSetupFunction : public ChromeAsyncExtensionFunction { class GcdPrivateStartSetupFunction : public ChromeAsyncExtensionFunction {
...@@ -128,15 +128,15 @@ class GcdPrivateStartSetupFunction : public ChromeAsyncExtensionFunction { ...@@ -128,15 +128,15 @@ class GcdPrivateStartSetupFunction : public ChromeAsyncExtensionFunction {
private: private:
}; };
class GcdPrivateSetWiFiNetworksFunction : public ChromeAsyncExtensionFunction { class GcdPrivateSetWiFiNetworkFunction : public ChromeAsyncExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("gcdPrivate.setWiFiNetworks", DECLARE_EXTENSION_FUNCTION("gcdPrivate.setWiFiNetwork",
GCDPRIVATE_SETWIFINETWORKS) GCDPRIVATE_SETWIFINETWORK)
GcdPrivateSetWiFiNetworksFunction(); GcdPrivateSetWiFiNetworkFunction();
protected: protected:
virtual ~GcdPrivateSetWiFiNetworksFunction(); virtual ~GcdPrivateSetWiFiNetworkFunction();
// AsyncExtensionFunction overrides. // AsyncExtensionFunction overrides.
virtual bool RunAsync() OVERRIDE; virtual bool RunAsync() OVERRIDE;
...@@ -144,16 +144,15 @@ class GcdPrivateSetWiFiNetworksFunction : public ChromeAsyncExtensionFunction { ...@@ -144,16 +144,15 @@ class GcdPrivateSetWiFiNetworksFunction : public ChromeAsyncExtensionFunction {
private: private:
}; };
class GcdPrivateSetWiFiCredentialsFunction class GcdPrivateSetWiFiPasswordFunction : public ChromeAsyncExtensionFunction {
: public ChromeAsyncExtensionFunction {
public: public:
DECLARE_EXTENSION_FUNCTION("gcdPrivate.setWiFiCredentials", DECLARE_EXTENSION_FUNCTION("gcdPrivate.setWiFiPassword",
GCDPRIVATE_SETWIFICREDENTIALS) GCDPRIVATE_SETWIFIPASSWORD)
GcdPrivateSetWiFiCredentialsFunction(); GcdPrivateSetWiFiPasswordFunction();
protected: protected:
virtual ~GcdPrivateSetWiFiCredentialsFunction(); virtual ~GcdPrivateSetWiFiPasswordFunction();
// AsyncExtensionFunction overrides. // AsyncExtensionFunction overrides.
virtual bool RunAsync() OVERRIDE; virtual bool RunAsync() OVERRIDE;
...@@ -191,6 +190,86 @@ class GcdPrivateStopSetupFunction : public ChromeAsyncExtensionFunction { ...@@ -191,6 +190,86 @@ class GcdPrivateStopSetupFunction : public ChromeAsyncExtensionFunction {
private: private:
}; };
class GcdPrivateGetCommandDefinitionsFunction
: public ChromeAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommandDefinitions",
GCDPRIVATE_GETCOMMANDDEFINITIONS)
GcdPrivateGetCommandDefinitionsFunction();
protected:
virtual ~GcdPrivateGetCommandDefinitionsFunction();
// AsyncExtensionFunction overrides.
virtual bool RunAsync() OVERRIDE;
private:
};
class GcdPrivateInsertCommandFunction : public ChromeAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("gcdPrivate.insertCommand",
GCDPRIVATE_INSERTCOMMAND)
GcdPrivateInsertCommandFunction();
protected:
virtual ~GcdPrivateInsertCommandFunction();
// AsyncExtensionFunction overrides.
virtual bool RunAsync() OVERRIDE;
private:
};
class GcdPrivateGetCommandFunction : public ChromeAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommand", GCDPRIVATE_GETCOMMAND)
GcdPrivateGetCommandFunction();
protected:
virtual ~GcdPrivateGetCommandFunction();
// AsyncExtensionFunction overrides.
virtual bool RunAsync() OVERRIDE;
private:
};
class GcdPrivateCancelCommandFunction : public ChromeAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("gcdPrivate.cancelCommand",
GCDPRIVATE_CANCELCOMMAND)
GcdPrivateCancelCommandFunction();
protected:
virtual ~GcdPrivateCancelCommandFunction();
// AsyncExtensionFunction overrides.
virtual bool RunAsync() OVERRIDE;
private:
};
class GcdPrivateGetCommandsListFunction : public ChromeAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommandsList",
GCDPRIVATE_GETCOMMANDSLIST)
GcdPrivateGetCommandsListFunction();
protected:
virtual ~GcdPrivateGetCommandsListFunction();
// AsyncExtensionFunction overrides.
virtual bool RunAsync() OVERRIDE;
private:
};
} // namespace extensions } // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_ #endif // CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_
...@@ -10,53 +10,66 @@ namespace gcdPrivate { ...@@ -10,53 +10,66 @@ namespace gcdPrivate {
// Represents a GCD device discovered locally or registered to a given user. // Represents a GCD device discovered locally or registered to a given user.
dictionary GCDDevice { dictionary GCDDevice {
// Opaque device identifier to be passed to API.
DOMString deviceId;
// How this device was discovered. // How this device was discovered.
SetupType setupType; SetupType setupType;
// Opaque device identifier to be passed to API.
DOMString idString;
// Cloud identifier string. // Cloud identifier string.
DOMString? cloudId; DOMString? cloudId;
// Device type (camera, printer, etc) // Device type (camera, printer, etc)
DOMString deviceType; DOMString deviceType;
// Device human readable name // Device human readable name.
DOMString deviceName; DOMString deviceName;
// Device human readable description // Device human readable description.
DOMString deviceDescription; DOMString deviceDescription;
}; };
// Represents wifi network credentials.
dictionary WiFiCredentials {
DOMString ssid;
DOMString password;
};
callback CloudDeviceListCallback = void(GCDDevice[] devices); callback CloudDeviceListCallback = void(GCDDevice[] devices);
// |commandDefinitions| : Is "commandDefs" value of device described at
// https://developers.google.com/cloud-devices/v1/reference/devices
// TODO(vitalybuka): consider to describe object in IDL.
callback CommandDefinitionsCallback = void(object commandDefinitions);
// |command| : Described at
// https://developers.google.com/cloud-devices/v1/reference/commands
// TODO(vitalybuka): consider to describe object in IDL.
callback CommandCallback = void(object command);
// |commands| : Array of commands described at
// https://developers.google.com/cloud-devices/v1/reference/commands
// TODO(vitalybuka): consider to describe object in IDL.
callback CommandListCallback = void(object[] commands);
interface Functions { interface Functions {
// Returns the list of cloud devices visible locally or available in the
// cloud for user account.
static void getCloudDeviceList(CloudDeviceListCallback callback); static void getCloudDeviceList(CloudDeviceListCallback callback);
// Queries network for local devices. Triggers an onDeviceStateChanged and
// onDeviceRemoved events. Call this function *only* after registering for
// onDeviceStateChanged and onDeviceRemoved events, or it will do nothing.
static void queryForNewLocalDevices();
// Starts device setup process. Returns id of setup process. Id should be // Starts device setup process. Returns id of setup process. Id should be
// used as |setupId| in all subsequent setup related calls, and for // used as |setupId| in all subsequent setup related calls, and for
// filtering setup events. // filtering setup events.
static long startSetup(GCDDevice device); static long startSetup(DOMString deviceId);
// Sets WiFi network list as reply to |onGetWifiNetworks| event. // Sets WiFi network as reply to |onGetWifiNetworks| event.
// |setupId| : The value returned by |startSetup|. // |setupId| : The value returned by |startSetup|.
// |networks| : The list of network device should be registered on. // |network| : The wifi network for device setup.
static void setWiFiNetworks(long setupId, DOMString[] networks); static void setWiFiNetwork(long setupId, DOMString network);
// Sets WiFi network credentials as reply to |onGetWifiCredentials| // Sets WiFi network password as reply to |onGetWifiPassword| event.
// event.
// |setupId| : The value returned by |startSetup|. // |setupId| : The value returned by |startSetup|.
// |credentials| : The list of ssid with passwoors. The list is not required // |password| : The password for network selected with |setWiFiNetwork|.
// to match |networks| provided with |setWiFiNetworks| or static void setWiFiPassword(long setupId, DOMString password);
// |onGetWifiCredentials|.
static void setWiFiCredentials(long setupId, WiFiCredentials[] credentials);
// Confirms that security code known to application match to the code known // Confirms that security code known to application match to the code known
// to device. // to device.
...@@ -68,24 +81,70 @@ namespace gcdPrivate { ...@@ -68,24 +81,70 @@ namespace gcdPrivate {
// starting new registration. // starting new registration.
// |setupId| : The value returned by |startSetup|. // |setupId| : The value returned by |startSetup|.
static void stopSetup(long setupId); static void stopSetup(long setupId);
// Returns command definitions.
// |deviceId| : The device to get command definitions for.
// |callback| : The result callback.
static void getCommandDefinitions(DOMString deviceId,
CommandDefinitionsCallback callback);
// Creates and sends a new command.
// |deviceId| : The device to send the command to.
// |expireInMs| : The number of milliseconds since now before the command
// expires. Expired command should not be executed by device. Acceptable
// values are 10000 to 2592000000, inclusive. All values outside that range
// will be replaced by 2592000000.
// |command| : Described at
// https://developers.google.com/cloud-devices/v1/reference/commands
// |callback| : The result callback.
static void insertCommand(DOMString deviceId,
long expireInMs,
object command,
CommandCallback callback);
// Returns a particular command.
// |commandId| : Unique command ID.
// |callback| : The result callback.
static void getCommand(DOMString commandId, CommandCallback callback);
// Cancels a command.
// |commandId| : Unique command ID.
// |callback| : The result callback.
static void cancelCommand(DOMString commandId, CommandCallback callback);
// Lists all commands in order of creation.
// |deviceId| : The device to get the commands for.
// |byUser| : List all the commands issued by the user. Special value 'me'
// can be used to list by the current user.
// |state| : Command state.
// |callback| : The result callback.
static void getCommandsList(DOMString deviceId,
DOMString byUser,
DOMString state,
CommandListCallback callback);
}; };
interface Events { interface Events {
// Subscribe to this event to start listening to cloud devices. New // Subscribe to this event to start listening new or updated devices. New
// listeners will get called with all known devices on the network. // listeners will get called with all known devices on the network, and
static void onCloudDeviceStateChanged(boolean available, GCDDevice device); // status updates for devices available through the cloud.
static void onDeviceStateChanged(GCDDevice device);
// Notifies that device has disappeared.
// |deviceId| : The device has disappeared.
static void onDeviceRemoved(DOMString deviceId);
// Notifies app that setup is waiting for network list. App should reply // Notifies app that setup is waiting for a wifi network. App should reply
// with |setWiFiNetworks|. // with |setWiFiNetwork|.
// |setupId| : The value returned by |startSetup|. // |setupId| : The value returned by |startSetup|.
static void onGetWifiNetworks(long setupId); static void onGetWifiNetwork(long setupId);
// Notifies app that setup is waiting for credentions for |networks| list. // Notifies app that setup is waiting for password for the network provided
// App should reply with |setWiFiCredentials|. // with |setWiFiNetwork|. Even will be called if setup flow would unable to
// get password from the system.
// App should reply with |setWiFiPassword|.
// |setupId| : The value returned by |startSetup|. // |setupId| : The value returned by |startSetup|.
// |networks| : A subset of the list provided in |setWiFiNetworks| for which static void onGetWifiPassword(long setupId);
// setup flow is unable to find credentials
static void onGetWifiCredentials(long setupId, DOMString[] networks);
// Notifies app that setup is waiting for confirmation that code is the same // Notifies app that setup is waiting for confirmation that code is the same
// as code known to device. App should reply with |confirmCode|, or // as code known to device. App should reply with |confirmCode|, or
...@@ -98,7 +157,7 @@ namespace gcdPrivate { ...@@ -98,7 +157,7 @@ namespace gcdPrivate {
// |setupId| : The value returned by |startSetup|. // |setupId| : The value returned by |startSetup|.
static void onSetupSuccess(long setupId); static void onSetupSuccess(long setupId);
// Notifies app that setup is failed or stoped. // Notifies app that setup is failed or stopped.
// |setupId| : The value returned by |startSetup|. // |setupId| : The value returned by |startSetup|.
static void onSetupError(long setupId); static void onSetupError(long setupId);
}; };
......
...@@ -8,13 +8,13 @@ onload = function() { ...@@ -8,13 +8,13 @@ onload = function() {
chrome.gcdPrivate.getCloudDeviceList(function(services) { chrome.gcdPrivate.getCloudDeviceList(function(services) {
// Sort to avoid order dependence // Sort to avoid order dependence
services.sort(function(a,b) { services.sort(function(a,b) {
return a.idString.localeCompare(b.idString); return a.deviceId.localeCompare(b.deviceId);
}); });
chrome.test.assertEq(2, services.length); chrome.test.assertEq(2, services.length);
chrome.test.assertEq(services[0].setupType, "cloud"); chrome.test.assertEq(services[0].setupType, "cloud");
chrome.test.assertEq(services[0].idString, chrome.test.assertEq(services[0].deviceId,
"cloudprint:someCloudPrintID"); "cloudprint:someCloudPrintID");
chrome.test.assertEq(services[0].cloudId, "someCloudPrintID"); chrome.test.assertEq(services[0].cloudId, "someCloudPrintID");
chrome.test.assertEq(services[0].deviceType, "printer"); chrome.test.assertEq(services[0].deviceType, "printer");
...@@ -24,7 +24,7 @@ onload = function() { ...@@ -24,7 +24,7 @@ onload = function() {
"someCloudPrintDescription"); "someCloudPrintDescription");
chrome.test.assertEq(services[1].setupType, "cloud"); chrome.test.assertEq(services[1].setupType, "cloud");
chrome.test.assertEq(services[1].idString, "gcd:someGCDID"); chrome.test.assertEq(services[1].deviceId, "gcd:someGCDID");
chrome.test.assertEq(services[1].cloudId, "someGCDID"); chrome.test.assertEq(services[1].cloudId, "someGCDID");
chrome.test.assertEq(services[1].deviceType, "someType"); chrome.test.assertEq(services[1].deviceType, "someType");
chrome.test.assertEq(services[1].deviceName, "someGCDDisplayName"); chrome.test.assertEq(services[1].deviceName, "someGCDDisplayName");
......
...@@ -4,21 +4,19 @@ ...@@ -4,21 +4,19 @@
onload = function() { onload = function() {
chrome.test.runTests([ chrome.test.runTests([
function receiveNewDevice() { function receiveNewDevice() {
chrome.gcdPrivate.onCloudDeviceStateChanged.addListener( chrome.gcdPrivate.onDeviceStateChanged.addListener(
function(available, device) { function(device) {
chrome.test.assertTrue(available); chrome.test.assertEq(device.setupType, "mdns");
chrome.test.assertEq(device.deviceId,
"mdns:myService._privet._tcp.local");
chrome.test.assertEq(device.deviceType, "printer");
chrome.test.assertEq(device.deviceName,
"Sample device");
chrome.test.assertEq(device.deviceDescription,
"Sample device description");
chrome.test.assertEq(device.setupType, "mdns"); chrome.test.notifyPass();
chrome.test.assertEq(device.idString, })
"mdns:myService._privet._tcp.local");
chrome.test.assertEq(device.deviceType, "printer");
chrome.test.assertEq(device.deviceName,
"Sample device");
chrome.test.assertEq(device.deviceDescription,
"Sample device description");
chrome.test.notifyPass();
})
}]); }]);
}; };
...@@ -4,26 +4,12 @@ ...@@ -4,26 +4,12 @@
onload = function() { onload = function() {
chrome.test.runTests([ chrome.test.runTests([
function addRemoveDevice() { function addRemoveDevice() {
var should_be_available = true; chrome.gcdPrivate.onDeviceRemoved.addListener(
chrome.gcdPrivate.onCloudDeviceStateChanged.addListener( function(deviceId) {
function(available, device) { chrome.test.assertEq(deviceId,
chrome.test.assertEq(available, should_be_available); "mdns:myService._privet._tcp.local");
should_be_available = false; chrome.test.notifyPass();
})
chrome.test.assertEq(device.setupType, "mdns");
chrome.test.assertEq(device.idString,
"mdns:myService._privet._tcp.local");
chrome.test.assertEq(device.deviceType, "printer");
chrome.test.assertEq(device.deviceName,
"Sample device");
chrome.test.assertEq(device.deviceDescription,
"Sample device description");
if (!available) {
// Only pass after device is removed
chrome.test.notifyPass();
}
})
}]); }]);
}; };
...@@ -884,14 +884,19 @@ enum HistogramValue { ...@@ -884,14 +884,19 @@ enum HistogramValue {
GCDPRIVATE_GETCLOUDDEVICELIST, GCDPRIVATE_GETCLOUDDEVICELIST,
GCDPRIVATE_QUERYFORNEWLOCALDEVICES, GCDPRIVATE_QUERYFORNEWLOCALDEVICES,
GCDPRIVATE_STARTSETUP, GCDPRIVATE_STARTSETUP,
GCDPRIVATE_SETWIFINETWORKS, GCDPRIVATE_SETWIFINETWORK,
GCDPRIVATE_SETWIFICREDENTIALS, GCDPRIVATE_SETWIFIPASSWORD,
GCDPRIVATE_CONFIRMCODE, GCDPRIVATE_CONFIRMCODE,
GCDPRIVATE_STOPSETUP, GCDPRIVATE_STOPSETUP,
TABS_SETZOOM, TABS_SETZOOM,
TABS_GETZOOM, TABS_GETZOOM,
TABS_SETZOOMSETTINGS, TABS_SETZOOMSETTINGS,
TABS_GETZOOMSETTINGS, TABS_GETZOOMSETTINGS,
GCDPRIVATE_GETCOMMANDDEFINITIONS,
GCDPRIVATE_INSERTCOMMAND,
GCDPRIVATE_GETCOMMAND,
GCDPRIVATE_CANCELCOMMAND,
GCDPRIVATE_GETCOMMANDSLIST,
// Last entry: Add new entries above and ensure to update // Last entry: Add new entries above and ensure to update
// tools/metrics/histograms/histograms/histograms.xml. // tools/metrics/histograms/histograms/histograms.xml.
ENUM_BOUNDARY ENUM_BOUNDARY
......
...@@ -38435,6 +38435,11 @@ Therefore, the affected-histogram name has to have at least one dot in it. ...@@ -38435,6 +38435,11 @@ Therefore, the affected-histogram name has to have at least one dot in it.
<int value="831" label="TABS_GETZOOM"/> <int value="831" label="TABS_GETZOOM"/>
<int value="832" label="TABS_SETZOOMSETTINGS"/> <int value="832" label="TABS_SETZOOMSETTINGS"/>
<int value="833" label="TABS_GETZOOMSETTINGS"/> <int value="833" label="TABS_GETZOOMSETTINGS"/>
<int value="834" label="GCDPRIVATE_GETCOMMANDDEFS"/>
<int value="835" label="GCDPRIVATE_INSERTCOMMAND"/>
<int value="836" label="GCDPRIVATE_GETCOMMAND"/>
<int value="837" label="GCDPRIVATE_CANCELCOMMAND"/>
<int value="838" label="GCDPRIVATE_GETCOMMANDSLIST"/>
</enum> </enum>
<enum name="ExtensionInstallCause" type="int"> <enum name="ExtensionInstallCause" type="int">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment