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

Side by Side Diff: services/log/log_impl.h

Issue 1928613002: Simplify LogImpl a bit. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « PRESUBMIT.py ('k') | services/log/log_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef SERVICES_LOG_LOG_IMPL_H_ 5 #ifndef SERVICES_LOG_LOG_IMPL_H_
6 #define SERVICES_LOG_LOG_IMPL_H_ 6 #define SERVICES_LOG_LOG_IMPL_H_
7 7
8 #include <stdio.h> 8 #include <functional>
9
10 #include <string> 9 #include <string>
11 10
12 #include "base/macros.h" 11 #include "base/macros.h"
13 #include "mojo/public/cpp/bindings/interface_request.h" 12 #include "mojo/public/cpp/bindings/interface_request.h"
14 #include "mojo/public/cpp/bindings/strong_binding.h" 13 #include "mojo/public/cpp/bindings/strong_binding.h"
15 #include "mojo/services/log/interfaces/entry.mojom.h" 14 #include "mojo/services/log/interfaces/entry.mojom.h"
16 #include "mojo/services/log/interfaces/log.mojom.h" 15 #include "mojo/services/log/interfaces/log.mojom.h"
17 16
18 namespace mojo { 17 namespace mojo {
19 18
20 class ApplicationConnection; 19 class ApplicationConnection;
21 20
22 namespace log { 21 namespace log {
23 22
24 // This is an implementation of the log service 23 // This is an implementation of the log service
25 // (see mojo/services/log/interfaces/log.mojom). It formats incoming messages 24 // (see mojo/services/log/interfaces/log.mojom). It formats incoming messages
26 // and writes them to the supplied FILE stream. It does not take ownership of 25 // and "prints" them using a supplied function.
27 // the FILE stream.
28 // 26 //
29 // This service implementation binds a new Log implementation for each incoming 27 // This service implementation binds a new Log implementation for each incoming
30 // application connection. 28 // application connection.
31 class LogImpl : public Log { 29 class LogImpl : public Log {
32 public: 30 public:
33 // LogImpl does not take ownership of |out_file|, so |out_file| must live for 31 // Function that prints the given (fully-formatted) log message.
34 // the duration of the incoming connection (which is left undefined). 32 using PrintLogMessageFunction =
33 std::function<void(const std::string& message)>;
34
35 // Note that |print_log_message_function| may be called many times, for the
36 // lifetime of the created object.
35 static void Create(ApplicationConnection* connection, 37 static void Create(ApplicationConnection* connection,
36 InterfaceRequest<Log> request, 38 InterfaceRequest<Log> request,
37 FILE* out_file); 39 PrintLogMessageFunction print_log_message_function);
38 40
39 // |Log| implementation: 41 // |Log| implementation:
40 void AddEntry(EntryPtr entry) override; 42 void AddEntry(EntryPtr entry) override;
41 43
42 private: 44 private:
43 LogImpl(const std::string& remote_url, 45 LogImpl(const std::string& remote_url,
44 InterfaceRequest<Log> request, 46 InterfaceRequest<Log> request,
45 FILE* out_file); 47 PrintLogMessageFunction print_log_message_function);
46 ~LogImpl() override; 48 ~LogImpl() override;
47 49
48 std::string FormatEntry(const EntryPtr& entry); 50 std::string FormatEntry(const EntryPtr& entry);
49 51
50 const std::string remote_url_; 52 const std::string remote_url_;
51 StrongBinding<Log> binding_; 53 StrongBinding<Log> binding_;
52 FILE* out_file_; 54 const PrintLogMessageFunction print_log_message_function_;
53 55
54 DISALLOW_COPY_AND_ASSIGN(LogImpl); 56 DISALLOW_COPY_AND_ASSIGN(LogImpl);
55 }; 57 };
56 58
57 } // namespace log 59 } // namespace log
58 } // namespace mojo 60 } // namespace mojo
59 61
60 #endif // SERVICES_LOG_LOG_IMPL_H_ 62 #endif // SERVICES_LOG_LOG_IMPL_H_
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | services/log/log_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698