Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1848)

Side by Side Diff: components/copresence/handlers/audio/audio_directive_handler_impl.h

Issue 690213004: Refactoring AudioDirectiveHandler to support testing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_H_ 5 #ifndef COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_IMPL_H_
6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_H_ 6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_IMPL_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h"
11 #include "base/macros.h" 10 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h" 13 #include "base/memory/scoped_vector.h"
15 #include "components/copresence/handlers/audio/audio_directive_list.h" 14 #include "components/copresence/handlers/audio/audio_directive_handler.h"
16 #include "components/copresence/mediums/audio/audio_manager.h"
17 #include "components/copresence/proto/data.pb.h"
18 15
19 namespace base { 16 namespace base {
17 class TimeTicks;
20 class Timer; 18 class Timer;
21 } 19 }
22 20
23 namespace media { 21 namespace media {
24 class AudioBusRefCounted; 22 class AudioBusRefCounted;
25 } 23 }
26 24
27 namespace copresence { 25 namespace copresence {
28 26
27 class AudioDirectiveList;
29 class TickClockRefCounted; 28 class TickClockRefCounted;
30 29
31 // The AudioDirectiveHandler handles audio transmit and receive instructions. 30 // The AudioDirectiveHandler handles audio transmit and receive instructions.
32 // TODO(rkc): Currently since WhispernetClient can only have one token encoded 31 // TODO(rkc): Currently since WhispernetClient can only have one token encoded
33 // callback at a time, we need to have both the audible and inaudible in this 32 // callback at a time, we need to have both the audible and inaudible in this
34 // class. Investigate a better way to do this; a few options are abstracting 33 // class. Investigate a better way to do this; a few options are abstracting
35 // out token encoding to a separate class, or allowing whispernet to have 34 // out token encoding to a separate class, or allowing whispernet to have
36 // multiple callbacks for encoded tokens being sent back and have two versions 35 // multiple callbacks for encoded tokens being sent back and have two versions
37 // of this class. 36 // of this class.
38 class AudioDirectiveHandler final { 37 class AudioDirectiveHandlerImpl final : public AudioDirectiveHandler {
39 public: 38 public:
40 AudioDirectiveHandler(); 39 AudioDirectiveHandlerImpl();
41 ~AudioDirectiveHandler(); 40 AudioDirectiveHandlerImpl(scoped_ptr<AudioManager> audio_manager,
41 scoped_ptr<base::Timer> timer,
42 const scoped_refptr<TickClockRefCounted>& clock);
43
44 ~AudioDirectiveHandlerImpl();
42 45
43 // Do not use this class before calling this. 46 // Do not use this class before calling this.
44 void Initialize(const AudioManager::DecodeSamplesCallback& decode_cb, 47 void Initialize(const AudioManager::DecodeSamplesCallback& decode_cb,
45 const AudioManager::EncodeTokenCallback& encode_cb); 48 const AudioManager::EncodeTokenCallback& encode_cb) override;
46 49
47 // Adds an instruction to our handler. The instruction will execute and be 50 // Adds an instruction to our handler. The instruction will execute and be
48 // removed after the ttl expires. 51 // removed after the ttl expires.
49 void AddInstruction(const copresence::TokenInstruction& instruction, 52 void AddInstruction(const copresence::TokenInstruction& instruction,
50 const std::string& op_id, 53 const std::string& op_id,
51 base::TimeDelta ttl_ms); 54 base::TimeDelta ttl_ms) override;
52 55
53 // Removes all instructions associated with this operation id. 56 // Removes all instructions associated with this operation id.
54 void RemoveInstructions(const std::string& op_id); 57 void RemoveInstructions(const std::string& op_id) override;
55 58
56 // Returns the currently playing token. 59 // Returns the currently playing token.
57 const std::string PlayingToken(AudioType type) const; 60 const std::string PlayingToken(AudioType type) const override;
58
59 // The manager being passed in needs to be uninitialized.
60 void set_audio_manager_for_testing(scoped_ptr<AudioManager> manager) {
61 audio_manager_ = manager.Pass();
62 }
63
64 void set_clock_for_testing(const scoped_refptr<TickClockRefCounted>& clock);
65 void set_timer_for_testing(scoped_ptr<base::Timer> timer);
66 61
67 private: 62 private:
68 // Processes the next active instruction, updating our audio manager state 63 // Processes the next active instruction,
69 // accordingly. 64 // updating our audio manager state accordingly.
70 void ProcessNextInstruction(); 65 void ProcessNextInstruction();
71 66
72 // Returns the time that an instruction expires at. This will always return 67 // Returns the time that an instruction expires at. This will always return
73 // the earliest expiry time among all the active receive and transmit 68 // the earliest expiry time among all the active receive and transmit
74 // instructions. In case we don't have any active instructions, this method 69 // instructions. If we don't have any active instructions, returns false.
75 // returns false.
76 bool GetNextInstructionExpiry(base::TimeTicks* next_event); 70 bool GetNextInstructionExpiry(base::TimeTicks* next_event);
77 71
78 scoped_ptr<AudioManager> audio_manager_; 72 scoped_ptr<AudioManager> audio_manager_;
79 73
80 // Audible and inaudible lists.
81 // AUDIBLE = 0, INAUDIBLE = 1 (see copresence_constants.h).
82 AudioDirectiveList transmits_list_[2];
83 AudioDirectiveList receives_list_[2];
84
85 scoped_ptr<base::Timer> audio_event_timer_; 74 scoped_ptr<base::Timer> audio_event_timer_;
86
87 scoped_refptr<TickClockRefCounted> clock_; 75 scoped_refptr<TickClockRefCounted> clock_;
88 76
89 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveHandler); 77 // Lists of transmits and receives, for both audible and inaudible tokens.
78 // AUDIBLE = element 0, INAUDIBLE = element 1 (see copresence_constants.h).
79 ScopedVector<AudioDirectiveList> transmits_lists_;
80 ScopedVector<AudioDirectiveList> receives_lists_;
81
82
83 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveHandlerImpl);
90 }; 84 };
91 85
92 } // namespace copresence 86 } // namespace copresence
93 87
94 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_H_ 88 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_HANDLER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698