OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/copresence/public/copresence_manager.h" | 5 #include "components/copresence/public/copresence_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "components/copresence/copresence_manager_impl.h" | 8 #include "components/copresence/copresence_manager_impl.h" |
9 #include "components/copresence/rpc/rpc_handler.h" | 9 #include "components/copresence/rpc/rpc_handler.h" |
10 | 10 |
11 namespace copresence { | 11 namespace copresence { |
12 | 12 |
13 // static | 13 // static |
14 scoped_ptr<CopresenceManager> CopresenceManager::Create( | 14 scoped_ptr<CopresenceManager> CopresenceManager::Create( |
15 CopresenceDelegate* delegate) { | 15 CopresenceDelegate* delegate) { |
16 CopresenceManagerImpl* manager = new CopresenceManagerImpl(delegate); | 16 CopresenceManagerImpl* manager = new CopresenceManagerImpl(delegate); |
17 | 17 |
18 manager->pending_init_operations_++; | 18 manager->pending_init_operations_++; |
19 manager->rpc_handler_.reset(new RpcHandler(delegate)); | 19 manager->rpc_handler_.reset(new RpcHandler(delegate)); |
20 manager->rpc_handler_->Initialize( | 20 manager->rpc_handler_->Initialize( |
21 base::Bind(&CopresenceManagerImpl::InitStepComplete, | 21 base::Bind(&CopresenceManagerImpl::InitStepComplete, |
22 // This is safe because the manager owns the RpcHandler. | 22 // This is safe because the manager owns the RpcHandler. |
23 base::Unretained(manager), | 23 base::Unretained(manager), |
24 "Copresence device registration")); | 24 "Copresence device registration")); |
25 | 25 |
26 // This callback will be canceled on manager's destruction, hence unretained | |
27 // is safe to use here. | |
28 manager->init_callback_.Reset( | |
Daniel Erat
2014/08/28 21:32:41
i'm missing some background here, but what's the r
rkc
2014/08/28 21:51:50
This was written by Charlie while I was OOO. I am
Charlie
2014/10/17 22:18:10
This was in response to kalman@'s suggestion:
htt
| |
29 base::Bind(&CopresenceManagerImpl::InitStepComplete, | |
30 base::Unretained(manager), | |
31 "Whispernet proxy initialization")); | |
32 | |
26 manager->pending_init_operations_++; | 33 manager->pending_init_operations_++; |
27 DCHECK(delegate->GetWhispernetClient()); | 34 DCHECK(delegate->GetWhispernetClient()); |
28 delegate->GetWhispernetClient()->Initialize( | 35 delegate->GetWhispernetClient()->Initialize( |
29 base::Bind(&CopresenceManagerImpl::InitStepComplete, | 36 manager->init_callback_.callback()); |
30 // We cannot cancel WhispernetClient initialization. | |
31 // TODO(ckehoe): Get rid of this. | |
32 manager->AsWeakPtr(), | |
33 "Whispernet proxy initialization")); | |
34 | 37 |
35 return make_scoped_ptr<CopresenceManager>(manager); | 38 return make_scoped_ptr<CopresenceManager>(manager); |
36 } | 39 } |
37 | 40 |
38 } // namespace copresence | 41 } // namespace copresence |
39 | 42 |
OLD | NEW |