OLD | NEW |
(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 MOJO_SHELL_PUBLIC_CPP_APPLICATION_RUNNER_REFERENCE_H_ |
| 6 #define MOJO_SHELL_PUBLIC_CPP_APPLICATION_RUNNER_REFERENCE_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" |
| 11 #include "mojo/public/cpp/system/core.h" |
| 12 |
| 13 namespace mojo { |
| 14 |
| 15 class MessageLoopRefImpl; |
| 16 |
| 17 // An interface implementation can keep this object as a member variable to |
| 18 // hold a reference to the ShellConnection, keeping it alive as long as the |
| 19 // bound implementation exists. |
| 20 // Since interface implementations can be bound on different threads than the |
| 21 // ShellConnection, this class is safe to use on any thread. However, each |
| 22 // instance should only be used on one thread at a time (otherwise there'll be |
| 23 // races between the AddRef resulting from cloning and destruction). |
| 24 class MessageLoopRef { |
| 25 public: |
| 26 virtual ~MessageLoopRef() {} |
| 27 |
| 28 virtual scoped_ptr<MessageLoopRef> Clone() = 0; |
| 29 }; |
| 30 |
| 31 class MessageLoopRefFactory { |
| 32 public: |
| 33 MessageLoopRefFactory(); |
| 34 ~MessageLoopRefFactory(); |
| 35 |
| 36 void set_quit_closure(const base::Closure& quit_closure) { |
| 37 quit_closure_ = quit_closure; |
| 38 } |
| 39 |
| 40 scoped_ptr<MessageLoopRef> CreateRef(); |
| 41 |
| 42 private: |
| 43 friend MessageLoopRefImpl; |
| 44 |
| 45 // Called from MessageLoopRefImpl. |
| 46 void AddRef(); |
| 47 void Release(); |
| 48 |
| 49 base::Closure quit_closure_; |
| 50 int ref_count_ = 0; |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(MessageLoopRefFactory); |
| 53 }; |
| 54 |
| 55 } // namespace mojo |
| 56 |
| 57 #endif // MOJO_SHELL_PUBLIC_CPP_APPLICATION_RUNNER_REFERENCE_H_ |
OLD | NEW |