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

Side by Side Diff: net/base/load_log.cc

Issue 848006: Generalize the net module's LoadLog facility from a passive container, to an event stream (NetLog). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Split up RequestTracker into ConnectJobTracker+RequestTracker+RequestTrackerBase, address comments Created 10 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « net/base/load_log.h ('k') | net/base/load_log_event_type_list.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 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 "net/base/load_log.h"
6 #include "base/logging.h"
7
8 namespace net {
9
10 LoadLog::LoadLog(size_t max_num_entries)
11 : num_entries_truncated_(0), max_num_entries_(max_num_entries) {
12 DCHECK_GT(max_num_entries, 0u);
13 }
14
15 // static
16 const char* LoadLog::EventTypeToString(EventType event) {
17 switch (event) {
18 #define EVENT_TYPE(label) case TYPE_ ## label: return #label;
19 #include "net/base/load_log_event_type_list.h"
20 #undef EVENT_TYPE
21 }
22 return NULL;
23 }
24
25 void LoadLog::Add(const Entry& entry) {
26 // Minor optimization. TODO(eroman): use StackVector instead.
27 if (entries_.empty())
28 entries_.reserve(10); // It is likely we will have at least 10 entries.
29
30 // Enforce a bound of |max_num_entries_| -- once we reach it, keep overwriting
31 // the final entry in the log.
32
33 if (entries_.size() + 1 <= max_num_entries_ ||
34 max_num_entries_ == kUnbounded) {
35 entries_.push_back(entry);
36 } else {
37 num_entries_truncated_ += 1;
38 entries_[max_num_entries_ - 1] = entry;
39 }
40 }
41
42 void LoadLog::Append(const LoadLog* log) {
43 for (size_t i = 0; i < log->entries().size(); ++i)
44 Add(log->entries()[i]);
45 num_entries_truncated_ += log->num_entries_truncated();
46 }
47
48 } // namespace net
OLDNEW
« no previous file with comments | « net/base/load_log.h ('k') | net/base/load_log_event_type_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698