Add ICU message format support
[chromium-blink-merge.git] / cc / base / unique_notifier.cc
blobeb0b09af36e6b4e50fb133cc95c3b559f449ec79
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 "cc/base/unique_notifier.h"
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/location.h"
10 #include "base/sequenced_task_runner.h"
12 namespace cc {
14 UniqueNotifier::UniqueNotifier(base::SequencedTaskRunner* task_runner,
15 const base::Closure& closure)
16 : task_runner_(task_runner),
17 closure_(closure),
18 notification_pending_(false),
19 weak_ptr_factory_(this) {
22 UniqueNotifier::~UniqueNotifier() {
25 void UniqueNotifier::Cancel() {
26 notification_pending_ = false;
29 void UniqueNotifier::Schedule() {
30 if (notification_pending_)
31 return;
33 task_runner_->PostTask(
34 FROM_HERE,
35 base::Bind(&UniqueNotifier::Notify, weak_ptr_factory_.GetWeakPtr()));
36 notification_pending_ = true;
39 void UniqueNotifier::Notify() {
40 if (!notification_pending_)
41 return;
43 // Note that the order here is important in case closure schedules another
44 // run.
45 notification_pending_ = false;
46 closure_.Run();
49 } // namespace cc