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

Unified Diff: components/copresence/copresence_client.cc

Issue 441103002: Tests for the Copresence API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@api
Patch Set: Fixing tests for the latest API. 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 side-by-side diff with in-line comments
Download patch
Index: components/copresence/copresence_client.cc
diff --git a/components/copresence/copresence_client.cc b/components/copresence/copresence_client.cc
index 60e45e15d2156368eddf0e575f1812e6339e9dc6..bf77e449f2c184f595c1764cd572c650714f1573 100644
--- a/components/copresence/copresence_client.cc
+++ b/components/copresence/copresence_client.cc
@@ -22,9 +22,18 @@ PendingRequest::~PendingRequest() {
// Public methods
-CopresenceClient::CopresenceClient(CopresenceClientDelegate* delegate)
- : delegate_(delegate), init_failed_(false), pending_init_operations_(0) {
+CopresenceClient::CopresenceClient()
+ : delegate_(NULL),
+ init_failed_(false),
+ pending_init_operations_(0) {}
+
+CopresenceClient::~CopresenceClient() {}
+
+void CopresenceClient::Initialize(CopresenceClientDelegate* delegate) {
DVLOG(3) << "Initializing client.";
+ DCHECK(delegate);
+ delegate_ = delegate;
+
pending_init_operations_++;
rpc_handler_.reset(
new RpcHandler(delegate,
@@ -33,19 +42,19 @@ CopresenceClient::CopresenceClient(CopresenceClientDelegate* delegate)
"Copresence device registration")));
pending_init_operations_++;
- delegate_->GetWhispernetClient()->Initialize(
+ DCHECK(delegate->GetWhispernetClient());
+ delegate->GetWhispernetClient()->Initialize(
base::Bind(&CopresenceClient::InitStepComplete,
AsWeakPtr(),
"Whispernet proxy initialization"));
}
-CopresenceClient::~CopresenceClient() {
-}
-
void CopresenceClient::Shutdown() {
DVLOG(3) << "Shutting down client.";
- delegate_->GetWhispernetClient()->Shutdown();
- rpc_handler_->DisconnectFromWhispernet();
+ if (delegate_ && delegate_->GetWhispernetClient())
+ delegate_->GetWhispernetClient()->Shutdown();
+ if (rpc_handler_.get())
+ rpc_handler_->DisconnectFromWhispernet();
}
// Returns false if any operations were malformed.

Powered by Google App Engine
This is Rietveld 408576698