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

Unified Diff: components/copresence/copresence_manager_impl.cc

Issue 764673003: Adding CopresenceState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « components/copresence/copresence_manager_impl.h ('k') | components/copresence/copresence_state_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/copresence/copresence_manager_impl.cc
diff --git a/components/copresence/copresence_manager_impl.cc b/components/copresence/copresence_manager_impl.cc
index de6d7e29051d148be08f9d1781350c559a15238e..63ad503225d9b58221c1440ea3205eb5c0de482c 100644
--- a/components/copresence/copresence_manager_impl.cc
+++ b/components/copresence/copresence_manager_impl.cc
@@ -8,7 +8,9 @@
#include "base/bind.h"
#include "base/strings/stringprintf.h"
+#include "base/time/time.h"
#include "base/timer/timer.h"
+#include "components/copresence/copresence_state_impl.h"
#include "components/copresence/handlers/directive_handler_impl.h"
#include "components/copresence/handlers/gcm_handler_impl.h"
#include "components/copresence/proto/rpcs.pb.h"
@@ -33,7 +35,12 @@ CopresenceManagerImpl::CopresenceManagerImpl(CopresenceDelegate* delegate)
// This callback gets cancelled when we are destroyed.
base::Unretained(this))),
init_failed_(false),
- directive_handler_(new DirectiveHandlerImpl),
+ state_(new CopresenceStateImpl),
+ directive_handler_(new DirectiveHandlerImpl(
+ // The directive handler and its descendants
+ // will be destructed before the CopresenceState instance.
+ base::Bind(&CopresenceStateImpl::UpdateDirectives,
+ base::Unretained(state_.get())))),
poll_timer_(new base::RepeatingTimer<CopresenceManagerImpl>),
audio_check_timer_(new base::RepeatingTimer<CopresenceManagerImpl>) {
DCHECK(delegate_);
@@ -46,6 +53,7 @@ CopresenceManagerImpl::CopresenceManagerImpl(CopresenceDelegate* delegate)
directive_handler_.get()));
rpc_handler_.reset(new RpcHandler(delegate,
+ state_.get(),
directive_handler_.get(),
gcm_handler_.get()));
}
@@ -54,6 +62,10 @@ CopresenceManagerImpl::~CopresenceManagerImpl() {
whispernet_init_callback_.Cancel();
}
+CopresenceState* CopresenceManagerImpl::state() {
+ return state_.get();
+}
+
// Returns false if any operations were malformed.
void CopresenceManagerImpl::ExecuteReportRequest(
const ReportRequest& request,
@@ -79,11 +91,9 @@ void CopresenceManagerImpl::WhispernetInitComplete(bool success) {
if (success) {
DVLOG(3) << "Whispernet initialized successfully.";
- // We destroy |directive_handler_| before |rpc_handler_|, hence passing
- // in |rpc_handler_|'s pointer is safe here.
directive_handler_->Start(delegate_->GetWhispernetClient(),
- base::Bind(&RpcHandler::ReportTokens,
- base::Unretained(rpc_handler_.get())));
+ base::Bind(&CopresenceManagerImpl::ReceivedTokens,
+ base::Unretained(this)));
// Start up timers.
poll_timer_->Start(FROM_HERE,
@@ -99,6 +109,21 @@ void CopresenceManagerImpl::WhispernetInitComplete(bool success) {
}
}
+void CopresenceManagerImpl::ReceivedTokens(
+ const std::vector<AudioToken>& tokens) {
+ rpc_handler_->ReportTokens(tokens);
+
+ // Update the CopresenceState.
+ for (const AudioToken audio_token : tokens) {
+ DVLOG(3) << "Heard token: " << audio_token.token;
+ ReceivedToken token(
+ audio_token.token,
+ audio_token.audible ? AUDIO_AUDIBLE_DTMF : AUDIO_ULTRASOUND_PASSBAND,
+ base::Time::Now());
+ state_->UpdateReceivedToken(token);
+ }
+}
+
void CopresenceManagerImpl::PollForMessages() {
// Report our currently playing tokens.
const std::string& audible_token =
« no previous file with comments | « components/copresence/copresence_manager_impl.h ('k') | components/copresence/copresence_state_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698