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

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

Issue 824593003: Revert of Adding CopresenceState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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_forward.h" 11 #include "base/callback_forward.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/default_tick_clock.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 #include "components/copresence/handlers/audio/tick_clock_ref_counted.h"
17 #include "components/copresence/proto/data.pb.h"
18 17
19 namespace media { 18 namespace media {
20 class AudioBusRefCounted; 19 class AudioBusRefCounted;
21 } 20 }
22 21
23 namespace copresence { 22 namespace copresence {
24 23
25 class TickClockRefCounted; 24 class TickClockRefCounted;
26 25
27 struct AudioDirective final { 26 struct AudioDirective final {
28 // Default ctor, required by the priority queue. 27 // Default ctor, required by the priority queue.
29 AudioDirective(); 28 AudioDirective();
30 AudioDirective(const std::string& op_id, 29 AudioDirective(const std::string& op_id, base::TimeTicks end_time);
31 base::TimeTicks end_time,
32 const Directive& server_directive);
33 30
34 std::string op_id; 31 std::string op_id;
35
36 // 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
37 // where your machine suspends. See crbug.com/426136 33 // where your machine suspends. See crbug.com/426136
38 base::TimeTicks end_time; 34 base::TimeTicks end_time;
39
40 Directive server_directive;
41 }; 35 };
42 36
43 // 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
44 // samples associated with a audio transmit directives and expires directives 38 // samples associated with a audio transmit directives and expires directives
45 // that have outlived their TTL. 39 // that have outlived their TTL.
46 // TODO(rkc): Once we implement more token technologies, move reusable code 40 // TODO(rkc): Once we implement more token technologies, move reusable code
47 // from here to a base class and inherit various XxxxDirectiveList 41 // from here to a base class and inherit various XxxxDirectiveList
48 // classes from it. 42 // classes from it.
49 class AudioDirectiveList final { 43 class AudioDirectiveList {
50 public: 44 public:
51 explicit AudioDirectiveList(const scoped_refptr<TickClockRefCounted>& clock = 45 explicit AudioDirectiveList(const scoped_refptr<TickClockRefCounted>& clock =
52 make_scoped_refptr(new TickClockRefCounted(new base::DefaultTickClock))); 46 make_scoped_refptr(new TickClockRefCounted(new base::DefaultTickClock)));
53 ~AudioDirectiveList(); 47 ~AudioDirectiveList();
54 48
55 void AddDirective(const std::string& op_id, const Directive& directive); 49 void AddDirective(const std::string& op_id, base::TimeDelta ttl);
56 void RemoveDirective(const std::string& op_id); 50 void RemoveDirective(const std::string& op_id);
57 51
58 scoped_ptr<AudioDirective> GetActiveDirective(); 52 scoped_ptr<AudioDirective> GetActiveDirective();
59 53
60 const std::vector<AudioDirective>& directives() const;
61
62 private: 54 private:
63 // Comparator for comparing end_times on audio tokens. 55 // Comparator for comparing end_times on audio tokens.
64 class LatestFirstComparator { 56 class LatestFirstComparator {
65 public: 57 public:
66 // 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.
67 bool operator()(const AudioDirective& left, 59 bool operator()(const AudioDirective& left,
68 const AudioDirective& right) const { 60 const AudioDirective& right) const {
69 return left.end_time < right.end_time; 61 return left.end_time < right.end_time;
70 } 62 }
71 }; 63 };
72 64
73 std::vector<AudioDirective>::iterator FindDirectiveByOpId( 65 std::vector<AudioDirective>::iterator FindDirectiveByOpId(
74 const std::string& op_id); 66 const std::string& op_id);
75 67
76 // 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
77 // element. Only currently active directives will exist in this list. 69 // element. Only currently active directives will exist in this list.
78 std::vector<AudioDirective> active_directives_; 70 std::vector<AudioDirective> active_directives_;
79 71
80 scoped_refptr<TickClockRefCounted> clock_; 72 scoped_refptr<TickClockRefCounted> clock_;
81 73
82 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveList); 74 DISALLOW_COPY_AND_ASSIGN(AudioDirectiveList);
83 }; 75 };
84 76
85 } // namespace copresence 77 } // namespace copresence
86 78
87 #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