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

Unified Diff: components/copresence/handlers/audio/audio_directive_list.cc

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 side-by-side diff with in-line comments
Download patch
Index: components/copresence/handlers/audio/audio_directive_list.cc
diff --git a/components/copresence/handlers/audio/audio_directive_list.cc b/components/copresence/handlers/audio/audio_directive_list.cc
index 5434c60b4ea0185df238cda87d4bc94cfdc15e0a..a12cbc27124535d4911bfdad2b2b0567eec9058f 100644
--- a/components/copresence/handlers/audio/audio_directive_list.cc
+++ b/components/copresence/handlers/audio/audio_directive_list.cc
@@ -4,40 +4,28 @@
#include "components/copresence/handlers/audio/audio_directive_list.h"
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/time/default_tick_clock.h"
-#include "base/time/time.h"
-#include "components/copresence/handlers/audio/tick_clock_ref_counted.h"
-
namespace copresence {
-// Public methods.
+// Public functions.
-AudioDirective::AudioDirective() {
-}
+AudioDirective::AudioDirective() {}
AudioDirective::AudioDirective(const std::string& op_id,
base::TimeTicks end_time)
- : op_id(op_id), end_time(end_time) {
-}
+ : op_id(op_id), end_time(end_time) {}
-AudioDirectiveList::AudioDirectiveList()
- : clock_(new TickClockRefCounted(
- make_scoped_ptr(new base::DefaultTickClock))) {
-}
+AudioDirectiveList::AudioDirectiveList(
+ const scoped_refptr<TickClockRefCounted>& clock)
+ : clock_(clock) {}
-AudioDirectiveList::~AudioDirectiveList() {
-}
+AudioDirectiveList::~AudioDirectiveList() {}
void AudioDirectiveList::AddDirective(const std::string& op_id,
base::TimeDelta ttl) {
base::TimeTicks end_time = clock_->NowTicks() + ttl;
- // In case this op is already in the list, update it instead of adding
- // it again.
- std::vector<AudioDirective>::iterator it = FindDirectiveByOpId(op_id);
+ // If this op is already in the list, update it instead of adding it again.
+ auto it = FindDirectiveByOpId(op_id);
if (it != active_directives_.end()) {
it->end_time = end_time;
std::make_heap(active_directives_.begin(),
@@ -53,7 +41,7 @@ void AudioDirectiveList::AddDirective(const std::string& op_id,
}
void AudioDirectiveList::RemoveDirective(const std::string& op_id) {
- std::vector<AudioDirective>::iterator it = FindDirectiveByOpId(op_id);
+ auto it = FindDirectiveByOpId(op_id);
if (it != active_directives_.end())
active_directives_.erase(it);
@@ -63,30 +51,24 @@ void AudioDirectiveList::RemoveDirective(const std::string& op_id) {
}
scoped_ptr<AudioDirective> AudioDirectiveList::GetActiveDirective() {
- // The top is always the instruction that is ending the latest. If that time
- // has passed, means all our previous instructions have expired too, hence
- // clear the list.
- if (!active_directives_.empty() &&
+ // The top is always the instruction that is ending the latest.
+ // If that time has passed, all our previous instructions have expired too.
+ // So we clear the list.
+ if (active_directives_.empty() ||
active_directives_.front().end_time < clock_->NowTicks()) {
active_directives_.clear();
- }
-
- if (active_directives_.empty())
return scoped_ptr<AudioDirective>().Pass();
+ }
return make_scoped_ptr(new AudioDirective(active_directives_.front()));
}
-void AudioDirectiveList::set_clock_for_testing(
- const scoped_refptr<TickClockRefCounted>& clock) {
- clock_ = clock;
-}
-// Private methods.
+// Private functions.
std::vector<AudioDirective>::iterator AudioDirectiveList::FindDirectiveByOpId(
const std::string& op_id) {
- for (std::vector<AudioDirective>::iterator it = active_directives_.begin();
+ for (auto it = active_directives_.begin();
it != active_directives_.end();
++it) {
if (it->op_id == op_id)

Powered by Google App Engine
This is Rietveld 408576698