OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/debugger/devtools_netlog_observer.h" | 5 #include "chrome/browser/debugger/devtools_netlog_observer.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "chrome/browser/io_thread.h" | 8 #include "chrome/browser/io_thread.h" |
9 #include "chrome/common/resource_response.h" | 9 #include "chrome/common/resource_response.h" |
10 #include "net/base/load_flags.h" | 10 #include "net/base/load_flags.h" |
11 #include "net/http/http_net_log_params.h" | 11 #include "net/http/http_net_log_params.h" |
12 #include "net/http/http_response_headers.h" | 12 #include "net/http/http_response_headers.h" |
13 #include "net/url_request/url_request.h" | 13 #include "net/url_request/url_request.h" |
14 #include "net/url_request/url_request_netlog_params.h" | 14 #include "net/url_request/url_request_netlog_params.h" |
15 #include "webkit/glue/resource_loader_bridge.h" | 15 #include "webkit/glue/resource_loader_bridge.h" |
16 | 16 |
17 namespace { | |
18 | |
19 void AddEntryOnIOThread( | |
20 DevToolsNetLogObserver* observer, | |
21 net::NetLog::EventType type, | |
22 const base::TimeTicks& time, | |
23 const net::NetLog::Source& source, | |
24 net::NetLog::EventPhase phase, | |
25 scoped_refptr<net::NetLog::EventParameters> params) { | |
26 if (observer == DevToolsNetLogObserver::GetInstance()) { | |
27 observer->OnAddEntry(type, time, source, phase, params.get()); | |
28 } | |
29 } | |
30 | |
31 } // namespace | |
32 | |
17 const size_t kMaxNumEntries = 1000; | 33 const size_t kMaxNumEntries = 1000; |
18 | 34 |
19 DevToolsNetLogObserver* DevToolsNetLogObserver::instance_ = NULL; | 35 DevToolsNetLogObserver* DevToolsNetLogObserver::instance_ = NULL; |
20 | 36 |
21 DevToolsNetLogObserver::DevToolsNetLogObserver(ChromeNetLog* chrome_net_log) | 37 DevToolsNetLogObserver::DevToolsNetLogObserver(ChromeNetLog* chrome_net_log) |
22 : ChromeNetLog::Observer(net::NetLog::LOG_ALL_BUT_BYTES), | 38 : ChromeNetLog::Observer(net::NetLog::LOG_ALL_BUT_BYTES), |
23 chrome_net_log_(chrome_net_log) { | 39 chrome_net_log_(chrome_net_log) { |
24 chrome_net_log_->AddObserver(this); | 40 chrome_net_log_->AddObserver(this); |
25 } | 41 } |
26 | 42 |
27 DevToolsNetLogObserver::~DevToolsNetLogObserver() { | 43 DevToolsNetLogObserver::~DevToolsNetLogObserver() { |
28 chrome_net_log_->RemoveObserver(this); | 44 chrome_net_log_->RemoveObserver(this); |
29 } | 45 } |
30 | 46 |
31 DevToolsNetLogObserver::ResourceInfo* | 47 DevToolsNetLogObserver::ResourceInfo* |
32 DevToolsNetLogObserver::GetResourceInfo(uint32 id) { | 48 DevToolsNetLogObserver::GetResourceInfo(uint32 id) { |
33 RequestToInfoMap::iterator it = request_to_info_.find(id); | 49 RequestToInfoMap::iterator it = request_to_info_.find(id); |
34 if (it != request_to_info_.end()) | 50 if (it != request_to_info_.end()) |
35 return it->second; | 51 return it->second; |
36 return NULL; | 52 return NULL; |
37 } | 53 } |
38 | 54 |
39 void DevToolsNetLogObserver::OnAddEntry(net::NetLog::EventType type, | 55 void DevToolsNetLogObserver::OnAddEntry(net::NetLog::EventType type, |
40 const base::TimeTicks& time, | 56 const base::TimeTicks& time, |
41 const net::NetLog::Source& source, | 57 const net::NetLog::Source& source, |
42 net::NetLog::EventPhase phase, | 58 net::NetLog::EventPhase phase, |
43 net::NetLog::EventParameters* params) { | 59 net::NetLog::EventParameters* params) { |
60 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | |
61 BrowserThread::PostTask(BrowserThread::IO, | |
eroman
2010/11/16 17:51:14
Can we instead just return immediately if we aren'
mmenke
2010/11/16 21:34:49
I'm not quite sure, actually. Do we care about th
| |
62 FROM_HERE, | |
63 NewRunnableFunction( | |
64 AddEntryOnIOThread, | |
65 this, type, time, source, phase, | |
66 make_scoped_refptr(params))); | |
67 return; | |
68 } | |
69 | |
44 if (type == net::NetLog::TYPE_URL_REQUEST_START_JOB) { | 70 if (type == net::NetLog::TYPE_URL_REQUEST_START_JOB) { |
45 if (phase != net::NetLog::PHASE_BEGIN) | 71 if (phase != net::NetLog::PHASE_BEGIN) |
46 return; | 72 return; |
47 int load_flags = static_cast<URLRequestStartEventParameters*>(params)-> | 73 int load_flags = static_cast<URLRequestStartEventParameters*>(params)-> |
48 load_flags(); | 74 load_flags(); |
49 if (!(load_flags & net::LOAD_REPORT_RAW_HEADERS)) | 75 if (!(load_flags & net::LOAD_REPORT_RAW_HEADERS)) |
50 return; | 76 return; |
51 if (request_to_info_.size() > kMaxNumEntries) { | 77 if (request_to_info_.size() > kMaxNumEntries) { |
52 LOG(WARNING) << "The raw headers observer url request count has grown " | 78 LOG(WARNING) << "The raw headers observer url request count has grown " |
53 "larger than expected, resetting"; | 79 "larger than expected, resetting"; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 } | 119 } |
94 default: | 120 default: |
95 break; | 121 break; |
96 } | 122 } |
97 } | 123 } |
98 | 124 |
99 void DevToolsNetLogObserver::Attach(IOThread* io_thread) { | 125 void DevToolsNetLogObserver::Attach(IOThread* io_thread) { |
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
101 DCHECK(!instance_); | 127 DCHECK(!instance_); |
102 | 128 |
103 instance_ = new DevToolsNetLogObserver(io_thread->globals()->net_log.get()); | 129 instance_ = new DevToolsNetLogObserver(io_thread->net_log()); |
104 } | 130 } |
105 | 131 |
106 void DevToolsNetLogObserver::Detach() { | 132 void DevToolsNetLogObserver::Detach() { |
107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
108 DCHECK(instance_); | 134 DCHECK(instance_); |
109 | 135 |
110 delete instance_; | 136 delete instance_; |
111 instance_ = NULL; | 137 instance_ = NULL; |
112 } | 138 } |
113 | 139 |
(...skipping 10 matching lines...) Expand all Loading... | |
124 return; | 150 return; |
125 | 151 |
126 uint32 source_id = request->net_log().source().id; | 152 uint32 source_id = request->net_log().source().id; |
127 DevToolsNetLogObserver* dev_tools_net_log_observer = | 153 DevToolsNetLogObserver* dev_tools_net_log_observer = |
128 DevToolsNetLogObserver::GetInstance(); | 154 DevToolsNetLogObserver::GetInstance(); |
129 if (!dev_tools_net_log_observer) | 155 if (!dev_tools_net_log_observer) |
130 return; | 156 return; |
131 response->response_head.devtools_info = | 157 response->response_head.devtools_info = |
132 dev_tools_net_log_observer->GetResourceInfo(source_id); | 158 dev_tools_net_log_observer->GetResourceInfo(source_id); |
133 } | 159 } |
OLD | NEW |