Index: components/copresence/copresence_client.cc |
diff --git a/components/copresence/copresence_client.cc b/components/copresence/copresence_client.cc |
index 60e45e15d2156368eddf0e575f1812e6339e9dc6..aee95e3149414e8ef5c770ced34c345262dace15 100644 |
--- a/components/copresence/copresence_client.cc |
+++ b/components/copresence/copresence_client.cc |
@@ -22,42 +22,27 @@ PendingRequest::~PendingRequest() { |
// Public methods |
-CopresenceClient::CopresenceClient(CopresenceClientDelegate* delegate) |
- : delegate_(delegate), init_failed_(false), pending_init_operations_(0) { |
- DVLOG(3) << "Initializing client."; |
- pending_init_operations_++; |
- rpc_handler_.reset( |
- new RpcHandler(delegate, |
- base::Bind(&CopresenceClient::InitStepComplete, |
- AsWeakPtr(), |
- "Copresence device registration"))); |
- |
- pending_init_operations_++; |
- delegate_->GetWhispernetClient()->Initialize( |
- base::Bind(&CopresenceClient::InitStepComplete, |
- AsWeakPtr(), |
- "Whispernet proxy initialization")); |
-} |
- |
-CopresenceClient::~CopresenceClient() { |
-} |
+CopresenceClient::~CopresenceClient() {} |
void CopresenceClient::Shutdown() { |
DVLOG(3) << "Shutting down client."; |
- delegate_->GetWhispernetClient()->Shutdown(); |
- rpc_handler_->DisconnectFromWhispernet(); |
+ if (delegate_ && delegate_->GetWhispernetClient()) |
not at google - send to devlin
2014/08/07 23:21:12
when would there not be a delegate? could you pass
Charlie
2014/08/07 23:52:25
I guess we only have the use case where there's no
rkc
2014/08/08 00:05:35
We should rebase this code and have it tracked of
Charlie
2014/08/08 18:25:50
Done.
|
+ delegate_->GetWhispernetClient()->Shutdown(); |
+ if (rpc_handler_.get()) |
not at google - send to devlin
2014/08/07 23:21:13
likewise.
Charlie
2014/08/07 23:52:25
MockCopresenceClient won't have an rpc_handler_.
not at google - send to devlin
2014/08/07 23:54:24
this inheritance structure is confusing. inheritan
rkc
2014/08/08 00:37:00
Deriving a Mock class from a concrete class is a v
not at google - send to devlin
2014/08/08 13:48:35
git gs "Mock.*: public.*" | wc -l = 1115
what doe
Charlie
2014/08/08 18:25:50
IIUC the change to the production code that we're
not at google - send to devlin
2014/08/08 19:42:04
Thanks.
I think you're right that CopresenceClien
Charlie
2014/08/13 19:13:15
Done.
|
+ rpc_handler_->DisconnectFromWhispernet(); |
} |
// Returns false if any operations were malformed. |
void CopresenceClient::ExecuteReportRequest(copresence::ReportRequest request, |
const std::string& app_id, |
const StatusCallback& callback) { |
- // Don't take on any more requests, we can't execute any, init failed. |
+ // Don't take on any more requests. We can't execute them since init failed. |
if (init_failed_) { |
callback.Run(FAIL); |
return; |
} |
+ DCHECK(rpc_handler_.get()); |
if (pending_init_operations_) { |
pending_requests_queue_.push_back( |
PendingRequest(request, app_id, callback)); |
@@ -69,12 +54,46 @@ void CopresenceClient::ExecuteReportRequest(copresence::ReportRequest request, |
} |
} |
+// static |
+scoped_ptr<CopresenceClient> CopresenceClient::Create( |
+ CopresenceClientDelegate* delegate) { |
+ DVLOG(3) << "Initializing client."; |
+ scoped_ptr<CopresenceClient> client(new CopresenceClient); |
+ DCHECK(delegate); |
+ client->delegate_ = delegate; |
+ |
+ client->pending_init_operations_++; |
not at google - send to devlin
2014/08/07 23:21:12
should be ++x not x++
Charlie
2014/08/07 23:52:25
Either is allowed for scalar types. With the -> sy
rkc
2014/08/08 00:37:00
prefixed is still better for consistency.
|
+ client->rpc_handler_.reset( |
+ new RpcHandler(delegate, |
+ base::Bind(&CopresenceClient::InitStepComplete, |
+ client->AsWeakPtr(), |
+ "Copresence device registration"))); |
+ |
+ client->pending_init_operations_++; |
+ DCHECK(delegate->GetWhispernetClient()); |
+ delegate->GetWhispernetClient()->Initialize( |
+ base::Bind(&CopresenceClient::InitStepComplete, |
+ client->AsWeakPtr(), |
+ "Whispernet proxy initialization")); |
+ |
+ return client.Pass(); |
+} |
+ |
+// Protected methods |
+ |
+CopresenceClient::CopresenceClient() |
+ : delegate_(NULL), |
+ init_failed_(false), |
+ pending_init_operations_(0) {} |
+ |
// Private methods |
void CopresenceClient::CompleteInitialization() { |
if (pending_init_operations_) |
return; |
+ DCHECK(delegate_); |
+ DCHECK(rpc_handler_.get()); |
if (!init_failed_) |
rpc_handler_->ConnectToWhispernet(delegate_->GetWhispernetClient()); |