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
3 // found in the LICENSE file.
5 #include "components/copresence/public/copresence_manager.h"
8 #include "components/copresence/copresence_manager_impl.h"
9 #include "components/copresence/rpc/rpc_handler.h"
11 namespace copresence
{
14 scoped_ptr
<CopresenceManager
> CopresenceManager::Create(
15 CopresenceDelegate
* delegate
) {
16 CopresenceManagerImpl
* manager
= new CopresenceManagerImpl(delegate
);
18 manager
->pending_init_operations_
++;
19 manager
->rpc_handler_
.reset(new RpcHandler(delegate
));
20 manager
->rpc_handler_
->Initialize(
21 base::Bind(&CopresenceManagerImpl::InitStepComplete
,
22 // This is safe because the manager owns the RpcHandler.
23 base::Unretained(manager
),
24 "Copresence device registration"));
26 // This callback will be canceled on manager's destruction, hence unretained
27 // is safe to use here.
28 manager
->init_callback_
.Reset(
29 base::Bind(&CopresenceManagerImpl::InitStepComplete
,
30 base::Unretained(manager
),
31 "Whispernet proxy initialization"));
33 manager
->pending_init_operations_
++;
34 DCHECK(delegate
->GetWhispernetClient());
35 delegate
->GetWhispernetClient()->Initialize(
36 manager
->init_callback_
.callback());
38 return make_scoped_ptr
<CopresenceManager
>(manager
);
41 } // namespace copresence