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

Side by Side Diff: chrome/browser/media/router/discovery/safe_dial_device_description_parser.cc

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 unified diff | Download patch
OLDNEW
(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 #include "chrome/browser/media/router/discovery/safe_dial_device_description_par ser.h"
6
7 #include <utility>
imcheng 2017/03/22 00:31:46 Is this used?
zhaobin 2017/03/22 01:55:31 Done.
8
9 #include "chrome/common/extensions/chrome_utility_extensions_messages.h"
imcheng 2017/03/22 00:31:46 Not used?
zhaobin 2017/03/22 01:55:31 Done.
10 #include "chrome/grit/generated_resources.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "ui/base/l10n/l10n_util.h"
13
14 using content::BrowserThread;
imcheng 2017/03/22 00:31:46 This doesn't seem to be used - remove?
zhaobin 2017/03/22 01:55:31 Done.
15 using content::UtilityProcessHost;
16
17 namespace media_router {
18
19 SafeDialDeviceDescriptionParser::SafeDialDeviceDescriptionParser() {}
20
21 SafeDialDeviceDescriptionParser::~SafeDialDeviceDescriptionParser() {}
22
23 void SafeDialDeviceDescriptionParser::Start(
24 const std::string& xml_text,
25 const DeviceDescriptionCallback& callback) {
26 DCHECK(thread_checker_.CalledOnValidThread());
27 DCHECK(!utility_process_mojo_client_);
28 DCHECK(callback);
29
30 device_description_callback_ = callback;
31
32 utility_process_mojo_client_ =
33 base::MakeUnique<content::UtilityProcessMojoClient<
34 chrome::mojom::DialDeviceDescriptionParser>>(
35 l10n_util::GetStringUTF16(
36 IDS_UTILITY_PROCESS_DIAL_DEVICE_DESCRIPTION_PARSER_NAME));
37
38 utility_process_mojo_client_->set_error_callback(base::Bind(
39 &SafeDialDeviceDescriptionParser::OnParseDeviceDescriptionFailed, this));
40
41 // This starts utility process in the background.
42 utility_process_mojo_client_->Start();
43
44 // This call is queued up until the Mojo message pipe has been established to
45 // the service running in the utility process.
46 utility_process_mojo_client_->service()->ParseDialDeviceDescription(
47 xml_text,
48 base::Bind(
49 &SafeDialDeviceDescriptionParser::OnParseDeviceDescriptionComplete,
50 this));
imcheng 2017/03/22 00:31:46 Unless you have ref counting for other purposes, c
zhaobin 2017/03/22 01:55:31 Done.
51 }
52
53 void SafeDialDeviceDescriptionParser::OnParseDeviceDescriptionComplete(
54 bool result,
55 const base::Optional<media_router::DialDeviceDescription>&
56 device_description) {
57 DCHECK(thread_checker_.CalledOnValidThread());
58
59 utility_process_mojo_client_.reset(); // Terminate the utility process.
60
61 DCHECK(!device_description_callback_.is_null());
62 device_description_callback_.Run(result, device_description);
63 }
64
65 void SafeDialDeviceDescriptionParser::OnParseDeviceDescriptionFailed() {
66 DCHECK(thread_checker_.CalledOnValidThread());
67
68 utility_process_mojo_client_.reset(); // Terminate the utility process.
69
70 DCHECK(!device_description_callback_.is_null());
71 device_description_callback_.Run(
72 false, base::Optional<media_router::DialDeviceDescription>());
73 }
74
75 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698