Chromium Code Reviews| Index: chrome/browser/media/router/discovery/safe_dial_device_description_parser.h |
| diff --git a/chrome/browser/media/router/discovery/safe_dial_device_description_parser.h b/chrome/browser/media/router/discovery/safe_dial_device_description_parser.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2a0a90ced97d8a0cdf67514d12ea0d0bbc18375e |
| --- /dev/null |
| +++ b/chrome/browser/media/router/discovery/safe_dial_device_description_parser.h |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2017 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_MEDIA_ROUTER_DISCOVERY_SAFE_DIAL_DEVICE_DESCRIPTION_PARSER_H_ |
| +#define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_SAFE_DIAL_DEVICE_DESCRIPTION_PARSER_H_ |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "chrome/common/media_router/dial_device_description.h" |
| +#include "chrome/common/media_router/dial_device_description_parser.mojom.h" |
| +#include "content/public/browser/utility_process_mojo_client.h" |
| + |
| +namespace media_router { |
| + |
| +// SafeDialDeviceDescriptionParser parses the given device description XML file |
| +// safely via a utility process. This class runs on IO thread. |
| +class SafeDialDeviceDescriptionParser |
| + : public base::RefCounted<SafeDialDeviceDescriptionParser> { |
| + public: |
| + // Callback function to be invoked when utility process finishes parsing |
| + // device description XML. |
| + // |result|: returns false if parsing fails. |
| + // |device_description|: device description object. Empty if parsing fails. |
| + // |logging_xml|: xml file for logging without unique ID and serial number. |
|
mark a. foltz
2017/03/21 01:39:21
Nit: s/xml file/serialized xml/
zhaobin
2017/03/21 03:15:37
Done.
|
| + using DeviceDescriptionCallback = base::Callback<void( |
| + bool result, |
| + const media_router::DialDeviceDescription& device_description, |
| + const std::string& logging_xml)>; |
| + |
| + SafeDialDeviceDescriptionParser(); |
| + |
| + // Start parsing device description XML file in utility process. |
| + void Start(const std::string& xml_text, |
| + const DeviceDescriptionCallback& callback); |
| + |
| + private: |
| + friend class base::RefCounted<SafeDialDeviceDescriptionParser>; |
| + |
| + ~SafeDialDeviceDescriptionParser(); |
| + |
| + // Notification from the utility process when it finishes parsing the |
| + // device description XML. Runs on IO thread. |
| + // |result|: returns false if parsing fails. |
|
mark a. foltz
2017/03/21 01:39:21
You could refer to the documentation for DeviceDes
zhaobin
2017/03/21 03:15:37
Done.
|
| + // |device_description|: device description object. Empty if parsing fails. |
| + // |logging_xml|: xml file for logging without unique ID and serial number. |
| + void OnParseDeviceDescriptionComplete( |
| + bool result, |
| + const media_router::DialDeviceDescription& device_description, |
| + const std::string& logging_xml); |
| + |
| + // TODO(crbug.com/702766): Add an enum type describing why utility process |
| + // fails to parse device description xml. |
| + void OnParseDeviceDescriptionFailed(); |
| + |
| + // Utility client used to send device description parsing task to the utility |
| + // process. |
| + std::unique_ptr<content::UtilityProcessMojoClient< |
| + chrome::mojom::DialDeviceDescriptionParser>> |
| + utility_process_mojo_client_; |
| + |
| + // Only accessed on the IO thread. |
| + DeviceDescriptionCallback device_description_callback_; |
| + |
| + base::ThreadChecker thread_checker_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SafeDialDeviceDescriptionParser); |
| +}; |
| + |
| +} // namespace media_router |
| + |
| +#endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_SAFE_DIAL_DEVICE_DESCRIPTION_PARSER_H_ |