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

Side by Side Diff: components/copresence/handlers/audio/audio_directive_list.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_LIST_H_ 5 #ifndef COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_
6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_ 6 #define COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h" 11 #include "base/callback_forward.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/default_tick_clock.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "components/copresence/handlers/audio/tick_clock_ref_counted.h"
16 17
17 namespace media { 18 namespace media {
18 class AudioBusRefCounted; 19 class AudioBusRefCounted;
19 } 20 }
20 21
21 namespace copresence { 22 namespace copresence {
22 23
23 class TickClockRefCounted; 24 class TickClockRefCounted;
24 25
25 struct AudioDirective final { 26 struct AudioDirective final {
26 // Default ctor, required by the priority queue. 27 // Default ctor, required by the priority queue.
27 AudioDirective(); 28 AudioDirective();
28 AudioDirective(const std::string& op_id, base::TimeTicks end_time); 29 AudioDirective(const std::string& op_id, base::TimeTicks end_time);
29 30
30 std::string op_id; 31 std::string op_id;
31 // We're currently using TimeTicks to track time. This may not work for cases 32 // We're currently using TimeTicks to track time. This may not work for cases
32 // where your machine suspends. See crbug.com/426136 33 // where your machine suspends. See crbug.com/426136
33 base::TimeTicks end_time; 34 base::TimeTicks end_time;
34 }; 35 };
35 36
36 // This class maintains a list of active audio directives. It fetches the audio 37 // This class maintains a list of active audio directives. It fetches the audio
37 // samples associated with a audio transmit directives and expires directives 38 // samples associated with a audio transmit directives and expires directives
38 // that have outlived their TTL. 39 // that have outlived their TTL.
39 // TODO(rkc): Once we implement more token technologies, move reusable code 40 // TODO(rkc): Once we implement more token technologies, move reusable code
40 // from here to a base class and inherit various XxxxDirectiveList 41 // from here to a base class and inherit various XxxxDirectiveList
41 // classes from it. 42 // classes from it.
42 class AudioDirectiveList { 43 class AudioDirectiveList {
43 public: 44 public:
44 AudioDirectiveList(); 45 explicit AudioDirectiveList(const scoped_refptr<TickClockRefCounted>& clock =
46 make_scoped_refptr(new TickClockRefCounted(new base::DefaultTickClock)));
45 ~AudioDirectiveList(); 47 ~AudioDirectiveList();
46 48
47 void AddDirective(const std::string& op_id, base::TimeDelta ttl); 49 void AddDirective(const std::string& op_id, base::TimeDelta ttl);
48 void RemoveDirective(const std::string& op_id); 50 void RemoveDirective(const std::string& op_id);
49 51
50 scoped_ptr<AudioDirective> GetActiveDirective(); 52 scoped_ptr<AudioDirective> GetActiveDirective();
51 53
52 void set_clock_for_testing(const scoped_refptr<TickClockRefCounted>& clock);
53
54 private: 54 private:
55 // Comparator for comparing end_times on audio tokens. 55 // Comparator for comparing end_times on audio tokens.
56 class LatestFirstComparator { 56 class LatestFirstComparator {
57 public: 57 public:
58 // This will sort our queue with the 'latest' time being the top. 58 // This will sort our queue with the 'latest' time being the top.
59 bool operator()(const AudioDirective& left, 59 bool operator()(const AudioDirective& left,
60 const AudioDirective& right) const { 60 const AudioDirective& right) const {
61 return left.end_time < right.end_time; 61 return left.end_time < right.end_time;
62 } 62 }
63 }; 63 };
64 64
65 std::vector<AudioDirective>::iterator FindDirectiveByOpId( 65 std::vector<AudioDirective>::iterator FindDirectiveByOpId(
66 const std::string& op_id); 66 const std::string& op_id);
67 67
68 // This vector will be organized as a heap with the latest time as the first 68 // This vector will be organized as a heap with the latest time as the first
69 // element. Only currently active directives will exist in this list. 69 // element. Only currently active directives will exist in this list.
70 std::vector<AudioDirective> active_directives_; 70 std::vector<AudioDirective> active_directives_;
71 71
72 scoped_refptr<TickClockRefCounted> clock_; 72 scoped_refptr<TickClockRefCounted> clock_;
73 73
74 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveList); 74 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveList);
75 }; 75 };
76 76
77 } // namespace copresence 77 } // namespace copresence
78 78
79 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_ 79 #endif // COMPONENTS_COPRESENCE_HANDLERS_AUDIO_AUDIO_DIRECTIVE_LIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698