summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/blink/renderer/modules/webaudio/offline_audio_worklet_thread.h
blob: 586531e134cd50bd23263a595fa92c84df2f15ab (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
44
45
46
47
// Copyright 2020 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 THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_OFFLINE_AUDIO_WORKLET_THREAD_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_OFFLINE_AUDIO_WORKLET_THREAD_H_

#include "third_party/blink/renderer/core/workers/worker_thread.h"
#include "third_party/blink/renderer/core/workers/worklet_thread_holder.h"
#include "third_party/blink/renderer/modules/modules_export.h"

namespace blink {

class WorkerReportingProxy;
struct ThreadCreationParams;

// OfflineAudioWorkletThread is a per-AudioWorkletGlobalScope object that has a
// reference count to the backing thread that performs AudioWorklet tasks.
// Its backing thread uses NORMAL priority no matter what the environment
// or the feature flag setting is.
class MODULES_EXPORT OfflineAudioWorkletThread final : public WorkerThread {
 public:
  explicit OfflineAudioWorkletThread(WorkerReportingProxy&);
  ~OfflineAudioWorkletThread() final;

  WorkerBackingThread& GetWorkerBackingThread() final;
  void ClearWorkerBackingThread() final {}

  static void EnsureSharedBackingThread(const ThreadCreationParams&);
  static void ClearSharedBackingThread();

 private:
  WorkerOrWorkletGlobalScope* CreateWorkerGlobalScope(
      std::unique_ptr<GlobalScopeCreationParams>) final;
  bool IsOwningBackingThread() const final { return false; }
  ThreadType GetThreadType() const final {
    return ThreadType::kOfflineAudioWorkletThread;
  }

  // Use for ref-counting of all OfflineAudioWorkletThread instances in a
  // process. Incremented by the constructor and decremented by destructor.
  static int s_ref_count_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_OFFLINE_AUDIO_WORKLET_THREAD_H_