summaryrefslogtreecommitdiff
path: root/chromium/headless/public/util/throttled_dispatcher.h
blob: 152dbd75aebae1f9125883319675367300fe62fb (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
// Copyright 2017 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 HEADLESS_PUBLIC_UTIL_THROTTLED_DISPATCHER_H_
#define HEADLESS_PUBLIC_UTIL_THROTTLED_DISPATCHER_H_

#include <vector>

#include "headless/public/util/expedited_dispatcher.h"

namespace headless {

class ManagedDispatchURLRequestJob;

// Similar to ExpeditedDispatcher except network fetches can be paused.
class HEADLESS_EXPORT ThrottledDispatcher : public ExpeditedDispatcher {
 public:
  explicit ThrottledDispatcher(
      scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner);
  ~ThrottledDispatcher() override;

  void PauseRequests();
  void ResumeRequests();

  // UrlRequestDispatcher implementation:
  void DataReady(ManagedDispatchURLRequestJob* job) override;
  void JobDeleted(ManagedDispatchURLRequestJob* job) override;

 private:
  // Protects all members below.
  base::Lock lock_;
  bool requests_paused_;
  std::vector<ManagedDispatchURLRequestJob*> paused_jobs_;

  DISALLOW_COPY_AND_ASSIGN(ThrottledDispatcher);
};

}  // namespace headless

#endif  // HEADLESS_PUBLIC_UTIL_EXPEDITED_DISPATCHER_H_