Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_SAFE_DIAL_DEVICE_DESCRIPTION_PARSE R_H_ | |
| 6 #define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_SAFE_DIAL_DEVICE_DESCRIPTION_PARSE R_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/threading/thread_checker.h" | |
| 12 #include "chrome/common/media_router/dial_device_description.h" | |
| 13 #include "chrome/common/media_router/dial_device_description_parser.mojom.h" | |
| 14 #include "content/public/browser/utility_process_mojo_client.h" | |
| 15 | |
| 16 namespace media_router { | |
| 17 | |
| 18 // SafeDialDeviceDescriptionParser parses the given device description XML file | |
| 19 // safely via a utility process. This class runs on IO thread. | |
| 20 class SafeDialDeviceDescriptionParser | |
| 21 : public base::RefCounted<SafeDialDeviceDescriptionParser> { | |
| 22 public: | |
| 23 // Callback function to be invoked when utility process finishes parsing | |
| 24 // device description XML. | |
| 25 // |result|: returns false if parsing fails. | |
| 26 // |device_description|: device description object. Empty if parsing fails. | |
| 27 // |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.
| |
| 28 using DeviceDescriptionCallback = base::Callback<void( | |
| 29 bool result, | |
| 30 const media_router::DialDeviceDescription& device_description, | |
| 31 const std::string& logging_xml)>; | |
| 32 | |
| 33 SafeDialDeviceDescriptionParser(); | |
| 34 | |
| 35 // Start parsing device description XML file in utility process. | |
| 36 void Start(const std::string& xml_text, | |
| 37 const DeviceDescriptionCallback& callback); | |
| 38 | |
| 39 private: | |
| 40 friend class base::RefCounted<SafeDialDeviceDescriptionParser>; | |
| 41 | |
| 42 ~SafeDialDeviceDescriptionParser(); | |
| 43 | |
| 44 // Notification from the utility process when it finishes parsing the | |
| 45 // device description XML. Runs on IO thread. | |
| 46 // |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.
| |
| 47 // |device_description|: device description object. Empty if parsing fails. | |
| 48 // |logging_xml|: xml file for logging without unique ID and serial number. | |
| 49 void OnParseDeviceDescriptionComplete( | |
| 50 bool result, | |
| 51 const media_router::DialDeviceDescription& device_description, | |
| 52 const std::string& logging_xml); | |
| 53 | |
| 54 // TODO(crbug.com/702766): Add an enum type describing why utility process | |
| 55 // fails to parse device description xml. | |
| 56 void OnParseDeviceDescriptionFailed(); | |
| 57 | |
| 58 // Utility client used to send device description parsing task to the utility | |
| 59 // process. | |
| 60 std::unique_ptr<content::UtilityProcessMojoClient< | |
| 61 chrome::mojom::DialDeviceDescriptionParser>> | |
| 62 utility_process_mojo_client_; | |
| 63 | |
| 64 // Only accessed on the IO thread. | |
| 65 DeviceDescriptionCallback device_description_callback_; | |
| 66 | |
| 67 base::ThreadChecker thread_checker_; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(SafeDialDeviceDescriptionParser); | |
| 70 }; | |
| 71 | |
| 72 } // namespace media_router | |
| 73 | |
| 74 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_SAFE_DIAL_DEVICE_DESCRIPTION_PA RSER_H_ | |
| OLD | NEW |