Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: components/copresence/copresence_client.cc

Issue 441103002: Tests for the Copresence API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@api
Patch Set: Fixing tests for the latest API. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_client.h" 5 #include "components/copresence/public/copresence_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "components/copresence/public/copresence_client_delegate.h" 8 #include "components/copresence/public/copresence_client_delegate.h"
9 #include "components/copresence/public/whispernet_client.h" 9 #include "components/copresence/public/whispernet_client.h"
10 #include "components/copresence/rpc/rpc_handler.h" 10 #include "components/copresence/rpc/rpc_handler.h"
11 11
12 namespace copresence { 12 namespace copresence {
13 13
14 PendingRequest::PendingRequest(const copresence::ReportRequest& report, 14 PendingRequest::PendingRequest(const copresence::ReportRequest& report,
15 const std::string app_id, 15 const std::string app_id,
16 const StatusCallback& callback) 16 const StatusCallback& callback)
17 : report(report), app_id(app_id), callback(callback) { 17 : report(report), app_id(app_id), callback(callback) {
18 } 18 }
19 19
20 PendingRequest::~PendingRequest() { 20 PendingRequest::~PendingRequest() {
21 } 21 }
22 22
23 // Public methods 23 // Public methods
24 24
25 CopresenceClient::CopresenceClient(CopresenceClientDelegate* delegate) 25 CopresenceClient::CopresenceClient()
26 : delegate_(delegate), init_failed_(false), pending_init_operations_(0) { 26 : delegate_(NULL),
27 init_failed_(false),
28 pending_init_operations_(0) {}
29
30 CopresenceClient::~CopresenceClient() {}
31
32 void CopresenceClient::Initialize(CopresenceClientDelegate* delegate) {
27 DVLOG(3) << "Initializing client."; 33 DVLOG(3) << "Initializing client.";
34 DCHECK(delegate);
35 delegate_ = delegate;
36
28 pending_init_operations_++; 37 pending_init_operations_++;
29 rpc_handler_.reset( 38 rpc_handler_.reset(
30 new RpcHandler(delegate, 39 new RpcHandler(delegate,
31 base::Bind(&CopresenceClient::InitStepComplete, 40 base::Bind(&CopresenceClient::InitStepComplete,
32 AsWeakPtr(), 41 AsWeakPtr(),
33 "Copresence device registration"))); 42 "Copresence device registration")));
34 43
35 pending_init_operations_++; 44 pending_init_operations_++;
36 delegate_->GetWhispernetClient()->Initialize( 45 DCHECK(delegate->GetWhispernetClient());
46 delegate->GetWhispernetClient()->Initialize(
37 base::Bind(&CopresenceClient::InitStepComplete, 47 base::Bind(&CopresenceClient::InitStepComplete,
38 AsWeakPtr(), 48 AsWeakPtr(),
39 "Whispernet proxy initialization")); 49 "Whispernet proxy initialization"));
40 } 50 }
41 51
42 CopresenceClient::~CopresenceClient() {
43 }
44
45 void CopresenceClient::Shutdown() { 52 void CopresenceClient::Shutdown() {
46 DVLOG(3) << "Shutting down client."; 53 DVLOG(3) << "Shutting down client.";
47 delegate_->GetWhispernetClient()->Shutdown(); 54 if (delegate_ && delegate_->GetWhispernetClient())
48 rpc_handler_->DisconnectFromWhispernet(); 55 delegate_->GetWhispernetClient()->Shutdown();
56 if (rpc_handler_.get())
57 rpc_handler_->DisconnectFromWhispernet();
49 } 58 }
50 59
51 // Returns false if any operations were malformed. 60 // Returns false if any operations were malformed.
52 void CopresenceClient::ExecuteReportRequest(copresence::ReportRequest request, 61 void CopresenceClient::ExecuteReportRequest(copresence::ReportRequest request,
53 const std::string& app_id, 62 const std::string& app_id,
54 const StatusCallback& callback) { 63 const StatusCallback& callback) {
55 // Don't take on any more requests, we can't execute any, init failed. 64 // Don't take on any more requests, we can't execute any, init failed.
56 if (init_failed_) { 65 if (init_failed_) {
57 callback.Run(FAIL); 66 callback.Run(FAIL);
58 return; 67 return;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 LOG(ERROR) << step << " failed!"; 108 LOG(ERROR) << step << " failed!";
100 init_failed_ = true; 109 init_failed_ = true;
101 } 110 }
102 111
103 DVLOG(3) << "Init step: " << step << " complete."; 112 DVLOG(3) << "Init step: " << step << " complete.";
104 pending_init_operations_--; 113 pending_init_operations_--;
105 CompleteInitialization(); 114 CompleteInitialization();
106 } 115 }
107 116
108 } // namespace copresence 117 } // namespace copresence
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698