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

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: 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
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..d29a64c6184ef30d52b0b4a4b8bb653746d597a2
--- /dev/null
+++ b/services/flog/flog_service_impl.cc
@@ -0,0 +1,90 @@
+// 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::map<uint32_t, std::string>&& labels_by_id) {
+ labels_by_id.swap(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]() {
+ // 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]() {
+ 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

Powered by Google App Engine
This is Rietveld 408576698