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/copresence_manager_impl.h"
8 #include "components/copresence/public/copresence_delegate.h"
9 #include "components/copresence/public/whispernet_client.h"
10 #include "components/copresence/rpc/rpc_handler.h"
12 namespace copresence
{
14 PendingRequest::PendingRequest(const copresence::ReportRequest
& report
,
15 const std::string app_id
,
16 const StatusCallback
& callback
)
17 : report(report
), app_id(app_id
), callback(callback
) {
20 PendingRequest::~PendingRequest() {
25 CopresenceManagerImpl::~CopresenceManagerImpl() {}
27 // Returns false if any operations were malformed.
28 void CopresenceManagerImpl::ExecuteReportRequest(
29 ReportRequest request
,
30 const std::string
& app_id
,
31 const StatusCallback
& callback
) {
32 // Don't take on any more requests. We can't execute them since init failed.
38 DCHECK(rpc_handler_
.get());
39 if (pending_init_operations_
) {
40 pending_requests_queue_
.push_back(
41 PendingRequest(request
, app_id
, callback
));
43 rpc_handler_
->SendReportRequest(
44 make_scoped_ptr(new copresence::ReportRequest(request
)),
52 CopresenceManagerImpl::CopresenceManagerImpl(CopresenceDelegate
* delegate
)
53 : init_failed_(false),
54 pending_init_operations_(0),
59 void CopresenceManagerImpl::CompleteInitialization() {
60 if (pending_init_operations_
)
63 DCHECK(rpc_handler_
.get());
65 rpc_handler_
->ConnectToWhispernet();
67 for (PendingRequest
& request
: pending_requests_queue_
) {
69 request
.callback
.Run(FAIL
);
71 rpc_handler_
->SendReportRequest(
72 make_scoped_ptr(new copresence::ReportRequest(request
.report
)),
77 pending_requests_queue_
.clear();
80 void CopresenceManagerImpl::InitStepComplete(
81 const std::string
& step
, bool success
) {
83 LOG(ERROR
) << step
<< " failed!";
87 DVLOG(3) << "Init step: " << step
<< " complete.";
88 pending_init_operations_
--;
89 CompleteInitialization();
92 } // namespace copresence