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

Side by Side Diff: mojo/services/flog/cpp/flog.h

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 unified diff | Download patch
« no previous file with comments | « mojo/services/flog/cpp/BUILD.gn ('k') | mojo/services/flog/interfaces/flog.mojom » ('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 2016 The Chromium Authors. All rights reserved. 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 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 MOJO_SERVICES_FLOG_CPP_FLOG_H_ 5 #ifndef MOJO_SERVICES_FLOG_CPP_FLOG_H_
6 #define MOJO_SERVICES_FLOG_CPP_FLOG_H_ 6 #define MOJO_SERVICES_FLOG_CPP_FLOG_H_
7 7
8 #include <atomic> 8 #include <atomic>
9 #include <memory> 9 #include <memory>
10 10
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 #define FLOG(channel_name, call) channel_name->call 89 #define FLOG(channel_name, call) channel_name->call
90 90
91 #define FLOG_ID(channel_name) channel_name->channel()->id() 91 #define FLOG_ID(channel_name) channel_name->channel()->id()
92 92
93 #endif 93 #endif
94 94
95 // Thread-safe logger for all channels in a given process. 95 // Thread-safe logger for all channels in a given process.
96 class Flog { 96 class Flog {
97 public: 97 public:
98 static void Initialize(ApplicationImpl* app, const std::string& label) { 98 static void Initialize(Shell* shell, const std::string& label) {
99 MOJO_DCHECK(!logger_); 99 MOJO_DCHECK(!logger_);
100 FlogServicePtr flog_service; 100 FlogServicePtr flog_service;
101 FlogLoggerPtr flog_logger; 101 FlogLoggerPtr flog_logger;
102 ConnectToService(app->shell(), "mojo:flog", GetProxy(&flog_service)); 102 ConnectToService(shell, "mojo:flog", GetProxy(&flog_service));
103 flog_service->CreateLogger(GetProxy(&flog_logger), label); 103 flog_service->CreateLogger(GetProxy(&flog_logger), label);
104 logger_ = flog_logger.Pass(); 104 logger_ = flog_logger.Pass();
105 } 105 }
106 106
107 // Sets the flog logger singleton. 107 // Sets the flog logger singleton.
108 static void Initialize(FlogLoggerPtr flog_logger) { 108 static void Initialize(FlogLoggerPtr flog_logger) {
109 MOJO_DCHECK(!logger_); 109 MOJO_DCHECK(!logger_);
110 logger_ = flog_logger.Pass(); 110 logger_ = flog_logger.Pass();
111 } 111 }
112 112
(...skipping 30 matching lines...) Expand all
143 143
144 // Logs the deletion of a channel. 144 // Logs the deletion of a channel.
145 static void LogChannelDeletion(uint32_t channel_id) { 145 static void LogChannelDeletion(uint32_t channel_id) {
146 if (!logger_) { 146 if (!logger_) {
147 return; 147 return;
148 } 148 }
149 149
150 logger_->LogChannelDeletion(GetTimeTicksNow(), channel_id); 150 logger_->LogChannelDeletion(GetTimeTicksNow(), channel_id);
151 } 151 }
152 152
153 // TODO(dalesat): Add method for text/file/line
154
153 private: 155 private:
154 static std::atomic_ulong last_allocated_channel_id_; 156 static std::atomic_ulong last_allocated_channel_id_;
155 static FlogLoggerPtr logger_; 157 static FlogLoggerPtr logger_;
156 }; 158 };
157 159
158 // Channel backing a FlogProxy. 160 // Channel backing a FlogProxy.
159 class FlogChannel : public MessageReceiverWithResponder { 161 class FlogChannel : public MessageReceiverWithResponder {
160 public: 162 public:
161 FlogChannel(const char* channel_type_name); 163 FlogChannel(const char* channel_type_name);
162 164
(...skipping 24 matching lines...) Expand all
187 } 189 }
188 190
189 private: 191 private:
190 explicit FlogProxy() : T::Proxy_(new FlogChannel(T::Name_)) {} 192 explicit FlogProxy() : T::Proxy_(new FlogChannel(T::Name_)) {}
191 }; 193 };
192 194
193 } // namespace flog 195 } // namespace flog
194 } // namespace mojo 196 } // namespace mojo
195 197
196 #endif // MOJO_SERVICES_FLOG_CPP_FLOG_H_ 198 #endif // MOJO_SERVICES_FLOG_CPP_FLOG_H_
OLDNEW
« no previous file with comments | « mojo/services/flog/cpp/BUILD.gn ('k') | mojo/services/flog/interfaces/flog.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698