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

Side by Side Diff: chrome/browser/extensions/api/copresence_private/copresence_private_api.cc

Issue 460743004: Improve audible token detection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
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 "chrome/browser/extensions/api/copresence_private/copresence_private_ap i.h" 5 #include "chrome/browser/extensions/api/copresence_private/copresence_private_ap i.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "chrome/browser/copresence/chrome_whispernet_client.h" 9 #include "chrome/browser/copresence/chrome_whispernet_client.h"
10 #include "chrome/browser/extensions/api/copresence/copresence_api.h" 10 #include "chrome/browser/extensions/api/copresence/copresence_api.h"
(...skipping 14 matching lines...) Expand all
25 // CopresenceSendFoundFunction implementation: 25 // CopresenceSendFoundFunction implementation:
26 ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() { 26 ExtensionFunction::ResponseAction CopresencePrivateSendFoundFunction::Run() {
27 if (!GetWhispernetClient() || 27 if (!GetWhispernetClient() ||
28 GetWhispernetClient()->GetTokensCallback().is_null()) { 28 GetWhispernetClient()->GetTokensCallback().is_null()) {
29 return RespondNow(NoArguments()); 29 return RespondNow(NoArguments());
30 } 30 }
31 31
32 scoped_ptr<api::copresence_private::SendFound::Params> params( 32 scoped_ptr<api::copresence_private::SendFound::Params> params(
33 api::copresence_private::SendFound::Params::Create(*args_)); 33 api::copresence_private::SendFound::Params::Create(*args_));
34 EXTENSION_FUNCTION_VALIDATE(params.get()); 34 EXTENSION_FUNCTION_VALIDATE(params.get());
35 GetWhispernetClient()->GetTokensCallback().Run(params->tokens); 35 std::vector<copresence::FullToken> tokens;
36 for (size_t i = 0; i < params->tokens.size(); ++i) {
37 tokens.push_back(copresence::FullToken(params->tokens[i]->token,
38 params->tokens[i]->audible));
39 }
40 GetWhispernetClient()->GetTokensCallback().Run(tokens);
36 return RespondNow(NoArguments()); 41 return RespondNow(NoArguments());
37 } 42 }
38 43
39 // CopresenceSendEncodedFunction implementation: 44 // CopresenceSendEncodedFunction implementation:
40 ExtensionFunction::ResponseAction CopresencePrivateSendSamplesFunction::Run() { 45 ExtensionFunction::ResponseAction CopresencePrivateSendSamplesFunction::Run() {
41 if (!GetWhispernetClient() || 46 if (!GetWhispernetClient() ||
42 GetWhispernetClient()->GetSamplesCallback().is_null()) { 47 GetWhispernetClient()->GetSamplesCallback().is_null()) {
43 return RespondNow(NoArguments()); 48 return RespondNow(NoArguments());
44 } 49 }
45 50
46 scoped_ptr<api::copresence_private::SendSamples::Params> params( 51 scoped_ptr<api::copresence_private::SendSamples::Params> params(
47 api::copresence_private::SendSamples::Params::Create(*args_)); 52 api::copresence_private::SendSamples::Params::Create(*args_));
48 EXTENSION_FUNCTION_VALIDATE(params.get()); 53 EXTENSION_FUNCTION_VALIDATE(params.get());
49 54
50 scoped_refptr<media::AudioBusRefCounted> samples = 55 scoped_refptr<media::AudioBusRefCounted> samples =
51 media::AudioBusRefCounted::Create(1, 56 media::AudioBusRefCounted::Create(1,
52 params->samples.size() / sizeof(float)); 57 params->samples.size() / sizeof(float));
53 58
54 memcpy(samples->channel(0), 59 memcpy(samples->channel(0),
55 string_as_array(&params->samples), 60 string_as_array(&params->samples),
56 params->samples.size()); 61 params->samples.size());
57 62
58 GetWhispernetClient()->GetSamplesCallback().Run(params->token, samples); 63 GetWhispernetClient()->GetSamplesCallback().Run(
64 params->token.token, params->token.audible, samples);
59 return RespondNow(NoArguments()); 65 return RespondNow(NoArguments());
60 } 66 }
61 67
62 // CopresenceSendDetectFunction implementation: 68 // CopresenceSendDetectFunction implementation:
63 ExtensionFunction::ResponseAction CopresencePrivateSendDetectFunction::Run() { 69 ExtensionFunction::ResponseAction CopresencePrivateSendDetectFunction::Run() {
64 if (!GetWhispernetClient() || 70 if (!GetWhispernetClient() ||
65 GetWhispernetClient()->GetDetectBroadcastCallback().is_null()) { 71 GetWhispernetClient()->GetDetectBroadcastCallback().is_null()) {
66 return RespondNow(NoArguments()); 72 return RespondNow(NoArguments());
67 } 73 }
68 74
(...skipping 15 matching lines...) Expand all
84 90
85 scoped_ptr<api::copresence_private::SendInitialized::Params> params( 91 scoped_ptr<api::copresence_private::SendInitialized::Params> params(
86 api::copresence_private::SendInitialized::Params::Create(*args_)); 92 api::copresence_private::SendInitialized::Params::Create(*args_));
87 EXTENSION_FUNCTION_VALIDATE(params.get()); 93 EXTENSION_FUNCTION_VALIDATE(params.get());
88 94
89 GetWhispernetClient()->GetInitializedCallback().Run(params->success); 95 GetWhispernetClient()->GetInitializedCallback().Run(params->success);
90 return RespondNow(NoArguments()); 96 return RespondNow(NoArguments());
91 } 97 }
92 98
93 } // namespace extensions 99 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698