| 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 const size_t kMaxNumEntries = 1000; | 17 const size_t kMaxNumEntries = 1000; |
| 18 | 18 |
| 19 DevToolsNetLogObserver* DevToolsNetLogObserver::instance_ = NULL; | 19 DevToolsNetLogObserver* DevToolsNetLogObserver::instance_ = NULL; |
| 20 | 20 |
| 21 DevToolsNetLogObserver::DevToolsNetLogObserver(ChromeNetLog* chrome_net_log) | 21 DevToolsNetLogObserver::DevToolsNetLogObserver(ChromeNetLog* chrome_net_log) |
| 22 : ChromeNetLog::Observer(net::NetLog::LOG_ALL_BUT_BYTES), | 22 : ChromeNetLog::ThreadSafeObserver(net::NetLog::LOG_ALL_BUT_BYTES), |
| 23 chrome_net_log_(chrome_net_log) { | 23 chrome_net_log_(chrome_net_log) { |
| 24 chrome_net_log_->AddObserver(this); | 24 chrome_net_log_->AddObserver(this); |
| 25 } | 25 } |
| 26 | 26 |
| 27 DevToolsNetLogObserver::~DevToolsNetLogObserver() { | 27 DevToolsNetLogObserver::~DevToolsNetLogObserver() { |
| 28 chrome_net_log_->RemoveObserver(this); | 28 chrome_net_log_->RemoveObserver(this); |
| 29 } | 29 } |
| 30 | 30 |
| 31 DevToolsNetLogObserver::ResourceInfo* | 31 DevToolsNetLogObserver::ResourceInfo* |
| 32 DevToolsNetLogObserver::GetResourceInfo(uint32 id) { | 32 DevToolsNetLogObserver::GetResourceInfo(uint32 id) { |
| 33 RequestToInfoMap::iterator it = request_to_info_.find(id); | 33 RequestToInfoMap::iterator it = request_to_info_.find(id); |
| 34 if (it != request_to_info_.end()) | 34 if (it != request_to_info_.end()) |
| 35 return it->second; | 35 return it->second; |
| 36 return NULL; | 36 return NULL; |
| 37 } | 37 } |
| 38 | 38 |
| 39 void DevToolsNetLogObserver::OnAddEntry(net::NetLog::EventType type, | 39 void DevToolsNetLogObserver::OnAddEntry(net::NetLog::EventType type, |
| 40 const base::TimeTicks& time, | 40 const base::TimeTicks& time, |
| 41 const net::NetLog::Source& source, | 41 const net::NetLog::Source& source, |
| 42 net::NetLog::EventPhase phase, | 42 net::NetLog::EventPhase phase, |
| 43 net::NetLog::EventParameters* params) { | 43 net::NetLog::EventParameters* params) { |
| 44 // The events that the Observer is interested in only occur on the IO thread. |
| 45 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) |
| 46 return; |
| 47 |
| 44 if (type == net::NetLog::TYPE_URL_REQUEST_START_JOB) { | 48 if (type == net::NetLog::TYPE_URL_REQUEST_START_JOB) { |
| 45 if (phase != net::NetLog::PHASE_BEGIN) | 49 if (phase != net::NetLog::PHASE_BEGIN) |
| 46 return; | 50 return; |
| 47 int load_flags = static_cast<URLRequestStartEventParameters*>(params)-> | 51 int load_flags = static_cast<URLRequestStartEventParameters*>(params)-> |
| 48 load_flags(); | 52 load_flags(); |
| 49 if (!(load_flags & net::LOAD_REPORT_RAW_HEADERS)) | 53 if (!(load_flags & net::LOAD_REPORT_RAW_HEADERS)) |
| 50 return; | 54 return; |
| 51 if (request_to_info_.size() > kMaxNumEntries) { | 55 if (request_to_info_.size() > kMaxNumEntries) { |
| 52 LOG(WARNING) << "The raw headers observer url request count has grown " | 56 LOG(WARNING) << "The raw headers observer url request count has grown " |
| 53 "larger than expected, resetting"; | 57 "larger than expected, resetting"; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 105 } |
| 102 default: | 106 default: |
| 103 break; | 107 break; |
| 104 } | 108 } |
| 105 } | 109 } |
| 106 | 110 |
| 107 void DevToolsNetLogObserver::Attach(IOThread* io_thread) { | 111 void DevToolsNetLogObserver::Attach(IOThread* io_thread) { |
| 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 109 DCHECK(!instance_); | 113 DCHECK(!instance_); |
| 110 | 114 |
| 111 instance_ = new DevToolsNetLogObserver(io_thread->globals()->net_log.get()); | 115 instance_ = new DevToolsNetLogObserver(io_thread->net_log()); |
| 112 } | 116 } |
| 113 | 117 |
| 114 void DevToolsNetLogObserver::Detach() { | 118 void DevToolsNetLogObserver::Detach() { |
| 115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 116 DCHECK(instance_); | 120 DCHECK(instance_); |
| 117 | 121 |
| 118 delete instance_; | 122 delete instance_; |
| 119 instance_ = NULL; | 123 instance_ = NULL; |
| 120 } | 124 } |
| 121 | 125 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 132 return; | 136 return; |
| 133 | 137 |
| 134 uint32 source_id = request->net_log().source().id; | 138 uint32 source_id = request->net_log().source().id; |
| 135 DevToolsNetLogObserver* dev_tools_net_log_observer = | 139 DevToolsNetLogObserver* dev_tools_net_log_observer = |
| 136 DevToolsNetLogObserver::GetInstance(); | 140 DevToolsNetLogObserver::GetInstance(); |
| 137 if (!dev_tools_net_log_observer) | 141 if (!dev_tools_net_log_observer) |
| 138 return; | 142 return; |
| 139 response->response_head.devtools_info = | 143 response->response_head.devtools_info = |
| 140 dev_tools_net_log_observer->GetResourceInfo(source_id); | 144 dev_tools_net_log_observer->GetResourceInfo(source_id); |
| 141 } | 145 } |
| OLD | NEW |