OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/background_sync/background_sync_registration.h" | 5 #include "content/browser/background_sync/background_sync_registration.h" |
6 | 6 |
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" | |
12 | |
7 namespace content { | 13 namespace content { |
8 | 14 |
9 const BackgroundSyncRegistration::RegistrationId | 15 const BackgroundSyncRegistration::RegistrationId |
10 BackgroundSyncRegistration::kInvalidRegistrationId = -1; | 16 BackgroundSyncRegistration::kInvalidRegistrationId = -1; |
11 | 17 |
12 const BackgroundSyncRegistration::RegistrationId | 18 const BackgroundSyncRegistration::RegistrationId |
13 BackgroundSyncRegistration::kInitialId = 0; | 19 BackgroundSyncRegistration::kInitialId = 0; |
14 | 20 |
21 BackgroundSyncRegistration::BackgroundSyncRegistration() = default; | |
22 BackgroundSyncRegistration::~BackgroundSyncRegistration() = default; | |
23 | |
15 bool BackgroundSyncRegistration::Equals( | 24 bool BackgroundSyncRegistration::Equals( |
16 const BackgroundSyncRegistration& other) const { | 25 const BackgroundSyncRegistration& other) const { |
17 return options_.Equals(other.options_); | 26 return options_.Equals(other.options_); |
18 } | 27 } |
19 | 28 |
20 bool BackgroundSyncRegistration::IsValid() const { | 29 bool BackgroundSyncRegistration::IsValid() const { |
21 return id_ != kInvalidRegistrationId; | 30 return id_ != kInvalidRegistrationId; |
22 } | 31 } |
23 | 32 |
33 void BackgroundSyncRegistration::AddDoneCallback( | |
34 const StateCallback& callback) { | |
35 DCHECK_NE(BACKGROUND_SYNC_STATE_SUCCESS, sync_state_); | |
36 DCHECK_NE(BACKGROUND_SYNC_STATE_FAILED, sync_state_); | |
37 DCHECK_NE(BACKGROUND_SYNC_STATE_UNREGISTERED, sync_state_); | |
iclelland
2015/09/17 13:48:09
This set of negative tests complements the positiv
jkarlin
2015/09/17 17:40:25
Nice catch. I've added HasCompleted() which uses a
| |
38 notify_done_callbacks_.push_back(callback); | |
39 } | |
40 | |
41 void BackgroundSyncRegistration::RunDoneCallbacks() { | |
42 DCHECK_NE(BACKGROUND_SYNC_STATE_PENDING, sync_state_); | |
43 DCHECK_NE(BACKGROUND_SYNC_STATE_FIRING, sync_state_); | |
44 | |
45 for (auto& callback : notify_done_callbacks_) { | |
46 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
47 FROM_HERE, base::Bind(callback, sync_state_)); | |
48 } | |
49 | |
50 notify_done_callbacks_.clear(); | |
51 } | |
52 | |
24 } // namespace content | 53 } // namespace content |
OLD | NEW |