summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorrkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-12 01:58:51 +0000
committerrkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-12 02:00:25 +0000
commitb9c27ea842c62c6995fb8b58f9936f048897e32c (patch)
tree33f7612869af7f60db1195782092ce8f173d8280 /components
parentcfa9b0a9a0155922c26d5f183a5300abfd06ab82 (diff)
downloadchromium_src-b9c27ea842c62c6995fb8b58f9936f048897e32c.zip
chromium_src-b9c27ea842c62c6995fb8b58f9936f048897e32c.tar.gz
chromium_src-b9c27ea842c62c6995fb8b58f9936f048897e32c.tar.bz2
Improve audible token detection.
The current code doesn't differentiate between tokens decoded by the DSSS (inaudible) or DTMF (audible) encoder/decoder. Fix this and send up the correct medium to the server. R=kalman@chromium.org, xiyuan@chromium.org BUG=402334 Review URL: https://codereview.chromium.org/460743004 Cr-Commit-Position: refs/heads/master@{#288872} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288872 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r--components/copresence/handlers/audio/audio_directive_handler_unittest.cc5
-rw-r--r--components/copresence/handlers/audio/audio_directive_list.cc1
-rw-r--r--components/copresence/handlers/audio/audio_directive_list.h6
-rw-r--r--components/copresence/handlers/audio/audio_directive_list_unittest.cc5
-rw-r--r--components/copresence/public/whispernet_client.h14
-rw-r--r--components/copresence/rpc/rpc_handler.cc12
-rw-r--r--components/copresence/rpc/rpc_handler.h2
-rw-r--r--components/copresence/rpc/rpc_handler_unittest.cc10
8 files changed, 33 insertions, 22 deletions
diff --git a/components/copresence/handlers/audio/audio_directive_handler_unittest.cc b/components/copresence/handlers/audio/audio_directive_handler_unittest.cc
index 5332252..4faa697 100644
--- a/components/copresence/handlers/audio/audio_directive_handler_unittest.cc
+++ b/components/copresence/handlers/audio/audio_directive_handler_unittest.cc
@@ -47,9 +47,10 @@ class AudioDirectiveHandlerTest : public testing::Test {
protected:
void EncodeToken(const std::string& token,
- bool /* audible */,
+ bool audible,
const AudioDirectiveList::SamplesCallback& callback) {
- callback.Run(token, CreateRandomAudioRefCounted(0x1337, 1, 0x7331));
+ callback.Run(
+ token, audible, CreateRandomAudioRefCounted(0x1337, 1, 0x7331));
}
copresence::TokenInstruction CreateTransmitInstruction(
diff --git a/components/copresence/handlers/audio/audio_directive_list.cc b/components/copresence/handlers/audio/audio_directive_list.cc
index db4b684..f6403f6 100644
--- a/components/copresence/handlers/audio/audio_directive_list.cc
+++ b/components/copresence/handlers/audio/audio_directive_list.cc
@@ -125,6 +125,7 @@ scoped_ptr<AudioDirective> AudioDirectiveList::GetNextFromList(
void AudioDirectiveList::OnTokenEncoded(
const std::string& token,
+ bool /* audible */,
const scoped_refptr<media::AudioBusRefCounted>& samples) {
// We shouldn't re-encode a token if it's already in the cache.
DCHECK(!samples_cache_.HasKey(token));
diff --git a/components/copresence/handlers/audio/audio_directive_list.h b/components/copresence/handlers/audio/audio_directive_list.h
index b94dec7..d97a549 100644
--- a/components/copresence/handlers/audio/audio_directive_list.h
+++ b/components/copresence/handlers/audio/audio_directive_list.h
@@ -52,8 +52,9 @@ struct AudioDirective {
// classes from it.
class AudioDirectiveList {
public:
- typedef base::Callback<
- void(const std::string&, const scoped_refptr<media::AudioBusRefCounted>&)>
+ typedef base::Callback<void(const std::string&,
+ bool,
+ const scoped_refptr<media::AudioBusRefCounted>&)>
SamplesCallback;
typedef base::Callback<void(const std::string&, bool, const SamplesCallback&)>
EncodeTokenCallback;
@@ -78,6 +79,7 @@ class AudioDirectiveList {
// This is the method that the whispernet client needs to call to return
// samples to us.
void OnTokenEncoded(const std::string& token,
+ bool audible,
const scoped_refptr<media::AudioBusRefCounted>& samples);
private:
diff --git a/components/copresence/handlers/audio/audio_directive_list_unittest.cc b/components/copresence/handlers/audio/audio_directive_list_unittest.cc
index 78d2985..f746b0d 100644
--- a/components/copresence/handlers/audio/audio_directive_list_unittest.cc
+++ b/components/copresence/handlers/audio/audio_directive_list_unittest.cc
@@ -26,9 +26,10 @@ class AudioDirectiveListTest : public testing::Test {
protected:
void EncodeToken(const std::string& token,
- bool /* audible */,
+ bool audible,
const AudioDirectiveList::SamplesCallback& callback) {
- callback.Run(token, CreateRandomAudioRefCounted(0x1337, 1, 0x7331));
+ callback.Run(
+ token, audible, CreateRandomAudioRefCounted(0x1337, 1, 0x7331));
}
base::MessageLoop message_loop_;
diff --git a/components/copresence/public/whispernet_client.h b/components/copresence/public/whispernet_client.h
index 6926fff..e800d85 100644
--- a/components/copresence/public/whispernet_client.h
+++ b/components/copresence/public/whispernet_client.h
@@ -18,6 +18,13 @@ class AudioBusRefCounted;
namespace copresence {
+struct FullToken {
+ FullToken(const std::string& token, bool audible)
+ : token(token), audible(audible) {}
+ std::string token;
+ bool audible;
+};
+
// The interface that the whispernet client needs to implement. These methods
// provide us the ability to use the audio medium in copresence. Currently since
// the only medium that copresence uses is audio, the implementation of this
@@ -27,10 +34,11 @@ class WhispernetClient {
// Generic callback to indicate a boolean success or failure.
typedef base::Callback<void(bool)> SuccessCallback;
// Callback that returns detected tokens.
- typedef base::Callback<void(const std::vector<std::string>&)> TokensCallback;
+ typedef base::Callback<void(const std::vector<FullToken>&)> TokensCallback;
// Callback that returns encoded samples for a given token.
- typedef base::Callback<
- void(const std::string&, const scoped_refptr<media::AudioBusRefCounted>&)>
+ typedef base::Callback<void(const std::string&,
+ bool,
+ const scoped_refptr<media::AudioBusRefCounted>&)>
SamplesCallback;
// Initialize the whispernet client and call the callback when done. The
diff --git a/components/copresence/rpc/rpc_handler.cc b/components/copresence/rpc/rpc_handler.cc
index c6c3d3c..2ca127e 100644
--- a/components/copresence/rpc/rpc_handler.cc
+++ b/components/copresence/rpc/rpc_handler.cc
@@ -262,14 +262,12 @@ void RpcHandler::SendReportRequest(scoped_ptr<ReportRequest> request,
status_callback));
}
-void RpcHandler::ReportTokens(TokenMedium medium,
- const std::vector<std::string>& tokens) {
- DCHECK_EQ(medium, AUDIO_ULTRASOUND_PASSBAND);
+void RpcHandler::ReportTokens(const std::vector<FullToken>& tokens) {
DCHECK(!tokens.empty());
scoped_ptr<ReportRequest> request(new ReportRequest);
for (size_t i = 0; i < tokens.size(); ++i) {
- const std::string& token = ToUrlSafe(tokens[i]);
+ const std::string& token = ToUrlSafe(tokens[i].token);
if (invalid_audio_token_cache_.HasKey(token))
continue;
@@ -280,7 +278,8 @@ void RpcHandler::ReportTokens(TokenMedium medium,
token_observation->set_token_id(token);
TokenSignals* signals = token_observation->add_signals();
- signals->set_medium(medium);
+ signals->set_medium(tokens[i].audible ? AUDIO_AUDIBLE_DTMF
+ : AUDIO_ULTRASOUND_PASSBAND);
signals->set_observed_time_millis(base::Time::Now().ToJsTime());
}
SendReportRequest(request.Pass());
@@ -300,8 +299,7 @@ void RpcHandler::ConnectToWhispernet() {
whispernet_client->RegisterTokensCallback(
base::Bind(&RpcHandler::ReportTokens,
// On destruction, this callback will be disconnected.
- base::Unretained(this),
- AUDIO_ULTRASOUND_PASSBAND));
+ base::Unretained(this)));
}
// Private methods
diff --git a/components/copresence/rpc/rpc_handler.h b/components/copresence/rpc/rpc_handler.h
index 2233f9a..82840d8 100644
--- a/components/copresence/rpc/rpc_handler.h
+++ b/components/copresence/rpc/rpc_handler.h
@@ -50,7 +50,7 @@ class RpcHandler {
const StatusCallback& callback);
// Report a set of tokens to the server for a given medium.
- void ReportTokens(TokenMedium medium, const std::vector<std::string>& tokens);
+ void ReportTokens(const std::vector<FullToken>& tokens);
// Create the directive handler and connect it to
// the whispernet client specified by the delegate.
diff --git a/components/copresence/rpc/rpc_handler_unittest.cc b/components/copresence/rpc/rpc_handler_unittest.cc
index f6c9359..b7907907 100644
--- a/components/copresence/rpc/rpc_handler_unittest.cc
+++ b/components/copresence/rpc/rpc_handler_unittest.cc
@@ -266,13 +266,13 @@ TEST_F(RpcHandlerTest, MAYBE_CreateRequestHeader) {
#define MAYBE_ReportTokens DISABLED_ReportTokens
TEST_F(RpcHandlerTest, MAYBE_ReportTokens) {
- std::vector<std::string> test_tokens;
- test_tokens.push_back("token 1");
- test_tokens.push_back("token 2");
- test_tokens.push_back("token 3");
+ std::vector<FullToken> test_tokens;
+ test_tokens.push_back(FullToken("token 1", false));
+ test_tokens.push_back(FullToken("token 2", true));
+ test_tokens.push_back(FullToken("token 3", false));
AddInvalidToken("token 2");
- rpc_handler_.ReportTokens(AUDIO_ULTRASOUND_PASSBAND, test_tokens);
+ rpc_handler_.ReportTokens(test_tokens);
EXPECT_EQ(RpcHandler::kReportRequestRpcName, rpc_name_);
ReportRequest* report = static_cast<ReportRequest*>(request_proto_.get());
google::protobuf::RepeatedPtrField<TokenObservation> tokens_sent =