| 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([this]( |
| 22 std::unique_ptr<std::map<uint32_t, std::string>> labels_by_id) { |
| 23 log_labels_by_id_ = std::move(labels_by_id); |
| 24 DCHECK(log_labels_by_id_); |
| 25 for (const std::pair<uint32_t, std::string>& pair : *log_labels_by_id_) { |
| 26 if (pair.first > last_allocated_log_id_) { |
| 27 last_allocated_log_id_ = pair.first; |
| 28 } |
| 29 } |
| 30 |
| 31 ready_.Occur(); |
| 32 }); |
| 33 } |
| 34 |
| 35 bool FlogServiceImpl::OnAcceptConnection( |
| 36 ServiceProviderImpl* service_provider_impl) { |
| 37 service_provider_impl->AddService<FlogService>( |
| 38 [this](const ConnectionContext& connection_context, |
| 39 InterfaceRequest<FlogService> flog_service_request) { |
| 40 bindings_.AddBinding(this, flog_service_request.Pass()); |
| 41 }); |
| 42 return true; |
| 43 } |
| 44 |
| 45 void FlogServiceImpl::CreateLogger(InterfaceRequest<FlogLogger> logger, |
| 46 const String& label) { |
| 47 // TODO(dalesat): Get rid of this capture hack once we have c++14. |
| 48 MessagePipeHandle handle = logger.PassMessagePipe().release(); |
| 49 ready_.When([this, handle, label]() { |
| 50 InterfaceRequest<FlogLogger> logger = |
| 51 InterfaceRequest<FlogLogger>(ScopedMessagePipeHandle(handle)); |
| 52 AddProduct(FlogLoggerImpl::Create(logger.Pass(), ++last_allocated_log_id_, |
| 53 label, directory_, this)); |
| 54 }); |
| 55 } |
| 56 |
| 57 void FlogServiceImpl::GetLogDescriptions( |
| 58 const GetLogDescriptionsCallback& callback) { |
| 59 ready_.When([this, callback]() { |
| 60 DCHECK(log_labels_by_id_); |
| 61 // TODO(dalesat): Include open and new logs. |
| 62 Array<FlogDescriptionPtr> descriptions = |
| 63 Array<FlogDescriptionPtr>::New(log_labels_by_id_->size()); |
| 64 |
| 65 size_t i = 0; |
| 66 for (std::pair<uint32_t, std::string> pair : *log_labels_by_id_) { |
| 67 FlogDescriptionPtr description = FlogDescription::New(); |
| 68 description->log_id = pair.first; |
| 69 description->label = pair.second; |
| 70 description->open = false; |
| 71 descriptions[i++] = description.Pass(); |
| 72 } |
| 73 |
| 74 callback.Run(descriptions.Pass()); |
| 75 }); |
| 76 } |
| 77 |
| 78 void FlogServiceImpl::CreateReader(InterfaceRequest<FlogReader> reader, |
| 79 uint32_t log_id) { |
| 80 // TODO(dalesat): Get rid of this capture hack once we have c++14. |
| 81 MessagePipeHandle handle = reader.PassMessagePipe().release(); |
| 82 ready_.When([this, handle, log_id]() { |
| 83 DCHECK(log_labels_by_id_); |
| 84 auto iter = log_labels_by_id_->find(log_id); |
| 85 AddProduct(FlogReaderImpl::Create( |
| 86 InterfaceRequest<FlogReader>(ScopedMessagePipeHandle(handle)), log_id, |
| 87 iter == log_labels_by_id_->end() ? nullptr : iter->second, directory_, |
| 88 this)); |
| 89 }); |
| 90 } |
| 91 |
| 92 } // namespace flog |
| 93 } // namespace mojo |
| OLD | NEW |