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

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

Issue 665353002: Add AudioDirectiveHandler timed tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@audio_redesign
Patch Set: build fix. 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 #include "components/copresence/handlers/audio/audio_directive_list.h" 5 #include "components/copresence/handlers/audio/audio_directive_list.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/default_tick_clock.h" 10 #include "base/time/default_tick_clock.h"
11 #include "base/time/tick_clock.h"
12 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "components/copresence/handlers/audio/tick_clock_ref_counted.h"
13 13
14 namespace copresence { 14 namespace copresence {
15 15
16 // Public methods. 16 // Public methods.
17 17
18 AudioDirective::AudioDirective() { 18 AudioDirective::AudioDirective() {
19 } 19 }
20 20
21 AudioDirective::AudioDirective(const std::string& op_id, 21 AudioDirective::AudioDirective(const std::string& op_id,
22 base::TimeTicks end_time) 22 base::TimeTicks end_time)
23 : op_id(op_id), end_time(end_time) { 23 : op_id(op_id), end_time(end_time) {
24 } 24 }
25 25
26 AudioDirectiveList::AudioDirectiveList() : clock_(new base::DefaultTickClock) { 26 AudioDirectiveList::AudioDirectiveList()
27 : clock_(new TickClockRefCounted(
28 make_scoped_ptr(new base::DefaultTickClock))) {
27 } 29 }
28 30
29 AudioDirectiveList::~AudioDirectiveList() { 31 AudioDirectiveList::~AudioDirectiveList() {
30 } 32 }
31 33
32 void AudioDirectiveList::AddDirective(const std::string& op_id, 34 void AudioDirectiveList::AddDirective(const std::string& op_id,
33 base::TimeDelta ttl) { 35 base::TimeDelta ttl) {
34 base::TimeTicks end_time = clock_->NowTicks() + ttl; 36 base::TimeTicks end_time = clock_->NowTicks() + ttl;
35 37
36 // In case this op is already in the list, update it instead of adding 38 // In case this op is already in the list, update it instead of adding
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 active_directives_.front().end_time < clock_->NowTicks()) { 70 active_directives_.front().end_time < clock_->NowTicks()) {
69 active_directives_.clear(); 71 active_directives_.clear();
70 } 72 }
71 73
72 if (active_directives_.empty()) 74 if (active_directives_.empty())
73 return make_scoped_ptr<AudioDirective>(NULL); 75 return make_scoped_ptr<AudioDirective>(NULL);
74 76
75 return make_scoped_ptr(new AudioDirective(active_directives_.front())); 77 return make_scoped_ptr(new AudioDirective(active_directives_.front()));
76 } 78 }
77 79
80 void AudioDirectiveList::set_clock_for_testing(
81 const scoped_refptr<TickClockRefCounted>& clock) {
82 clock_ = clock;
83 }
84
85 // Private methods.
86
78 std::vector<AudioDirective>::iterator AudioDirectiveList::FindDirectiveByOpId( 87 std::vector<AudioDirective>::iterator AudioDirectiveList::FindDirectiveByOpId(
79 const std::string& op_id) { 88 const std::string& op_id) {
80 for (std::vector<AudioDirective>::iterator it = active_directives_.begin(); 89 for (std::vector<AudioDirective>::iterator it = active_directives_.begin();
81 it != active_directives_.end(); 90 it != active_directives_.end();
82 ++it) { 91 ++it) {
83 if (it->op_id == op_id) 92 if (it->op_id == op_id)
84 return it; 93 return it;
85 } 94 }
86 return active_directives_.end(); 95 return active_directives_.end();
87 } 96 }
88 97
89 } // namespace copresence 98 } // namespace copresence
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698