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..09733d9a40eb924ebaa0d553c1886cbf7e523cd8 |
--- /dev/null |
+++ b/mojo/application/app_lifetime_helper.cc |
@@ -0,0 +1,44 @@ |
+// 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 { |
+ |
+AppRefCount::AppRefCount( |
+ const base::WeakPtr<AppLifetimeHelper>& app_lifetime_helper) |
+ : app_lifetime_helper_(app_lifetime_helper) { |
+} |
+ |
+AppRefCount::~AppRefCount() { |
+ // We have to null check first because at launcher shutdown it is valid that |
+ // the app goes away while there are outstanding service objects. |
+ if (app_lifetime_helper_) |
+ app_lifetime_helper_->Release(); |
+} |
+ |
+scoped_ptr<AppRefCount> AppRefCount::Clone() { |
+ return app_lifetime_helper_->CreateAppRefCount(); |
+} |
+ |
+AppLifetimeHelper::AppLifetimeHelper() : ref_count_(0), weak_factory_(this) { |
+} |
+ |
+AppLifetimeHelper::~AppLifetimeHelper() { |
+} |
+ |
+scoped_ptr<AppRefCount> AppLifetimeHelper::CreateAppRefCount() { |
+ ref_count_++; |
+ return make_scoped_ptr(new AppRefCount(weak_factory_.GetWeakPtr())); |
+} |
+ |
+void AppLifetimeHelper::Release() { |
+ if (!--ref_count_) |
+ ApplicationImpl::Terminate(); |
+} |
+ |
+} // namespace mojo |