forked from sanyaade-mobiledev/chromium.src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This CL adds the copresence component that will be used by the Copresence API. This code exposes the CopresenceClient class. This class provides all the functionality needed by any user of Copresence, which currently is only the Chrome API. A few notes on the CL: . I have stubbed out as much code as possible while still keeping the implementation of at least the client in the CL. This required me to have the proto buffers (since the delegate we use sends its data back and forth in proto buffs) and the stub RPC handler (which the client directly depends on). . The protobufs are automatically generated by pulling them from the server code and running a tool that strips out unnecessary fields. This has the unfortunate side effect of pulling out all comments/formatting and leaving us with no control on naming (unless we go change the server code). This does ensure though that we are constantly up-to-date with the server protos. - We also have a few deprecated fields in the protobufs, since they are still needed on the server for Chrome specific server code. We have bugs out on the server to fix this and as soon as that happens, we will be getting rid of all the deprecated fields from here too. An open question I have is about the .GN files. Are those going to get autogenerated from the GYPs? Or do I need to manually add them? R=jochen@chromium.org, willchan@chromium.org BUG=365493 Review URL: https://codereview.chromium.org/426093003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287036 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
rkc@chromium.org
committed
Aug 1, 2014
1 parent
1701929
commit e0a6edf
Showing
19 changed files
with
873 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright 2014 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
{ | ||
'targets': [ | ||
{ | ||
'target_name': 'copresence', | ||
'type': 'static_library', | ||
'dependencies': [ | ||
'../base/base.gyp:base', | ||
'../net/net.gyp:net', | ||
'copresence_proto', | ||
], | ||
'include_dirs': [ | ||
'..', | ||
], | ||
'sources': [ | ||
'copresence/copresence_client.cc', | ||
'copresence/public/copresence_client_delegate.h', | ||
'copresence/public/copresence_client.h', | ||
'copresence/public/whispernet_client.h', | ||
'copresence/rpc/rpc_handler.cc', | ||
'copresence/rpc/rpc_handler.h', | ||
], | ||
'export_dependent_settings': [ | ||
'copresence_proto', | ||
], | ||
}, | ||
{ | ||
# Protobuf compiler / generate rule for copresence. | ||
# GN version: //components/copresence/proto | ||
# Note: These protos are auto-generated from the protos of the | ||
# Copresence server. Currently this strips all formatting and comments | ||
# but makes sure that we are always using up to date protos. | ||
'target_name': 'copresence_proto', | ||
'type': 'static_library', | ||
'sources': [ | ||
'copresence/proto/codes.proto', | ||
'copresence/proto/data.proto', | ||
'copresence/proto/enums.proto', | ||
'copresence/proto/identity.proto', | ||
'copresence/proto/rpcs.proto', | ||
], | ||
'variables': { | ||
'proto_in_dir': 'copresence/proto', | ||
'proto_out_dir': 'components/copresence/proto', | ||
}, | ||
'includes': [ '../build/protoc.gypi' ] | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2014 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
static_library("copresence") { | ||
sources = [ | ||
"copresence_client.cc", | ||
"public/copresence_client_delegate.h", | ||
"public/copresence_client.h", | ||
"public/whispernet_client.h", | ||
"rpc/rpc_handler.cc", | ||
"rpc/rpc_handler.h", | ||
] | ||
|
||
deps = [ | ||
"//base", | ||
"//components/copresence/proto", | ||
"//net", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include_rules = [ | ||
"+base", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
rkc@chromium.org | ||
ckehoe@chromium.org | ||
xiyuan@chromium.org | ||
derat@chromium.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "components/copresence/public/copresence_client.h" | ||
|
||
#include "base/bind.h" | ||
#include "components/copresence/public/copresence_client_delegate.h" | ||
#include "components/copresence/public/whispernet_client.h" | ||
#include "components/copresence/rpc/rpc_handler.h" | ||
|
||
namespace copresence { | ||
|
||
PendingRequest::PendingRequest(const copresence::ReportRequest& report, | ||
const std::string app_id, | ||
const StatusCallback& callback) | ||
: report(report), app_id(app_id), callback(callback) { | ||
} | ||
|
||
PendingRequest::~PendingRequest() { | ||
} | ||
|
||
// Public methods | ||
|
||
CopresenceClient::CopresenceClient(CopresenceClientDelegate* delegate) | ||
: delegate_(delegate), init_failed_(false), pending_init_operations_(0) { | ||
DVLOG(3) << "Initializing client."; | ||
pending_init_operations_++; | ||
rpc_handler_.reset( | ||
new RpcHandler(delegate, | ||
base::Bind(&CopresenceClient::InitStepComplete, | ||
AsWeakPtr(), | ||
"Copresence device registration"))); | ||
|
||
pending_init_operations_++; | ||
delegate_->GetWhispernetClient()->Initialize( | ||
base::Bind(&CopresenceClient::InitStepComplete, | ||
AsWeakPtr(), | ||
"Whispernet proxy initialization")); | ||
} | ||
|
||
CopresenceClient::~CopresenceClient() { | ||
} | ||
|
||
void CopresenceClient::Shutdown() { | ||
DVLOG(3) << "Shutting down client."; | ||
delegate_->GetWhispernetClient()->Shutdown(); | ||
rpc_handler_->DisconnectFromWhispernet(); | ||
} | ||
|
||
// Returns false if any operations were malformed. | ||
void CopresenceClient::ExecuteReportRequest(copresence::ReportRequest request, | ||
const std::string& app_id, | ||
const StatusCallback& callback) { | ||
// Don't take on any more requests, we can't execute any, init failed. | ||
if (init_failed_) { | ||
callback.Run(FAIL); | ||
return; | ||
} | ||
|
||
if (pending_init_operations_) { | ||
pending_requests_queue_.push_back( | ||
PendingRequest(request, app_id, callback)); | ||
} else { | ||
rpc_handler_->SendReportRequest( | ||
make_scoped_ptr(new copresence::ReportRequest(request)), | ||
app_id, | ||
callback); | ||
} | ||
} | ||
|
||
// Private methods | ||
|
||
void CopresenceClient::CompleteInitialization() { | ||
if (pending_init_operations_) | ||
return; | ||
|
||
if (!init_failed_) | ||
rpc_handler_->ConnectToWhispernet(delegate_->GetWhispernetClient()); | ||
|
||
for (std::vector<PendingRequest>::iterator request = | ||
pending_requests_queue_.begin(); | ||
request != pending_requests_queue_.end(); | ||
++request) { | ||
if (init_failed_) { | ||
request->callback.Run(FAIL); | ||
} else { | ||
rpc_handler_->SendReportRequest( | ||
make_scoped_ptr(new copresence::ReportRequest(request->report)), | ||
request->app_id, | ||
request->callback); | ||
} | ||
} | ||
pending_requests_queue_.clear(); | ||
} | ||
|
||
void CopresenceClient::InitStepComplete(const std::string& step, bool success) { | ||
if (!success) { | ||
LOG(ERROR) << step << " failed!"; | ||
init_failed_ = true; | ||
} | ||
|
||
DVLOG(3) << "Init step: " << step << " complete."; | ||
pending_init_operations_--; | ||
CompleteInitialization(); | ||
} | ||
|
||
} // namespace copresence |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2014 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
import("//third_party/protobuf/proto_library.gni") | ||
|
||
# GYP version: components/copresence.gypi:copresence_proto | ||
proto_library("proto") { | ||
sources = [ | ||
"codes.proto", | ||
"data.proto", | ||
"enums.proto", | ||
"identity.proto", | ||
"rpcs.proto", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
syntax = "proto2"; | ||
package util.error; | ||
option optimize_for = LITE_RUNTIME; | ||
enum Code { | ||
OK = 0; | ||
CANCELLED = 1; | ||
UNKNOWN = 2; | ||
INVALID_ARGUMENT = 3; | ||
DEADLINE_EXCEEDED = 4; | ||
NOT_FOUND = 5; | ||
ALREADY_EXISTS = 6; | ||
PERMISSION_DENIED = 7; | ||
UNAUTHENTICATED = 16; | ||
RESOURCE_EXHAUSTED = 8; | ||
FAILED_PRECONDITION = 9; | ||
ABORTED = 10; | ||
OUT_OF_RANGE = 11; | ||
UNIMPLEMENTED = 12; | ||
INTERNAL = 13; | ||
UNAVAILABLE = 14; | ||
DATA_LOSS = 15; | ||
DO_NOT_USE_RESERVED_FOR_FUTURE_EXPANSION_USE_DEFAULT_IN_SWITCH_INSTEAD_ = 20; | ||
} |
Oops, something went wrong.