Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5341)

Unified Diff: chrome/browser/media/router/discovery/safe_dial_device_description_parser.h

Issue 2745653008: [Media Router] Parse device description xml in utility process (Closed)
Patch Set: resolve code review comments from Mark Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..066a06a7b90dbd2e6e92d913a30938ce72b881ff
--- /dev/null
+++ b/chrome/browser/media/router/discovery/safe_dial_device_description_parser.h
@@ -0,0 +1,70 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
imcheng 2017/03/22 00:31:46 Seems like this file should be in c/b/m/r/discover
zhaobin 2017/03/22 01:55:32 Done.
+// 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"
imcheng 2017/03/22 00:31:46 #include <memory> #include <string>
zhaobin 2017/03/22 01:55:32 Done.
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/optional.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> {
imcheng 2017/03/22 00:31:46 why does this need to be ref counted?
zhaobin 2017/03/22 01:55:32 Done.
+ public:
+ // Callback function to be invoked when utility process finishes parsing
+ // device description XML.
+ // |result|: returns false if parsing fails.
imcheng 2017/03/22 00:31:47 s/result/success
zhaobin 2017/03/22 01:55:32 Done.
+ // |device_description|: device description object. Empty if parsing fails.
+ using DeviceDescriptionCallback = base::Callback<void(
+ bool result,
+ const base::Optional<media_router::DialDeviceDescription>&
+ device_description)>;
+
+ 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();
+
+ // See SafeDialDeviceDescriptionParser::DeviceDescriptionCallback
+ void OnParseDeviceDescriptionComplete(
+ bool result,
imcheng 2017/03/22 00:31:46 s/result/success
zhaobin 2017/03/22 01:55:32 Done.
+ const base::Optional<media_router::DialDeviceDescription>&
+ device_description);
+
+ // 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_

Powered by Google App Engine
This is Rietveld 408576698