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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
content / test / test_background_sync_proxy.h [blame]
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_TEST_TEST_BACKGROUND_SYNC_PROXY_H_
#define CONTENT_TEST_TEST_BACKGROUND_SYNC_PROXY_H_
#include "base/functional/callback_forward.h"
#include "base/memory/scoped_refptr.h"
#include "base/time/time.h"
#include "content/browser/background_sync/background_sync_proxy.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
namespace content {
class TestBackgroundSyncProxy : public BackgroundSyncProxy {
public:
explicit TestBackgroundSyncProxy(
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context)
: BackgroundSyncProxy(service_worker_context) {}
~TestBackgroundSyncProxy() override;
void ScheduleDelayedProcessing(blink::mojom::BackgroundSyncType sync_type,
base::TimeDelta delay,
base::OnceClosure delayed_task) override;
base::OneShotTimer& GetDelayedTimer(
blink::mojom::BackgroundSyncType sync_type) {
if (sync_type == blink::mojom::BackgroundSyncType::ONE_SHOT)
return one_shot_sync_delay_timer_;
else
return periodic_sync_delay_timer_;
}
void RunDelayedTask(blink::mojom::BackgroundSyncType sync_type) {
GetDelayedTimer(sync_type).FireNow();
}
bool IsDelayedTaskSet(blink::mojom::BackgroundSyncType sync_type) {
return GetDelayedTimer(sync_type).IsRunning();
}
base::TimeDelta GetDelay(blink::mojom::BackgroundSyncType sync_type) {
return GetDelayedTimer(sync_type).GetCurrentDelay();
}
private:
base::OneShotTimer one_shot_sync_delay_timer_;
base::OneShotTimer periodic_sync_delay_timer_;
};
} // namespace content
#endif // CONTENT_TEST_TEST_BACKGROUND_SYNC_PROXY_H_