blob: 2539c27ccbc372e83fe69f5b8e60d0c75bb9b2c1 (
plain)
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
|
// Copyright (c) 2010 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.
#ifndef CHROME_BROWSER_NET_PASSIVE_LOG_COLLECTOR_H_
#define CHROME_BROWSER_NET_PASSIVE_LOG_COLLECTOR_H_
#include <vector>
#include "base/hash_tables.h"
#include "chrome/browser/net/chrome_net_log.h"
#include "net/base/net_log.h"
class PassiveLogCollector : public ChromeNetLog::Observer {
public:
struct RequestInfo {
RequestInfo() : num_entries_truncated(0) {}
std::string url;
std::vector<net::NetLog::Entry> entries;
size_t num_entries_truncated;
};
typedef std::vector<RequestInfo> RequestInfoList;
// This class stores and manages the passively logged information for
// URLRequests/SocketStreams/ConnectJobs.
class RequestTrackerBase {
public:
explicit RequestTrackerBase(size_t max_graveyard_size);
void OnAddEntry(const net::NetLog::Entry& entry);
RequestInfoList GetLiveRequests() const;
void ClearRecentlyDeceased();
RequestInfoList GetRecentlyDeceased() const;
void SetUnbounded(bool unbounded);
bool IsUnbounded() const { return is_unbounded_; }
void Clear();
const RequestInfo* GetRequestInfoFromGraveyard(int id) const;
protected:
enum Action {
ACTION_NONE,
ACTION_DELETE,
ACTION_MOVE_TO_GRAVEYARD,
};
// Updates |out_info| with the information from |entry|. Returns an action
// to perform for this map entry on completion.
virtual Action DoAddEntry(const net::NetLog::Entry& entry,
RequestInfo* out_info) = 0;
bool is_unbounded() const { return is_unbounded_; }
private:
typedef base::hash_map<int, RequestInfo> SourceIDToInfoMap;
bool HandleNotificationOfConnectJobID(const net::NetLog::Entry& entry,
RequestInfo* live_entry);
void RemoveFromLiveRequests(int source_id);
void InsertIntoGraveyard(const RequestInfo& info);
SourceIDToInfoMap live_requests_;
size_t max_graveyard_size_;
size_t next_graveyard_index_;
RequestInfoList graveyard_;
bool is_unbounded_;
DISALLOW_COPY_AND_ASSIGN(RequestTrackerBase);
};
// Specialization of RequestTrackerBase for handling ConnectJobs.
class ConnectJobTracker : public RequestTrackerBase {
public:
static const size_t kMaxGraveyardSize;
ConnectJobTracker();
protected:
virtual Action DoAddEntry(const net::NetLog::Entry& entry,
RequestInfo* out_info);
private:
DISALLOW_COPY_AND_ASSIGN(ConnectJobTracker);
};
// Specialization of RequestTrackerBase for handling URLRequest/SocketStream.
class RequestTracker : public RequestTrackerBase {
public:
static const size_t kMaxGraveyardSize;
static const size_t kMaxGraveyardURLSize;
explicit RequestTracker(ConnectJobTracker* connect_job_tracker);
protected:
virtual Action DoAddEntry(const net::NetLog::Entry& entry,
RequestInfo* out_info);
private:
// Searches through |connect_job_tracker_| for information on the
// ConnectJob specified in |entry|, and appends it to |live_entry|.
void AddConnectJobInfo(const net::NetLog::Entry& entry,
RequestInfo* live_entry);
ConnectJobTracker* connect_job_tracker_;
DISALLOW_COPY_AND_ASSIGN(RequestTracker);
};
PassiveLogCollector();
~PassiveLogCollector();
// Observer implementation:
virtual void OnAddEntry(const net::NetLog::Entry& entry);
// Clears all of the passively logged data.
void Clear();
RequestTracker* url_request_tracker() {
return &url_request_tracker_;
}
RequestTracker* socket_stream_tracker() {
return &socket_stream_tracker_;
}
private:
ConnectJobTracker connect_job_tracker_;
RequestTracker url_request_tracker_;
RequestTracker socket_stream_tracker_;
DISALLOW_COPY_AND_ASSIGN(PassiveLogCollector);
};
#endif // CHROME_BROWSER_NET_PASSIVE_LOG_COLLECTOR_H_
|