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

Side by Side 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 X errors on Linux 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/application/app_lifetime_helper.h"
6
7 #include "base/time/tick_clock.h"
8 #include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h"
9
10 namespace mojo {
11
12 AppRefCount::AppRefCount(
13 const base::WeakPtr<AppLifetimeHelper>& app_lifetime_helper)
14 : app_lifetime_helper_(app_lifetime_helper) {
15 }
16
17 AppRefCount::~AppRefCount() {
18 // We have to null check first because at launcher shutdown it is valid that
19 // the app goes away while there are outstanding service objects.
20 if (app_lifetime_helper_)
21 app_lifetime_helper_->Release();
22 }
23
24 scoped_ptr<AppRefCount> AppRefCount::Clone() {
25 return app_lifetime_helper_->CreateAppRefCount();
26 }
27
28 AppLifetimeHelper::AppLifetimeHelper() : ref_count_(0), weak_factory_(this) {
29 }
30
31 AppLifetimeHelper::~AppLifetimeHelper() {
32 }
33
34 scoped_ptr<AppRefCount> AppLifetimeHelper::CreateAppRefCount() {
35 ref_count_++;
36 return make_scoped_ptr(new AppRefCount(weak_factory_.GetWeakPtr()));
37 }
38
39 void AppLifetimeHelper::Release() {
40 if (!--ref_count_)
41 ApplicationImpl::Terminate();
42 }
43
44 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698