Index: mojo/application/app_lifetime_helper.h |
diff --git a/mojo/application/app_lifetime_helper.h b/mojo/application/app_lifetime_helper.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bbbf844666cc8849b95308aad53e5db4c8bf5ae8 |
--- /dev/null |
+++ b/mojo/application/app_lifetime_helper.h |
@@ -0,0 +1,49 @@ |
+// Copyright 2015 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_APPLICATION_APP_LIFETIME_HELPER_H_ |
+#define MOJO_APPLICATION_APP_LIFETIME_HELPER_H_ |
+ |
+#include "base/basictypes.h" |
+#include "base/memory/scoped_ptr.h" |
+ |
+namespace mojo { |
+ |
+class AppLifetimeHelper; |
+ |
+class ServiceRefcount { |
+ public: |
+ ServiceRefcount(AppLifetimeHelper* app_lifetime_helper); |
Ben Goodger (Google)
2015/05/13 20:21:07
explicit
jam
2015/05/14 14:42:47
Done.
|
+ ~ServiceRefcount(); |
+ |
+ private: |
+ AppLifetimeHelper* app_lifetime_helper_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ServiceRefcount); |
+}; |
+ |
+// This is a helper class for apps to manage their lifetime. |
+// An app can contain an object of this class as a member variable. Each time it |
+// creates an instance of a service, it gives it a refcount using |
+// CreateServiceRefCount. The service implementation then keeps that object as a |
+// member variable. When all the service implemenations go away, the app will be |
+// quit with a call to mojo::ApplicationImpl::Terminate(). |
+class AppLifetimeHelper { |
+ public: |
+ AppLifetimeHelper(); |
+ ~AppLifetimeHelper(); |
+ |
+ scoped_ptr<ServiceRefcount> CreateServiceRefCount(); |
+ |
+ private: |
+ friend ServiceRefcount; |
+ void Release(); |
+ |
+ int ref_count_; |
+ DISALLOW_COPY_AND_ASSIGN(AppLifetimeHelper); |
+}; |
+ |
+} // namespace mojo |
+ |
+#endif // MOJO_APPLICATION_APP_LIFETIME_HELPER_H_ |