1 // Copyright 2014 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.
5 #include "mojo/shell/keep_alive.h"
8 #include "mojo/shell/context.h"
13 KeepAlive::KeepAlive(Context
* context
) : context_(context
) {
14 DCHECK(context_
->task_runners()->ui_runner()->RunsTasksOnCurrentThread());
15 ++context_
->keep_alive_counter()->count_
;
18 KeepAlive::~KeepAlive() {
19 DCHECK(context_
->task_runners()->ui_runner()->RunsTasksOnCurrentThread());
20 if (--context_
->keep_alive_counter()->count_
== 0) {
21 base::MessageLoop::current()->PostTask(
23 base::Bind(&KeepAlive::MaybeQuit
, context_
));
28 void KeepAlive::MaybeQuit(Context
* context
) {
29 if (context
->keep_alive_counter()->count_
== 0)
30 base::MessageLoop::current()->Quit();