| Index: mojo/services/test_service/test_service_impl.cc
|
| diff --git a/mojo/services/test_service/test_service_impl.cc b/mojo/services/test_service/test_service_impl.cc
|
| index ec652004f9aa5352de5ea74e9b5189612efd8e39..f1117651a87a8931ca211bb24589dd2e4184e6d6 100644
|
| --- a/mojo/services/test_service/test_service_impl.cc
|
| +++ b/mojo/services/test_service/test_service_impl.cc
|
| @@ -4,14 +4,21 @@
|
|
|
| #include "mojo/services/test_service/test_service_impl.h"
|
|
|
| +#include "base/bind.h"
|
| +#include "base/i18n/time_formatting.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "mojo/public/cpp/application/application_connection.h"
|
| +#include "mojo/services/test_service/monitoring_uploader.h"
|
| #include "mojo/services/test_service/test_service_application.h"
|
| +#include "mojo/services/test_service/test_time_service_impl.h"
|
| +#include "url/gurl.h"
|
|
|
| namespace mojo {
|
| namespace test {
|
|
|
| TestServiceImpl::TestServiceImpl(ApplicationConnection* connection,
|
| TestServiceApplication* application)
|
| - : application_(application) {
|
| + : application_(application), connection_(connection) {
|
| }
|
|
|
| TestServiceImpl::~TestServiceImpl() {
|
| @@ -26,8 +33,38 @@ void TestServiceImpl::OnConnectionError() {
|
| }
|
|
|
| void TestServiceImpl::Ping(const mojo::Callback<void()>& callback) {
|
| + if (monitoring_)
|
| + monitoring_->RecordNewRequest();
|
| callback.Run();
|
| }
|
|
|
| +void SendWelcomeMessageWithTime(
|
| + const mojo::Callback<void(mojo::String)>& requestor_callback,
|
| + int64_t time_usec) {
|
| + std::string friendly_msg(TestServiceImpl::kWelcomeMessagePrefix);
|
| + friendly_msg += UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(
|
| + base::Time::FromInternalValue(time_usec)));
|
| + requestor_callback.Run(friendly_msg);
|
| +}
|
| +
|
| +void TestServiceImpl::GetFriendlyWelcomeMessage(
|
| + const mojo::String& time_app_url,
|
| + const mojo::Callback<void(mojo::String)>& callback) {
|
| + connection_->ConnectToService(time_app_url, &time_service_);
|
| + if (monitoring_) {
|
| + monitoring_->RecordNewRequest();
|
| + time_service_->StartMonitoring(mojo::Callback<void()>());
|
| + }
|
| + time_service_->GetPartyTime(base::Bind(
|
| + &SendWelcomeMessageWithTime,
|
| + callback));
|
| +}
|
| +
|
| +void TestServiceImpl::StartMonitoring(const mojo::Callback<void()>& callback) {
|
| + ToyMonitoringServiceStatsRecorderPtr recorder;
|
| + connection_->ConnectToService("mojo:mojo_test_monitoring_app", &recorder);
|
| + monitoring_.reset(new MonitoringUploader(recorder.Pass(), Name_, callback));
|
| +}
|
| +
|
| } // namespace test
|
| } // namespace mojo
|
|
|