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

Unified Diff: services/flog/flog_service_impl.cc

Issue 2046703002: Add 'flog' service implementation. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fixes per feedback. Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/flog/flog_service_impl.h ('k') | services/flog/main.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/flog/flog_service_impl.cc
diff --git a/services/flog/flog_service_impl.cc b/services/flog/flog_service_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ecfd4516f5ea8c589d180082df749c299262d962
--- /dev/null
+++ b/services/flog/flog_service_impl.cc
@@ -0,0 +1,93 @@
+// Copyright 2016 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 "mojo/public/cpp/application/connect.h"
+#include "mojo/public/cpp/application/service_provider_impl.h"
+#include "services/flog/flog_directory.h"
+#include "services/flog/flog_logger_impl.h"
+#include "services/flog/flog_reader_impl.h"
+#include "services/flog/flog_service_impl.h"
+
+namespace mojo {
+namespace flog {
+
+FlogServiceImpl::FlogServiceImpl() {}
+
+FlogServiceImpl::~FlogServiceImpl() {}
+
+void FlogServiceImpl::OnInitialize() {
+ directory_ = std::shared_ptr<FlogDirectory>(new FlogDirectory(shell()));
+ directory_->GetExistingFiles([this](
+ std::unique_ptr<std::map<uint32_t, std::string>> labels_by_id) {
+ log_labels_by_id_ = std::move(labels_by_id);
+ DCHECK(log_labels_by_id_);
+ for (const std::pair<uint32_t, std::string>& pair : *log_labels_by_id_) {
+ if (pair.first > last_allocated_log_id_) {
+ last_allocated_log_id_ = pair.first;
+ }
+ }
+
+ ready_.Occur();
+ });
+}
+
+bool FlogServiceImpl::OnAcceptConnection(
+ ServiceProviderImpl* service_provider_impl) {
+ service_provider_impl->AddService<FlogService>(
+ [this](const ConnectionContext& connection_context,
+ InterfaceRequest<FlogService> flog_service_request) {
+ bindings_.AddBinding(this, flog_service_request.Pass());
+ });
+ return true;
+}
+
+void FlogServiceImpl::CreateLogger(InterfaceRequest<FlogLogger> logger,
+ const String& label) {
+ // TODO(dalesat): Get rid of this capture hack once we have c++14.
+ MessagePipeHandle handle = logger.PassMessagePipe().release();
+ ready_.When([this, handle, label]() {
+ InterfaceRequest<FlogLogger> logger =
+ InterfaceRequest<FlogLogger>(ScopedMessagePipeHandle(handle));
+ AddProduct(FlogLoggerImpl::Create(logger.Pass(), ++last_allocated_log_id_,
+ label, directory_, this));
+ });
+}
+
+void FlogServiceImpl::GetLogDescriptions(
+ const GetLogDescriptionsCallback& callback) {
+ ready_.When([this, callback]() {
+ DCHECK(log_labels_by_id_);
+ // TODO(dalesat): Include open and new logs.
+ Array<FlogDescriptionPtr> descriptions =
+ Array<FlogDescriptionPtr>::New(log_labels_by_id_->size());
+
+ size_t i = 0;
+ for (std::pair<uint32_t, std::string> pair : *log_labels_by_id_) {
+ FlogDescriptionPtr description = FlogDescription::New();
+ description->log_id = pair.first;
+ description->label = pair.second;
+ description->open = false;
+ descriptions[i++] = description.Pass();
+ }
+
+ callback.Run(descriptions.Pass());
+ });
+}
+
+void FlogServiceImpl::CreateReader(InterfaceRequest<FlogReader> reader,
+ uint32_t log_id) {
+ // TODO(dalesat): Get rid of this capture hack once we have c++14.
+ MessagePipeHandle handle = reader.PassMessagePipe().release();
+ ready_.When([this, handle, log_id]() {
+ DCHECK(log_labels_by_id_);
+ auto iter = log_labels_by_id_->find(log_id);
+ AddProduct(FlogReaderImpl::Create(
+ InterfaceRequest<FlogReader>(ScopedMessagePipeHandle(handle)), log_id,
+ iter == log_labels_by_id_->end() ? nullptr : iter->second, directory_,
+ this));
+ });
+}
+
+} // namespace flog
+} // namespace mojo
« no previous file with comments | « services/flog/flog_service_impl.h ('k') | services/flog/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698