1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
// Copyright (c) 2009 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 "base/logging.h"
#include "base/mac_util.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
#include "base/time.h"
#include "chrome/browser/browser_process.h"
#import "chrome/browser/cocoa/about_ipc_controller.h"
#if defined(IPC_MESSAGE_LOG_ENABLED)
@implementation CocoaLogData
- (id)initWithLogData:(const IPC::LogData&)data {
if ((self = [super init])) {
data_ = data;
// data_.message_name may not have been filled in if it originated
// somewhere other than the browser process.
IPC::Logging::GetMessageText(data_.type, &data_.message_name, NULL, NULL);
}
return self;
}
- (NSString*)time {
base::Time t = base::Time::FromInternalValue(data_.sent);
base::Time::Exploded exploded;
t.LocalExplode(&exploded);
return [NSString stringWithFormat:@"%02d:%02d:%02d.%03d",
exploded.hour, exploded.minute,
exploded.second, exploded.millisecond];
}
- (NSString*)channel {
return base::SysUTF8ToNSString(data_.channel);
}
- (NSString*)message {
if (data_.message_name == L"") {
int high = data_.type >> 12;
int low = data_.type - (high<<12);
return [NSString stringWithFormat:@"type=(%d,%d) 0x%x,0x%x",
high, low, high, low];
}
else {
return base::SysWideToNSString(data_.message_name);
}
}
- (NSString*)flags {
return base::SysWideToNSString(data_.flags);
}
- (NSString*)dispatch {
base::Time sent = base::Time::FromInternalValue(data_.sent);
int64 delta = (base::Time::FromInternalValue(data_.receive) -
sent).InMilliseconds();
return [NSString stringWithFormat:@"%d", delta ? (int)delta : 0];
}
- (NSString*)process {
base::TimeDelta delta = (base::Time::FromInternalValue(data_.dispatch) -
base::Time::FromInternalValue(data_.receive));
int64 t = delta.InMilliseconds();
return [NSString stringWithFormat:@"%d", t ? (int)t : 0];
}
- (NSString*)parameters {
return base::SysWideToNSString(data_.params);
}
@end
namespace {
AboutIPCController* gSharedController = nil;
}
@implementation AboutIPCController
+ (AboutIPCController*)sharedController {
if (gSharedController == nil)
gSharedController = [[AboutIPCController alloc] init];
return gSharedController;
}
- (id)init {
NSString* nibpath = [mac_util::MainAppBundle() pathForResource:@"AboutIPC"
ofType:@"nib"];
if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
// Default to all on
appCache_ = view_ = utilityHost_ = viewHost_ = plugin_ =
npObject_ = devTools_ = pluginProcessing_ = userString1_ =
userString2_ = userString3_ = YES;
}
return self;
}
- (void)dealloc {
if (gSharedController == self)
gSharedController = nil;
if (g_browser_process)
g_browser_process->SetIPCLoggingEnabled(false); // just in case...
IPC::Logging::current()->SetConsumer(NULL);
[super dealloc];
}
- (void)awakeFromNib {
// Running Chrome with the --ipc-logging switch might cause it to
// be enabled before the about:ipc window comes up; accomodate.
[self updateVisibleRunState];
// We are now able to display information, so let'er rip.
bridge_.reset(new AboutIPCBridge(self));
IPC::Logging::current()->SetConsumer(bridge_.get());
}
// Delegate callback. Closing the window means there is no more need
// for the me, the controller.
- (void)windowWillClose:(NSNotification*)notification {
[self autorelease];
}
- (void)updateVisibleRunState {
if (IPC::Logging::current()->Enabled())
[startStopButton_ setTitle:@"Stop"];
else
[startStopButton_ setTitle:@"Start"];
}
- (IBAction)startStop:(id)sender {
g_browser_process->SetIPCLoggingEnabled(!IPC::Logging::current()->Enabled());
[self updateVisibleRunState];
}
- (IBAction)clear:(id)sender {
[dataController_ setContent:[NSMutableArray array]];
[eventCount_ setStringValue:@"0"];
[filteredEventCount_ setStringValue:@"0"];
filteredEventCounter_ = 0;
}
// Return YES if we should filter this out; else NO.
// Just to be clear, [@"any string" hasPrefix:@""] returns NO.
- (BOOL)filterOut:(CocoaLogData*)data {
NSString* name = [data message];
if ((appCache_) && [name hasPrefix:@"AppCache"])
return NO;
if ((view_) && [name hasPrefix:@"ViewMsg"])
return NO;
if ((utilityHost_) && [name hasPrefix:@"UtilityHost"])
return NO;
if ((viewHost_) && [name hasPrefix:@"ViewHost"])
return NO;
if ((plugin_) && [name hasPrefix:@"PluginMsg"])
return NO;
if ((npObject_) && [name hasPrefix:@"NPObject"])
return NO;
if ((devTools_) && [name hasPrefix:@"DevTools"])
return NO;
if ((pluginProcessing_) && [name hasPrefix:@"PluginProcessing"])
return NO;
if ((userString1_) && ([name hasPrefix:[userStringTextField1_ stringValue]]))
return NO;
if ((userString2_) && ([name hasPrefix:[userStringTextField2_ stringValue]]))
return NO;
if ((userString3_) && ([name hasPrefix:[userStringTextField3_ stringValue]]))
return NO;
// Special case the unknown type.
if ([name hasPrefix:@"type="])
return NO;
return YES; // filter out.
}
- (void)log:(CocoaLogData*)data {
if ([self filterOut:data]) {
[filteredEventCount_ setStringValue:[NSString stringWithFormat:@"%d",
++filteredEventCounter_]];
return;
}
[dataController_ addObject:data];
NSUInteger count = [[dataController_ arrangedObjects] count];
// Uncomment if you want scroll-to-end behavior... but seems expensive.
// [tableView_ scrollRowToVisible:count-1];
[eventCount_ setStringValue:[NSString stringWithFormat:@"%d", count]];
}
- (void)setDisplayViewMessages:(BOOL)display {
view_ = display;
}
@end
#endif // IPC_MESSAGE_LOG_ENABLED
|