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

Side by Side Diff: content/public/browser/utility_process_mojo_client.h

Issue 2049303002: Add the UtilityProcessMojoClient class and convert SafeJsonParser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 2016 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 CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_
6 #define CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_
7
8 #include "base/callback.h"
Anand Mistry (off Chromium) 2016/06/10 11:13:55 #include "base/logging.h" for DCHECK
Patrick Monette 2016/06/10 18:13:24 Done.
9 #include "base/macros.h"
10 #include "base/strings/string16.h"
11 #include "base/threading/thread_checker.h"
12 #include "content/public/browser/utility_process_mojo_client_impl.h"
13 #include "mojo/public/cpp/bindings/interface_ptr.h"
14
15 namespace content {
16
17 // Implements a client to a mojo service running on a utility process. Takes
18 // care of starting the utility process and connecting to the remote mojo
19 // service. The utility process is terminated in the destructor.
20 // Note: This class is not thread-safe. It is bound to the
21 // SingleThreadTaskRunner it is created on.
22 template <class MojoInterface>
23 class UtilityProcessMojoClient : public UtilityProcessMojoClientImpl {
Anand Mistry (off Chromium) 2016/06/10 11:13:54 It's kinda weird to derive from the impl. Since th
Patrick Monette 2016/06/10 18:13:23 Done.
24 public:
25 explicit UtilityProcessMojoClient(const base::string16& process_name)
26 : UtilityProcessMojoClientImpl(process_name) {}
27
28 // Sets an error handler that will be called when an error occurs.
29 void set_error_handler(const base::Closure& on_error_callback) {
grt (UTC plus 2) 2016/06/09 14:48:58 specifying an error handler seems like it will be
Anand Mistry (off Chromium) 2016/06/10 11:13:55 +1. I think we want to ensure a valid callback is
Patrick Monette 2016/06/10 18:13:23 Done. I'll make the callback mandatory.
30 on_error_callback_ = on_error_callback;
31 }
32
33 void Start() {
34 DCHECK(thread_checker_.CalledOnValidThread());
Anand Mistry (off Chromium) 2016/06/10 11:13:54 DCHECK(!start_called_);
Patrick Monette 2016/06/10 18:13:24 Done.
35
36 start_called_ = true;
37
38 mojo::InterfaceRequest<MojoInterface> req = mojo::GetProxy(&service_);
39
40 service_.set_connection_error_handler(base::Bind(
41 &UtilityProcessMojoClient::OnConnectionError, base::Unretained(this)));
42 StartImpl(MojoInterface::Name_, req.PassMessagePipe());
43 }
44
45 // Returns the Mojo service used to make calls to the utility process.
46 MojoInterface* service() WARN_UNUSED_RESULT {
47 DCHECK(thread_checker_.CalledOnValidThread());
48 DCHECK(start_called_);
49
50 return service_.get();
51 }
52
53 private:
54 void OnConnectionError() { on_error_callback_.Run(); }
Anand Mistry (off Chromium) 2016/06/10 11:13:54 If you don't make the error handler mandatory like
Patrick Monette 2016/06/10 18:13:23 Acknowledged.
55
56 // Enforce calling Start() before getting the service.
57 bool start_called_ = false;
58
59 // Called when a connection error happens or if the process didn't start.
60 base::Closure on_error_callback_;
61
62 mojo::InterfacePtr<MojoInterface> service_;
63
64 // Checks that this class is always accessed from the same thread.
65 base::ThreadChecker thread_checker_;
grt (UTC plus 2) 2016/06/09 14:48:58 how about getting rid of this and instead move the
Anand Mistry (off Chromium) 2016/06/10 11:13:54 Or get rid of the impl's thread checker. I don't t
Patrick Monette 2016/06/10 18:13:24 Got rid of impl's thread checker.
66
67 DISALLOW_COPY_AND_ASSIGN(UtilityProcessMojoClient);
68 };
69
70 } // namespace content
71
72 #endif // CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698