Commit 0e07df1b authored by rkc's avatar rkc Committed by Commit bot

Remove weak_ptr from CopresenceManager.

The WhispernetClient object provided by the CopresenceDelegate passed to the
CopresenceManager has a lifetime exceeding that of the CopresenceManager. We
explicitly want to decouple their lifetimes since we may have lifetime
restrictions imposed on WhispernetClient which may require it to outlive the
CopresenceManager. For this reason, when passing a callback to the
WhispernetClient from CopresenceManager, we were using a WeakPtr. This is
unnecessary since the same can be accomplished by passing a CancelableCallback
to the WhispernetClient and Canceling the callback in the CopresenceManager
destructor.

R=derat@chromium.org, willchan@chromium.org
BUG=None.

Review URL: https://codereview.chromium.org/517753002

Cr-Commit-Position: refs/heads/master@{#292772}
parent 34ab8858
...@@ -23,14 +23,17 @@ scoped_ptr<CopresenceManager> CopresenceManager::Create( ...@@ -23,14 +23,17 @@ scoped_ptr<CopresenceManager> CopresenceManager::Create(
base::Unretained(manager), base::Unretained(manager),
"Copresence device registration")); "Copresence device registration"));
// This callback will be canceled on manager's destruction, hence unretained
// is safe to use here.
manager->init_callback_.Reset(
base::Bind(&CopresenceManagerImpl::InitStepComplete,
base::Unretained(manager),
"Whispernet proxy initialization"));
manager->pending_init_operations_++; manager->pending_init_operations_++;
DCHECK(delegate->GetWhispernetClient()); DCHECK(delegate->GetWhispernetClient());
delegate->GetWhispernetClient()->Initialize( delegate->GetWhispernetClient()->Initialize(
base::Bind(&CopresenceManagerImpl::InitStepComplete, manager->init_callback_.callback());
// We cannot cancel WhispernetClient initialization.
// TODO(ckehoe): Get rid of this.
manager->AsWeakPtr(),
"Whispernet proxy initialization"));
return make_scoped_ptr<CopresenceManager>(manager); return make_scoped_ptr<CopresenceManager>(manager);
} }
......
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
#include <vector> #include <vector>
#include "base/callback.h" #include "base/callback.h"
#include "base/cancelable_callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "components/copresence/proto/rpcs.pb.h" #include "components/copresence/proto/rpcs.pb.h"
#include "components/copresence/public/copresence_manager.h" #include "components/copresence/public/copresence_manager.h"
...@@ -35,8 +35,7 @@ struct PendingRequest { ...@@ -35,8 +35,7 @@ struct PendingRequest {
}; };
// The implementation for CopresenceManager. // The implementation for CopresenceManager.
class CopresenceManagerImpl : public CopresenceManager, class CopresenceManagerImpl : public CopresenceManager {
public base::SupportsWeakPtr<CopresenceManagerImpl> {
public: public:
virtual ~CopresenceManagerImpl(); virtual ~CopresenceManagerImpl();
virtual void ExecuteReportRequest(ReportRequest request, virtual void ExecuteReportRequest(ReportRequest request,
...@@ -54,6 +53,8 @@ class CopresenceManagerImpl : public CopresenceManager, ...@@ -54,6 +53,8 @@ class CopresenceManagerImpl : public CopresenceManager,
bool init_failed_; bool init_failed_;
std::vector<PendingRequest> pending_requests_queue_; std::vector<PendingRequest> pending_requests_queue_;
base::CancelableCallback<void(bool)> init_callback_;
// TODO(rkc): This code is almost identical to what we use in feedback to // TODO(rkc): This code is almost identical to what we use in feedback to
// perform multiple blocking tasks and then run a post process method. Look // perform multiple blocking tasks and then run a post process method. Look
// into refactoring it all out to a common construct, like maybe a // into refactoring it all out to a common construct, like maybe a
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment