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

Unified Diff: mojo/application/app_lifetime_helper.h

Issue 1139673003: Make Mandoline shut down cleanly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix crash in surfaces if surfaceimpl outlives the app, and a double delete in browser Created 5 years, 7 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: 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_

Powered by Google App Engine
This is Rietveld 408576698