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