Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / content / browser / background_sync / background_sync_registration.cc
blob30bbf9e2afaf43ff13f394d8cbaf50991d79dcd5
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.
5 #include "content/browser/background_sync/background_sync_registration.h"
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/logging.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h"
13 namespace content {
15 const BackgroundSyncRegistration::RegistrationId
16 BackgroundSyncRegistration::kInvalidRegistrationId = -1;
18 const BackgroundSyncRegistration::RegistrationId
19 BackgroundSyncRegistration::kInitialId = 0;
21 BackgroundSyncRegistration::BackgroundSyncRegistration() = default;
22 BackgroundSyncRegistration::~BackgroundSyncRegistration() = default;
24 bool BackgroundSyncRegistration::Equals(
25 const BackgroundSyncRegistration& other) const {
26 return options_.Equals(other.options_);
29 bool BackgroundSyncRegistration::IsValid() const {
30 return id_ != kInvalidRegistrationId;
33 void BackgroundSyncRegistration::AddDoneCallback(
34 const StateCallback& callback) {
35 DCHECK(!HasCompleted());
36 notify_done_callbacks_.push_back(callback);
39 void BackgroundSyncRegistration::RunDoneCallbacks() {
40 DCHECK(HasCompleted());
42 for (auto& callback : notify_done_callbacks_) {
43 base::ThreadTaskRunnerHandle::Get()->PostTask(
44 FROM_HERE, base::Bind(callback, sync_state_));
47 notify_done_callbacks_.clear();
50 bool BackgroundSyncRegistration::HasCompleted() const {
51 switch (sync_state_) {
52 case BACKGROUND_SYNC_STATE_PENDING:
53 case BACKGROUND_SYNC_STATE_FIRING:
54 case BACKGROUND_SYNC_STATE_UNREGISTERED_WHILE_FIRING:
55 return false;
56 case BACKGROUND_SYNC_STATE_FAILED:
57 case BACKGROUND_SYNC_STATE_SUCCESS:
58 case BACKGROUND_SYNC_STATE_UNREGISTERED:
59 return true;
61 NOTREACHED();
62 return false;
65 } // namespace content