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

Unified 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: bauerb@ comment 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 side-by-side diff with in-line comments
Download patch
Index: content/public/browser/utility_process_mojo_client.h
diff --git a/content/public/browser/utility_process_mojo_client.h b/content/public/browser/utility_process_mojo_client.h
new file mode 100644
index 0000000000000000000000000000000000000000..b62f10415c9dff4f1d781ad10cefbadd684fc873
--- /dev/null
+++ b/content/public/browser/utility_process_mojo_client.h
@@ -0,0 +1,72 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_
+#define CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_
+
+#include "base/callback.h"
+#include "base/logging.h"
+#include "base/macros.h"
+#include "base/strings/string16.h"
+#include "base/threading/thread_checker.h"
+#include "content/public/browser/utility_process_mojo_client_impl.h"
+#include "mojo/public/cpp/bindings/interface_ptr.h"
+
+namespace content {
+
+// Implements a client to a mojo service running on a utility process. Takes
+// care of starting the utility process and connecting to the remote mojo
+// service. The utility process is terminated in the destructor.
+// Note: This class is not thread-safe. It is bound to the
+// SingleThreadTaskRunner it is created on.
+template <class MojoInterface>
+class UtilityProcessMojoClient {
+ public:
+ UtilityProcessMojoClient(const base::string16& process_name,
+ const base::Closure& on_error_callback)
+ : impl_(process_name), on_error_callback_(on_error_callback) {
+ DCHECK(!on_error_callback_.is_null());
+ }
+
+ void set_disable_sandbox() { impl_.set_disable_sandbox(); }
+
+ void Start() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(!start_called_);
+
+ start_called_ = true;
+
+ mojo::InterfaceRequest<MojoInterface> req = mojo::GetProxy(&service_);
+
+ service_.set_connection_error_handler(on_error_callback_);
+ impl_.Start(MojoInterface::Name_, req.PassMessagePipe());
+ }
+
+ // Returns the Mojo service used to make calls to the utility process.
+ MojoInterface* service() WARN_UNUSED_RESULT {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(start_called_);
+
+ return service_.get();
+ }
+
+ private:
+ // Called when a connection error happens or if the process didn't start.
+ base::Closure on_error_callback_;
+
+ mojo::InterfacePtr<MojoInterface> service_;
+ UtilityProcessMojoClientImpl impl_;
+
+ // Enforce calling Start() before getting the service.
+ bool start_called_ = false;
+
+ // Checks that this class is always accessed from the same thread.
+ base::ThreadChecker thread_checker_;
+
+ DISALLOW_COPY_AND_ASSIGN(UtilityProcessMojoClient);
+};
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_MOJO_CLIENT_H_

Powered by Google App Engine
This is Rietveld 408576698