Re-submit of https://codereview.chromium.org/356613002

> Add function queryForNewLocalDevices to send query for new local devices,
> implement it for mDNS (WiFi devices forthcoming)
>
> BUG=383167
>
> Review URL: https://codereview.chromium.org/356613002

TBR=noamsml@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282315 0039d316-1c4b-4281-b951-d872f2087c98
parent 409e5628
......@@ -168,6 +168,15 @@ void GcdPrivateAPI::DeviceCacheFlushed() {
known_devices_.clear();
}
bool GcdPrivateAPI::QueryForDevices() {
if (!privet_device_lister_)
return false;
privet_device_lister_->DiscoverNewDevices(true);
return true;
}
// static
void GcdPrivateAPI::SetGCDApiFlowFactoryForTests(
GCDApiFlowFactoryForTests* factory) {
......@@ -176,6 +185,7 @@ void GcdPrivateAPI::SetGCDApiFlowFactoryForTests(
GcdPrivateGetCloudDeviceListFunction::GcdPrivateGetCloudDeviceListFunction() {
}
GcdPrivateGetCloudDeviceListFunction::~GcdPrivateGetCloudDeviceListFunction() {
}
......@@ -258,7 +268,20 @@ GcdPrivateQueryForNewLocalDevicesFunction::
}
bool GcdPrivateQueryForNewLocalDevicesFunction::RunSync() {
return false;
GcdPrivateAPI* gcd_api =
BrowserContextKeyedAPIFactory<GcdPrivateAPI>::Get(GetProfile());
if (!gcd_api)
return false;
if (!gcd_api->QueryForDevices()) {
error_ =
"You must first subscribe to onDeviceStateChanged or onDeviceRemoved "
"notifications";
return false;
}
return true;
}
GcdPrivateStartSetupFunction::GcdPrivateStartSetupFunction() {
......
......@@ -37,6 +37,8 @@ class GcdPrivateAPI : public BrowserContextKeyedAPI,
// BrowserContextKeyedAPI implementation.
static BrowserContextKeyedAPIFactory<GcdPrivateAPI>* GetFactoryInstance();
bool QueryForDevices();
private:
friend class BrowserContextKeyedAPIFactory<GcdPrivateAPI>;
......
......@@ -130,6 +130,22 @@ const uint8 kGoodbyePacket[] = {
'o', 'c', 'a', 'l', 0x00,
};
const uint8 kQueryPacket[] = {
// Header
0x00, 0x00, // ID is zeroed out
0x00, 0x00, // No flags.
0x00, 0x01, // One question.
0x00, 0x00, // 0 RRs (answers)
0x00, 0x00, // 0 authority RRs
0x00, 0x00, // 0 additional RRs
// Question
// This part is echoed back from the respective query.
0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 0x04, '_', 't', 'c',
'p', 0x05, 'l', 'o', 'c', 'a', 'l', 0x00, 0x00, 0x0c, // TYPE is PTR.
0x00, 0x01, // CLASS is IN.
};
#endif // ENABLE_MDNS
// Sentinel value to signify the request should fail.
......@@ -254,6 +270,18 @@ IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, AddRemove) {
EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "remove_device.html"));
}
IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, SendQuery) {
// TODO(noamsml): Win Dbg has a workaround that makes RunExtensionSubtest
// always return true without actually running the test. Remove when fixed.
// See http://crbug.com/177163 for details.
#if !defined(OS_WIN) || defined(NDEBUG)
EXPECT_CALL(*test_service_discovery_client_,
OnSendTo(std::string(reinterpret_cast<const char*>(kQueryPacket),
sizeof(kQueryPacket)))).Times(2);
#endif
EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "send_query.html"));
}
#endif // ENABLE_MDNS
} // namespace
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
onload = function() {
chrome.test.runTests([
function sendQuery() {
chrome.gcdPrivate.onDeviceStateChanged.addListener(function(device) {});
chrome.gcdPrivate.queryForNewLocalDevices();
chrome.test.notifyPass();
}
]);
};
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