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 |