Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_database_task_manager.h
bloba54b252accf4c7c99f54f86eac603fb81a84fb86
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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_TASK_MANAGER_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_TASK_MANAGER_H_
8 #include "base/memory/ref_counted.h"
9 #include "content/common/content_export.h"
11 namespace base {
12 class SequencedTaskRunner;
15 namespace content {
17 // Used to sequence ServiceWorkerDatabase tasks. Vends two task runners: one
18 // that blocks shutdown and one that doesn't. The task runners use the same
19 // sequence token, so no matter which runner you post to, the tasks run in the
20 // order they are posted. This lets you post sequenced tasks with mixed shutdown
21 // behaviors.
22 class ServiceWorkerDatabaseTaskManager {
23 public:
24 virtual ~ServiceWorkerDatabaseTaskManager(){};
25 virtual scoped_ptr<ServiceWorkerDatabaseTaskManager> Clone() = 0;
26 virtual base::SequencedTaskRunner* GetTaskRunner() = 0;
27 virtual base::SequencedTaskRunner* GetShutdownBlockingTaskRunner() = 0;
30 class ServiceWorkerDatabaseTaskManagerImpl
31 : public ServiceWorkerDatabaseTaskManager {
32 public:
33 explicit ServiceWorkerDatabaseTaskManagerImpl(
34 base::SequencedWorkerPool* pool);
35 ~ServiceWorkerDatabaseTaskManagerImpl() override;
37 protected:
38 scoped_ptr<ServiceWorkerDatabaseTaskManager> Clone() override;
39 base::SequencedTaskRunner* GetTaskRunner() override;
40 base::SequencedTaskRunner* GetShutdownBlockingTaskRunner() override;
42 private:
43 ServiceWorkerDatabaseTaskManagerImpl(
44 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
45 const scoped_refptr<base::SequencedTaskRunner>&
46 shutdown_blocking_task_runner);
48 scoped_refptr<base::SequencedTaskRunner> task_runner_;
49 scoped_refptr<base::SequencedTaskRunner> shutdown_blocking_task_runner_;
51 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabaseTaskManagerImpl);
54 // Dummy implementation for testing. It vends whatever you give it in the ctor.
55 class CONTENT_EXPORT MockServiceWorkerDatabaseTaskManager
56 : public NON_EXPORTED_BASE(ServiceWorkerDatabaseTaskManager) {
57 public:
58 explicit MockServiceWorkerDatabaseTaskManager(
59 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
60 ~MockServiceWorkerDatabaseTaskManager() override;
62 protected:
63 scoped_ptr<ServiceWorkerDatabaseTaskManager> Clone() override;
64 base::SequencedTaskRunner* GetTaskRunner() override;
65 base::SequencedTaskRunner* GetShutdownBlockingTaskRunner() override;
67 private:
68 scoped_refptr<base::SequencedTaskRunner> task_runner_;
70 DISALLOW_COPY_AND_ASSIGN(MockServiceWorkerDatabaseTaskManager);
73 } // namespace content
75 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_TASK_MANAGER_H_