| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/public/cpp/application/connect.h" |
| 6 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 7 #include "services/flog/flog_directory.h" |
| 8 #include "services/flog/flog_logger_impl.h" |
| 9 #include "services/flog/flog_reader_impl.h" |
| 10 #include "services/flog/flog_service_impl.h" |
| 11 |
| 12 namespace mojo { |
| 13 namespace flog { |
| 14 |
| 15 FlogServiceImpl::FlogServiceImpl() {} |
| 16 |
| 17 FlogServiceImpl::~FlogServiceImpl() {} |
| 18 |
| 19 void FlogServiceImpl::OnInitialize() { |
| 20 directory_ = std::shared_ptr<FlogDirectory>(new FlogDirectory(shell())); |
| 21 directory_->GetExistingFiles( |
| 22 [this](std::map<uint32_t, std::string>&& labels_by_id) { |
| 23 labels_by_id.swap(log_labels_by_id_); |
| 24 for (const std::pair<uint32_t, std::string>& pair : log_labels_by_id_) { |
| 25 if (pair.first > last_allocated_log_id_) { |
| 26 last_allocated_log_id_ = pair.first; |
| 27 } |
| 28 } |
| 29 |
| 30 ready_.Occur(); |
| 31 }); |
| 32 } |
| 33 |
| 34 bool FlogServiceImpl::OnAcceptConnection( |
| 35 ServiceProviderImpl* service_provider_impl) { |
| 36 service_provider_impl->AddService<FlogService>( |
| 37 [this](const ConnectionContext& connection_context, |
| 38 InterfaceRequest<FlogService> flog_service_request) { |
| 39 bindings_.AddBinding(this, flog_service_request.Pass()); |
| 40 }); |
| 41 return true; |
| 42 } |
| 43 |
| 44 void FlogServiceImpl::CreateLogger(InterfaceRequest<FlogLogger> logger, |
| 45 const String& label) { |
| 46 // TODO(dalesat): Get rid of this capture hack once we have c++14. |
| 47 MessagePipeHandle handle = logger.PassMessagePipe().release(); |
| 48 ready_.When([this, handle, label]() { |
| 49 InterfaceRequest<FlogLogger> logger = |
| 50 InterfaceRequest<FlogLogger>(ScopedMessagePipeHandle(handle)); |
| 51 AddProduct(FlogLoggerImpl::Create(logger.Pass(), ++last_allocated_log_id_, |
| 52 label, directory_, this)); |
| 53 }); |
| 54 } |
| 55 |
| 56 void FlogServiceImpl::GetLogDescriptions( |
| 57 const GetLogDescriptionsCallback& callback) { |
| 58 ready_.When([this, callback]() { |
| 59 // TODO(dalesat): Include open and new logs. |
| 60 Array<FlogDescriptionPtr> descriptions = |
| 61 Array<FlogDescriptionPtr>::New(log_labels_by_id_.size()); |
| 62 |
| 63 size_t i = 0; |
| 64 for (std::pair<uint32_t, std::string> pair : log_labels_by_id_) { |
| 65 FlogDescriptionPtr description = FlogDescription::New(); |
| 66 description->log_id = pair.first; |
| 67 description->label = pair.second; |
| 68 description->open = false; |
| 69 descriptions[i++] = description.Pass(); |
| 70 } |
| 71 |
| 72 callback.Run(descriptions.Pass()); |
| 73 }); |
| 74 } |
| 75 |
| 76 void FlogServiceImpl::CreateReader(InterfaceRequest<FlogReader> reader, |
| 77 uint32_t log_id) { |
| 78 // TODO(dalesat): Get rid of this capture hack once we have c++14. |
| 79 MessagePipeHandle handle = reader.PassMessagePipe().release(); |
| 80 ready_.When([this, handle, log_id]() { |
| 81 auto iter = log_labels_by_id_.find(log_id); |
| 82 AddProduct(FlogReaderImpl::Create( |
| 83 InterfaceRequest<FlogReader>(ScopedMessagePipeHandle(handle)), log_id, |
| 84 iter == log_labels_by_id_.end() ? nullptr : iter->second, directory_, |
| 85 this)); |
| 86 }); |
| 87 } |
| 88 |
| 89 } // namespace flog |
| 90 } // namespace mojo |
| OLD | NEW |