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

Side by Side Diff: chrome/browser/net/chrome_net_log.cc

Issue 12094085: LoadTiming in net part 7: Hooking it all up (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync Created 7 years, 8 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 | « chrome/browser/net/chrome_net_log.h ('k') | chrome/browser/net/load_timing_browsertest.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/net/chrome_net_log.h" 5 #include "chrome/browser/net/chrome_net_log.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h"
8 #include "base/logging.h" 9 #include "base/logging.h"
9 #include "base/string_util.h" 10 #include "base/string_util.h"
10 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "chrome/browser/net/load_timing_observer.h"
13 #include "chrome/browser/net/net_log_logger.h" 13 #include "chrome/browser/net/net_log_logger.h"
14 #include "chrome/browser/net/net_log_temp_file.h" 14 #include "chrome/browser/net/net_log_temp_file.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 16
17 ChromeNetLog::ChromeNetLog() 17 ChromeNetLog::ChromeNetLog()
18 : last_id_(0), 18 : last_id_(0),
19 base_log_level_(LOG_BASIC), 19 base_log_level_(LOG_BASIC),
20 effective_log_level_(LOG_BASIC), 20 effective_log_level_(LOG_BASIC),
21 load_timing_observer_(new LoadTimingObserver()),
22 net_log_temp_file_(new NetLogTempFile(this)) { 21 net_log_temp_file_(new NetLogTempFile(this)) {
23 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 22 const CommandLine* command_line = CommandLine::ForCurrentProcess();
24 // Adjust base log level based on command line switch, if present. 23 // Adjust base log level based on command line switch, if present.
25 // This is done before adding any observers so the call to UpdateLogLevel when 24 // This is done before adding any observers so the call to UpdateLogLevel when
26 // an observers is added will set |effective_log_level_| correctly. 25 // an observers is added will set |effective_log_level_| correctly.
27 if (command_line->HasSwitch(switches::kNetLogLevel)) { 26 if (command_line->HasSwitch(switches::kNetLogLevel)) {
28 std::string log_level_string = 27 std::string log_level_string =
29 command_line->GetSwitchValueASCII(switches::kNetLogLevel); 28 command_line->GetSwitchValueASCII(switches::kNetLogLevel);
30 int command_line_log_level; 29 int command_line_log_level;
31 if (base::StringToInt(log_level_string, &command_line_log_level) && 30 if (base::StringToInt(log_level_string, &command_line_log_level) &&
32 command_line_log_level >= LOG_ALL && 31 command_line_log_level >= LOG_ALL &&
33 command_line_log_level <= LOG_BASIC) { 32 command_line_log_level <= LOG_BASIC) {
34 base_log_level_ = static_cast<LogLevel>(command_line_log_level); 33 base_log_level_ = static_cast<LogLevel>(command_line_log_level);
35 } 34 }
36 } 35 }
37 36
38 load_timing_observer_->StartObserving(this);
39
40 if (command_line->HasSwitch(switches::kLogNetLog)) { 37 if (command_line->HasSwitch(switches::kLogNetLog)) {
41 net_log_logger_.reset(new NetLogLogger( 38 net_log_logger_.reset(new NetLogLogger(
42 command_line->GetSwitchValuePath(switches::kLogNetLog))); 39 command_line->GetSwitchValuePath(switches::kLogNetLog)));
43 net_log_logger_->StartObserving(this); 40 net_log_logger_->StartObserving(this);
44 } 41 }
45 } 42 }
46 43
47 ChromeNetLog::~ChromeNetLog() { 44 ChromeNetLog::~ChromeNetLog() {
48 net_log_temp_file_.reset(); 45 net_log_temp_file_.reset();
49 // Remove the observers we own before we're destroyed. 46 // Remove the observers we own before we're destroyed.
50 RemoveThreadSafeObserver(load_timing_observer_.get()); 47 if (net_log_logger_)
51 if (net_log_logger_.get())
52 RemoveThreadSafeObserver(net_log_logger_.get()); 48 RemoveThreadSafeObserver(net_log_logger_.get());
53 } 49 }
54 50
55 void ChromeNetLog::OnAddEntry(const net::NetLog::Entry& entry) { 51 void ChromeNetLog::OnAddEntry(const net::NetLog::Entry& entry) {
56 base::AutoLock lock(lock_); 52 base::AutoLock lock(lock_);
57 53
58 // Notify all of the log observers. 54 // Notify all of the log observers.
59 FOR_EACH_OBSERVER(ThreadSafeObserver, observers_, OnAddEntry(entry)); 55 FOR_EACH_OBSERVER(ThreadSafeObserver, observers_, OnAddEntry(entry));
60 } 56 }
61 57
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 LogLevel new_effective_log_level = base_log_level_; 103 LogLevel new_effective_log_level = base_log_level_;
108 ObserverListBase<ThreadSafeObserver>::Iterator it(observers_); 104 ObserverListBase<ThreadSafeObserver>::Iterator it(observers_);
109 ThreadSafeObserver* observer; 105 ThreadSafeObserver* observer;
110 while ((observer = it.GetNext()) != NULL) { 106 while ((observer = it.GetNext()) != NULL) {
111 new_effective_log_level = 107 new_effective_log_level =
112 std::min(new_effective_log_level, observer->log_level()); 108 std::min(new_effective_log_level, observer->log_level());
113 } 109 }
114 base::subtle::NoBarrier_Store(&effective_log_level_, 110 base::subtle::NoBarrier_Store(&effective_log_level_,
115 new_effective_log_level); 111 new_effective_log_level);
116 } 112 }
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_net_log.h ('k') | chrome/browser/net/load_timing_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698