summaryrefslogtreecommitdiffstats
path: root/content/browser/cache_storage/cache_storage_scheduler.h
blob: 32e7617de00cd696f3a674eeebe8ee1038d6bcf4 (plain)
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
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_SCHEDULER_H_
#define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_SCHEDULER_H_

#include <list>

#include "base/callback.h"
#include "content/common/content_export.h"

namespace content {

class CONTENT_EXPORT CacheStorageScheduler {
 public:
  CacheStorageScheduler();
  virtual ~CacheStorageScheduler();

  // Adds the operation to the tail of the queue and starts it if the scheduler
  // is idle.
  void ScheduleOperation(const base::Closure& closure);

  // Call this after each operation completes. It cleans up the current
  // operation and starts the next.
  void CompleteOperationAndRunNext();

  // Returns true if there are any running or pending operations.
  bool ScheduledOperations() const;

 private:
  void RunOperationIfIdle();

  // The list of operations waiting on initialization.
  std::list<base::Closure> pending_operations_;
  bool operation_running_;

  DISALLOW_COPY_AND_ASSIGN(CacheStorageScheduler);
};

}  // namespace content

#endif  // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_SCHEDULER_H_