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

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

Issue 1151603003: Fixing race condition in AudioDirectiveHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_handler_impl.h" 5 #include "components/copresence/handlers/audio/audio_directive_handler_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 12 matching lines...) Expand all
23 using audio_modem::AUDIBLE; 23 using audio_modem::AUDIBLE;
24 using audio_modem::INAUDIBLE; 24 using audio_modem::INAUDIBLE;
25 using audio_modem::TokenParameters; 25 using audio_modem::TokenParameters;
26 26
27 namespace copresence { 27 namespace copresence {
28 28
29 namespace { 29 namespace {
30 30
31 base::TimeTicks GetEarliestEventTime(AudioDirectiveList* list, 31 base::TimeTicks GetEarliestEventTime(AudioDirectiveList* list,
32 base::TimeTicks event_time) { 32 base::TimeTicks event_time) {
33 if (!list->GetActiveDirective()) 33 scoped_ptr<AudioDirective> active_directive = list->GetActiveDirective();
34
35 if (!active_directive)
34 return event_time; 36 return event_time;
37 if (event_time.is_null())
38 return active_directive->end_time;
35 39
36 return event_time.is_null() ? 40 return std::min(active_directive->end_time, event_time);
37 list->GetActiveDirective()->end_time :
38 std::min(list->GetActiveDirective()->end_time, event_time);
39 } 41 }
40 42
41 void ConvertDirectives(const std::vector<AudioDirective>& in_directives, 43 void ConvertDirectives(const std::vector<AudioDirective>& in_directives,
42 std::vector<Directive>* out_directives) { 44 std::vector<Directive>* out_directives) {
43 for (const AudioDirective& in_directive : in_directives) 45 for (const AudioDirective& in_directive : in_directives)
44 out_directives->push_back(in_directive.server_directive); 46 out_directives->push_back(in_directive.server_directive);
45 } 47 }
46 48
47 } // namespace 49 } // namespace
48 50
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 229
228 *expiry = GetEarliestEventTime(transmits_lists_[AUDIBLE], base::TimeTicks()); 230 *expiry = GetEarliestEventTime(transmits_lists_[AUDIBLE], base::TimeTicks());
229 *expiry = GetEarliestEventTime(transmits_lists_[INAUDIBLE], *expiry); 231 *expiry = GetEarliestEventTime(transmits_lists_[INAUDIBLE], *expiry);
230 *expiry = GetEarliestEventTime(receives_lists_[AUDIBLE], *expiry); 232 *expiry = GetEarliestEventTime(receives_lists_[AUDIBLE], *expiry);
231 *expiry = GetEarliestEventTime(receives_lists_[INAUDIBLE], *expiry); 233 *expiry = GetEarliestEventTime(receives_lists_[INAUDIBLE], *expiry);
232 234
233 return !expiry->is_null(); 235 return !expiry->is_null();
234 } 236 }
235 237
236 } // namespace copresence 238 } // namespace copresence
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698