forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeep_alive.cc
34 lines (27 loc) · 961 Bytes
/
keep_alive.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2014 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/shell/keep_alive.h"
#include "base/bind.h"
#include "mojo/shell/context.h"
namespace mojo {
namespace shell {
KeepAlive::KeepAlive(Context* context) : context_(context) {
DCHECK(context_->task_runners()->shell_runner()->RunsTasksOnCurrentThread());
++context_->keep_alive_counter()->count_;
}
KeepAlive::~KeepAlive() {
DCHECK(context_->task_runners()->shell_runner()->RunsTasksOnCurrentThread());
if (--context_->keep_alive_counter()->count_ == 0) {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&KeepAlive::MaybeQuit, context_));
}
}
// static
void KeepAlive::MaybeQuit(Context* context) {
if (context->keep_alive_counter()->count_ == 0)
base::MessageLoop::current()->Quit();
}
} // namespace shell
} // namespace mojo