OLD | NEW |
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 "content/browser/loader/netlog_observer.h" | 5 #include "content/browser/loader/netlog_observer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "content/browser/loader/resource_request_info_impl.h" | 11 #include "content/browser/loader/resource_request_info_impl.h" |
12 #include "content/public/common/resource_response.h" | 12 #include "content/public/common/resource_response.h" |
13 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
14 #include "net/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
15 #include "net/http/http_util.h" | 15 #include "net/http/http_util.h" |
| 16 #include "net/log/net_log_capture_mode.h" |
| 17 #include "net/log/net_log_entry.h" |
16 #include "net/log/net_log_event_type.h" | 18 #include "net/log/net_log_event_type.h" |
17 #include "net/log/net_log_source_type.h" | 19 #include "net/log/net_log_source_type.h" |
| 20 #include "net/log/net_log_with_source.h" |
18 #include "net/spdy/spdy_header_block.h" | 21 #include "net/spdy/spdy_header_block.h" |
19 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
20 #include "net/url_request/url_request_netlog_params.h" | 23 #include "net/url_request/url_request_netlog_params.h" |
21 | 24 |
22 namespace content { | 25 namespace content { |
23 const size_t kMaxNumEntries = 1000; | 26 const size_t kMaxNumEntries = 1000; |
24 | 27 |
25 // static | 28 // static |
26 NetLogObserver* NetLogObserver::instance_ = NULL; | 29 NetLogObserver* NetLogObserver::instance_ = NULL; |
27 | 30 |
28 // static | 31 // static |
29 base::LazyInstance<std::unique_ptr<base::ThreadChecker>>::Leaky | 32 base::LazyInstance<std::unique_ptr<base::ThreadChecker>>::Leaky |
30 NetLogObserver::io_thread_checker_; | 33 NetLogObserver::io_thread_checker_; |
31 | 34 |
32 NetLogObserver::NetLogObserver() {} | 35 NetLogObserver::NetLogObserver() {} |
33 | 36 |
34 NetLogObserver::~NetLogObserver() {} | 37 NetLogObserver::~NetLogObserver() {} |
35 | 38 |
36 NetLogObserver::ResourceInfo* NetLogObserver::GetResourceInfo(uint32_t id) { | 39 NetLogObserver::ResourceInfo* NetLogObserver::GetResourceInfo(uint32_t id) { |
37 RequestToInfoMap::iterator it = request_to_info_.find(id); | 40 RequestToInfoMap::iterator it = request_to_info_.find(id); |
38 if (it != request_to_info_.end()) | 41 if (it != request_to_info_.end()) |
39 return it->second.get(); | 42 return it->second.get(); |
40 return NULL; | 43 return NULL; |
41 } | 44 } |
42 | 45 |
43 void NetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { | 46 void NetLogObserver::OnAddEntry(const net::NetLogEntry& entry) { |
44 DCHECK(io_thread_checker_.Get().get()); | 47 DCHECK(io_thread_checker_.Get().get()); |
45 | 48 |
46 // The events that the Observer is interested in only occur on the IO thread. | 49 // The events that the Observer is interested in only occur on the IO thread. |
47 if (!io_thread_checker_.Get()->CalledOnValidThread()) | 50 if (!io_thread_checker_.Get()->CalledOnValidThread()) |
48 return; | 51 return; |
49 | 52 |
50 if (entry.source().type == net::NetLogSourceType::URL_REQUEST) | 53 if (entry.source().type == net::NetLogSourceType::URL_REQUEST) |
51 OnAddURLRequestEntry(entry); | 54 OnAddURLRequestEntry(entry); |
52 } | 55 } |
53 | 56 |
54 void NetLogObserver::OnAddURLRequestEntry(const net::NetLog::Entry& entry) { | 57 void NetLogObserver::OnAddURLRequestEntry(const net::NetLogEntry& entry) { |
55 bool is_begin = entry.phase() == net::NetLogEventPhase::BEGIN; | 58 bool is_begin = entry.phase() == net::NetLogEventPhase::BEGIN; |
56 bool is_end = entry.phase() == net::NetLogEventPhase::END; | 59 bool is_end = entry.phase() == net::NetLogEventPhase::END; |
57 | 60 |
58 if (entry.type() == net::NetLogEventType::URL_REQUEST_START_JOB) { | 61 if (entry.type() == net::NetLogEventType::URL_REQUEST_START_JOB) { |
59 if (is_begin) { | 62 if (is_begin) { |
60 if (request_to_info_.size() > kMaxNumEntries) { | 63 if (request_to_info_.size() > kMaxNumEntries) { |
61 LOG(WARNING) << "The raw headers observer url request count has grown " | 64 LOG(WARNING) << "The raw headers observer url request count has grown " |
62 "larger than expected, resetting"; | 65 "larger than expected, resetting"; |
63 request_to_info_.clear(); | 66 request_to_info_.clear(); |
64 } | 67 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 203 |
201 uint32_t source_id = request->net_log().source().id; | 204 uint32_t source_id = request->net_log().source().id; |
202 NetLogObserver* dev_tools_net_log_observer = NetLogObserver::GetInstance(); | 205 NetLogObserver* dev_tools_net_log_observer = NetLogObserver::GetInstance(); |
203 if (dev_tools_net_log_observer == NULL) | 206 if (dev_tools_net_log_observer == NULL) |
204 return; | 207 return; |
205 response->head.devtools_info = | 208 response->head.devtools_info = |
206 dev_tools_net_log_observer->GetResourceInfo(source_id); | 209 dev_tools_net_log_observer->GetResourceInfo(source_id); |
207 } | 210 } |
208 | 211 |
209 } // namespace content | 212 } // namespace content |
OLD | NEW |