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

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: rebase 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/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "mojo/application/public/cpp/application_impl.h"
10
11 namespace mojo {
12
13 AppRefCount::AppRefCount(
14 AppLifetimeHelper* app_lifetime_helper,
15 scoped_refptr<base::SingleThreadTaskRunner> app_task_runner)
16 : app_lifetime_helper_(app_lifetime_helper),
17 app_task_runner_(app_task_runner) {
18 }
19
20 AppRefCount::~AppRefCount() {
21 if (app_task_runner_->BelongsToCurrentThread()) {
22 app_lifetime_helper_->Release();
23 return;
24 }
25
26 app_task_runner_->PostTask(
27 FROM_HERE,
28 base::Bind(&AppLifetimeHelper::Release,
29 base::Unretained(app_lifetime_helper_)));
30 }
31
32 scoped_ptr<AppRefCount> AppRefCount::Clone() {
33 if (app_task_runner_->BelongsToCurrentThread()) {
34 app_lifetime_helper_->AddRef();
35 } else {
36 app_task_runner_->PostTask(
37 FROM_HERE,
38 base::Bind(&AppLifetimeHelper::AddRef,
yzshen1 2015/05/15 06:56:12 Is it possible to have races because of this AddRe
jam 2015/05/15 07:08:44 I had thought about this, but I convinced myself t
39 base::Unretained(app_lifetime_helper_)));
40 }
41
42 return make_scoped_ptr(new AppRefCount(
43 app_lifetime_helper_, app_task_runner_));
44 }
45
46 AppLifetimeHelper::AppLifetimeHelper()
47 : ref_count_(0) {
48 }
49
50 AppLifetimeHelper::~AppLifetimeHelper() {
51 }
52
53 scoped_ptr<AppRefCount> AppLifetimeHelper::CreateAppRefCount() {
54 AddRef();
55 return make_scoped_ptr(new AppRefCount(
56 this, base::MessageLoop::current()->task_runner()));
57 }
58
59 void AppLifetimeHelper::AddRef() {
60 ref_count_++;
61 }
62
63 void AppLifetimeHelper::Release() {
64 if (!--ref_count_)
65 ApplicationImpl::Terminate();
66 }
67
68 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/application/app_lifetime_helper.h ('k') | mojo/runner/android/native_viewport_application_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698