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

Unified Diff: mojo/shell/public/cpp/message_loop_ref.h

Issue 1725353003: Eliminate mojo::Shell client lib class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@15connector
Patch Set: . Created 4 years, 10 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
« no previous file with comments | « mojo/shell/public/cpp/lib/shell_connection.cc ('k') | mojo/shell/public/cpp/shell.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/public/cpp/message_loop_ref.h
diff --git a/mojo/shell/public/cpp/message_loop_ref.h b/mojo/shell/public/cpp/message_loop_ref.h
new file mode 100644
index 0000000000000000000000000000000000000000..fffb7384021cdd8374bc9ddf85ea54675f35e648
--- /dev/null
+++ b/mojo/shell/public/cpp/message_loop_ref.h
@@ -0,0 +1,57 @@
+// 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 MOJO_SHELL_PUBLIC_CPP_APPLICATION_RUNNER_REFERENCE_H_
+#define MOJO_SHELL_PUBLIC_CPP_APPLICATION_RUNNER_REFERENCE_H_
+
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop/message_loop.h"
+#include "mojo/public/cpp/system/core.h"
+
+namespace mojo {
+
+class MessageLoopRefImpl;
+
+// An interface implementation can keep this object as a member variable to
+// hold a reference to the ShellConnection, keeping it alive as long as the
+// bound implementation exists.
+// Since interface implementations can be bound on different threads than the
+// ShellConnection, this class is safe to use on any thread. However, each
+// instance should only be used on one thread at a time (otherwise there'll be
+// races between the AddRef resulting from cloning and destruction).
+class MessageLoopRef {
+ public:
+ virtual ~MessageLoopRef() {}
+
+ virtual scoped_ptr<MessageLoopRef> Clone() = 0;
+};
+
+class MessageLoopRefFactory {
+ public:
+ MessageLoopRefFactory();
+ ~MessageLoopRefFactory();
+
+ void set_quit_closure(const base::Closure& quit_closure) {
+ quit_closure_ = quit_closure;
+ }
+
+ scoped_ptr<MessageLoopRef> CreateRef();
+
+ private:
+ friend MessageLoopRefImpl;
+
+ // Called from MessageLoopRefImpl.
+ void AddRef();
+ void Release();
+
+ base::Closure quit_closure_;
+ int ref_count_ = 0;
+
+ DISALLOW_COPY_AND_ASSIGN(MessageLoopRefFactory);
+};
+
+} // namespace mojo
+
+#endif // MOJO_SHELL_PUBLIC_CPP_APPLICATION_RUNNER_REFERENCE_H_
« no previous file with comments | « mojo/shell/public/cpp/lib/shell_connection.cc ('k') | mojo/shell/public/cpp/shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698