Extension syncing: Introduce a NeedsSync pref
[chromium-blink-merge.git] / components / copresence / handlers / audio / audio_directive_handler_impl.h
blob5dc9230c9ad4fbc9f97780abe8e20aa728bca684
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 COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_IMPL_H_
6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_IMPL_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
15 #include "components/audio_modem/public/modem.h"
16 #include "components/copresence/handlers/audio/audio_directive_handler.h"
17 #include "components/copresence/public/copresence_constants.h"
19 namespace base {
20 class TimeTicks;
21 class Timer;
24 namespace media {
25 class AudioBusRefCounted;
28 namespace copresence {
30 class AudioDirectiveList;
31 class TickClockRefCounted;
33 // The AudioDirectiveHandler handles audio transmit and receive instructions.
34 // TODO(rkc): Currently since WhispernetClient can only have one token encoded
35 // callback at a time, we need to have both the audible and inaudible in this
36 // class. Investigate a better way to do this; a few options are abstracting
37 // out token encoding to a separate class, or allowing whispernet to have
38 // multiple callbacks for encoded tokens being sent back and have two versions
39 // of this class.
40 class AudioDirectiveHandlerImpl final : public AudioDirectiveHandler {
41 public:
42 explicit AudioDirectiveHandlerImpl(
43 const DirectivesCallback& update_directives_callback);
44 AudioDirectiveHandlerImpl(
45 const DirectivesCallback& update_directives_callback,
46 scoped_ptr<audio_modem::Modem> audio_modem,
47 scoped_ptr<base::Timer> timer,
48 const scoped_refptr<TickClockRefCounted>& clock);
50 ~AudioDirectiveHandlerImpl() override;
52 // AudioDirectiveHandler overrides:
53 void Initialize(audio_modem::WhispernetClient* whispernet_client,
54 const audio_modem::TokensCallback& tokens_cb) override;
55 void AddInstruction(const Directive& directive,
56 const std::string& op_id) override;
57 void RemoveInstructions(const std::string& op_id) override;
58 const std::string PlayingToken(audio_modem::AudioType type) const override;
59 bool IsPlayingTokenHeard(audio_modem::AudioType type) const override;
61 private:
62 // Processes the next active instruction,
63 // updating our audio manager state accordingly.
64 void ProcessNextInstruction();
66 // Returns the time that an instruction expires at. This will always return
67 // the earliest expiry time among all the active receive and transmit
68 // instructions. If we don't have any active instructions, returns false.
69 bool GetNextInstructionExpiry(base::TimeTicks* next_event);
71 DirectivesCallback update_directives_callback_;
72 scoped_ptr<audio_modem::Modem> audio_modem_;
73 scoped_ptr<base::Timer> audio_event_timer_;
74 scoped_refptr<TickClockRefCounted> clock_;
76 // Lists of transmits and receives, for both audible and inaudible tokens.
77 // AUDIBLE = element 0, INAUDIBLE = element 1 (see copresence_constants.h).
78 ScopedVector<AudioDirectiveList> transmits_lists_;
79 ScopedVector<AudioDirectiveList> receives_lists_;
81 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveHandlerImpl);
84 } // namespace copresence
86 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_IMPL_H_