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

Unified Diff: mojo/application/app_lifetime_helper.cc

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.cc
diff --git a/mojo/application/app_lifetime_helper.cc b/mojo/application/app_lifetime_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5d4a0b23fea43e41ed35e549a8e506dbc03a73c4
--- /dev/null
+++ b/mojo/application/app_lifetime_helper.cc
@@ -0,0 +1,36 @@
+// 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.
+
+#include "mojo/application/app_lifetime_helper.h"
+
+#include "base/time/tick_clock.h"
+#include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h"
+
+namespace mojo {
+
+ServiceRefcount::ServiceRefcount(AppLifetimeHelper* app_lifetime_helper)
+ : app_lifetime_helper_(app_lifetime_helper) {
+}
+
+ServiceRefcount::~ServiceRefcount() {
+ app_lifetime_helper_->Release();
+}
+
+AppLifetimeHelper::AppLifetimeHelper() : ref_count_(0) {
+}
+
+AppLifetimeHelper::~AppLifetimeHelper() {
+}
+
+scoped_ptr<ServiceRefcount> AppLifetimeHelper::CreateServiceRefCount() {
+ ref_count_++;
+ return make_scoped_ptr(new ServiceRefcount(this));
+}
+
+void AppLifetimeHelper::Release() {
+ if (!--ref_count_)
+ ApplicationImpl::Terminate();
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698