diff options
author | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-25 04:58:35 +0000 |
---|---|---|
committer | hashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-25 04:58:35 +0000 |
commit | c9a384406ed1801f1c13bf8e7634032236dd45e1 (patch) | |
tree | 2f63198423b7658ba82b5a2e25695765d5af7802 /chrome | |
parent | 3b1992d113b559211d6f58d72935ad17d6af222f (diff) | |
download | chromium_src-c9a384406ed1801f1c13bf8e7634032236dd45e1.zip chromium_src-c9a384406ed1801f1c13bf8e7634032236dd45e1.tar.gz chromium_src-c9a384406ed1801f1c13bf8e7634032236dd45e1.tar.bz2 |
chromeos: Separate XML parsing code from IntrospectableClient
BUG=119583
TEST=unit_tests --gtest_filter=IntrospectUtilTest.GetInterfacesFromIntrospectResult
Review URL: http://codereview.chromium.org/9839064
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128805 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/chromeos/bluetooth/bluetooth_device.cc | 3 | ||||
-rw-r--r-- | chrome/browser/chromeos/dbus/introspect_util.cc | 50 | ||||
-rw-r--r-- | chrome/browser/chromeos/dbus/introspect_util.h | 22 | ||||
-rw-r--r-- | chrome/browser/chromeos/dbus/introspect_util_unittest.cc (renamed from chrome/browser/chromeos/dbus/introspectable_client_unittest.cc) | 6 | ||||
-rw-r--r-- | chrome/browser/chromeos/dbus/introspectable_client.cc | 37 | ||||
-rw-r--r-- | chrome/browser/chromeos/dbus/introspectable_client.h | 5 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 2 |
8 files changed, 80 insertions, 47 deletions
diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_device.cc b/chrome/browser/chromeos/bluetooth/bluetooth_device.cc index f1c04da..c9c85cc 100644 --- a/chrome/browser/chromeos/bluetooth/bluetooth_device.cc +++ b/chrome/browser/chromeos/bluetooth/bluetooth_device.cc @@ -19,6 +19,7 @@ #include "chrome/browser/chromeos/dbus/bluetooth_device_client.h" #include "chrome/browser/chromeos/dbus/bluetooth_input_client.h" #include "chrome/browser/chromeos/dbus/introspectable_client.h" +#include "chrome/browser/chromeos/dbus/introspect_util.h" #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" #include "dbus/bus.h" #include "dbus/object_path.h" @@ -281,7 +282,7 @@ void BluetoothDevice::OnIntrospect(ErrorCallback error_callback, // device. Send appropraite Connect calls for each of those interfaces // to connect all of the application protocols for this device. std::vector<std::string> interfaces = - IntrospectableClient::GetInterfacesFromXmlData(xml_data); + GetInterfacesFromIntrospectResult(xml_data); for (std::vector<std::string>::iterator iter = interfaces.begin(); iter != interfaces.end(); ++iter) { diff --git a/chrome/browser/chromeos/dbus/introspect_util.cc b/chrome/browser/chromeos/dbus/introspect_util.cc new file mode 100644 index 0000000..6b7dc5f --- /dev/null +++ b/chrome/browser/chromeos/dbus/introspect_util.cc @@ -0,0 +1,50 @@ +// Copyright (c) 2012 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. + +#include "chrome/browser/chromeos/dbus/introspect_util.h" + +#include "chrome/common/libxml_utils.h" + +namespace { + +// String constants used for parsing D-Bus Introspection XML data. +const char kInterfaceNode[] = "interface"; +const char kInterfaceNameAttribute[] = "name"; + +} + +namespace chromeos { + +std::vector<std::string> GetInterfacesFromIntrospectResult( + const std::string& xml_data) { + std::vector<std::string> interfaces; + + XmlReader reader; + if (!reader.Load(xml_data)) + return interfaces; + + do { + // Skip to the next open tag, exit when done. + while (!reader.SkipToElement()) { + if (!reader.Read()) { + return interfaces; + } + } + + // Only look at interface nodes. + if (reader.NodeName() != kInterfaceNode) + continue; + + // Skip if missing the interface name. + std::string interface_name; + if (!reader.NodeAttribute(kInterfaceNameAttribute, &interface_name)) + continue; + + interfaces.push_back(interface_name); + } while (reader.Read()); + + return interfaces; +} + +} diff --git a/chrome/browser/chromeos/dbus/introspect_util.h b/chrome/browser/chromeos/dbus/introspect_util.h new file mode 100644 index 0000000..93577c0 --- /dev/null +++ b/chrome/browser/chromeos/dbus/introspect_util.h @@ -0,0 +1,22 @@ +// Copyright (c) 2012 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. + +#ifndef CHROME_BROWSER_CHROMEOS_DBUS_INTROSPECT_UTIL_H_ +#define CHROME_BROWSER_CHROMEOS_DBUS_INTROSPECT_UTIL_H_ +#pragma once + +#include <string> +#include <vector> + +namespace chromeos { + +// Parses XML-formatted introspection data returned by +// org.freedesktop.DBus.Introspectable.Introspect and returns the list of +// interface names declared within. +std::vector<std::string> GetInterfacesFromIntrospectResult( + const std::string& xml_data); + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_DBUS_INTROSPECT_UTIL_H_ diff --git a/chrome/browser/chromeos/dbus/introspectable_client_unittest.cc b/chrome/browser/chromeos/dbus/introspect_util_unittest.cc index 2600e69..5d68ada 100644 --- a/chrome/browser/chromeos/dbus/introspectable_client_unittest.cc +++ b/chrome/browser/chromeos/dbus/introspect_util_unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/dbus/introspectable_client.h" +#include "chrome/browser/chromeos/dbus/introspect_util.h" #include "testing/gtest/include/gtest/gtest.h" @@ -55,9 +55,9 @@ const char kXmlData[] = namespace chromeos { -TEST(IntrospectableTest, GetInterfacesFromXmlData) { +TEST(IntrospectUtilTest, GetInterfacesFromIntrospectResult) { std::vector<std::string> interfaces = - IntrospectableClient::GetInterfacesFromXmlData(kXmlData); + GetInterfacesFromIntrospectResult(kXmlData); ASSERT_EQ(3U, interfaces.size()); EXPECT_EQ("org.freedesktop.DBus.Introspectable", interfaces[0]); diff --git a/chrome/browser/chromeos/dbus/introspectable_client.cc b/chrome/browser/chromeos/dbus/introspectable_client.cc index 508e1da..4a26dd2 100644 --- a/chrome/browser/chromeos/dbus/introspectable_client.cc +++ b/chrome/browser/chromeos/dbus/introspectable_client.cc @@ -10,7 +10,6 @@ #include "base/bind.h" #include "base/logging.h" #include "base/chromeos/chromeos_version.h" -#include "chrome/common/libxml_utils.h" #include "dbus/bus.h" #include "dbus/message.h" #include "dbus/object_path.h" @@ -22,10 +21,6 @@ namespace { const char kIntrospectableInterface[] = "org.freedesktop.DBus.Introspectable"; const char kIntrospect[] = "Introspect"; -// String constants used for parsing D-Bus Introspection XML data. -const char kInterfaceNode[] = "interface"; -const char kInterfaceNameAttribute[] = "name"; - } // namespace namespace chromeos { @@ -111,38 +106,6 @@ IntrospectableClient::~IntrospectableClient() { } // static -std::vector<std::string> IntrospectableClient::GetInterfacesFromXmlData( - const std::string&xml_data) { - std::vector<std::string> interfaces; - - XmlReader reader; - if (!reader.Load(xml_data)) - return interfaces; - - do { - // Skip to the next open tag, exit when done. - while (!reader.SkipToElement()) { - if (!reader.Read()) { - return interfaces; - } - } - - // Only look at interface nodes. - if (reader.NodeName() != kInterfaceNode) - continue; - - // Skip if missing the interface name. - std::string interface_name; - if (!reader.NodeAttribute(kInterfaceNameAttribute, &interface_name)) - continue; - - interfaces.push_back(interface_name); - } while (reader.Read()); - - return interfaces; -} - -// static IntrospectableClient* IntrospectableClient::Create(dbus::Bus* bus) { if (base::chromeos::IsRunningOnChromeOS()) { return new IntrospectableClientImpl(bus); diff --git a/chrome/browser/chromeos/dbus/introspectable_client.h b/chrome/browser/chromeos/dbus/introspectable_client.h index ef82036..928116f 100644 --- a/chrome/browser/chromeos/dbus/introspectable_client.h +++ b/chrome/browser/chromeos/dbus/introspectable_client.h @@ -40,11 +40,6 @@ class IntrospectableClient { const dbus::ObjectPath& object_path, const IntrospectCallback& callback) = 0; - // Parses XML-formatted introspection data, as passed to IntrospectCallback, - // and returns the list of interface names declared within. - static std::vector<std::string> GetInterfacesFromXmlData( - const std::string&xml_data); - // Creates the instance static IntrospectableClient* Create(dbus::Bus* bus); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 06a52d6..630a6b7 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -491,6 +491,8 @@ 'browser/chromeos/dbus/image_burner_client.h', 'browser/chromeos/dbus/introspectable_client.cc', 'browser/chromeos/dbus/introspectable_client.h', + 'browser/chromeos/dbus/introspect_util.cc', + 'browser/chromeos/dbus/introspect_util.h', 'browser/chromeos/dbus/power_manager_client.cc', 'browser/chromeos/dbus/power_manager_client.h', 'browser/chromeos/dbus/proxy_resolution_service_provider.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 0757753..3e31531 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1313,7 +1313,7 @@ 'browser/chromeos/cros_settings_unittest.cc', 'browser/chromeos/customization_document_unittest.cc', 'browser/chromeos/dbus/cros_dbus_service_unittest.cc', - 'browser/chromeos/dbus/introspectable_client_unittest.cc', + 'browser/chromeos/dbus/introspect_util_unittest.cc', 'browser/chromeos/dbus/proxy_resolution_service_provider_unittest.cc', 'browser/chromeos/extensions/file_browser_notifications_unittest.cc', 'browser/chromeos/external_metrics_unittest.cc', |