| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 97 } |
| 94 default: | 98 default: |
| 95 break; | 99 break; |
| 96 } | 100 } |
| 97 } | 101 } |
| 98 | 102 |
| 99 void DevToolsNetLogObserver::Attach(IOThread* io_thread) { | 103 void DevToolsNetLogObserver::Attach(IOThread* io_thread) { |
| 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 101 DCHECK(!instance_); | 105 DCHECK(!instance_); |
| 102 | 106 |
| 103 instance_ = new DevToolsNetLogObserver(io_thread->globals()->net_log.get()); | 107 instance_ = new DevToolsNetLogObserver(io_thread->net_log()); |
| 104 } | 108 } |
| 105 | 109 |
| 106 void DevToolsNetLogObserver::Detach() { | 110 void DevToolsNetLogObserver::Detach() { |
| 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 108 DCHECK(instance_); | 112 DCHECK(instance_); |
| 109 | 113 |
| 110 delete instance_; | 114 delete instance_; |
| 111 instance_ = NULL; | 115 instance_ = NULL; |
| 112 } | 116 } |
| 113 | 117 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 124 return; | 128 return; |
| 125 | 129 |
| 126 uint32 source_id = request->net_log().source().id; | 130 uint32 source_id = request->net_log().source().id; |
| 127 DevToolsNetLogObserver* dev_tools_net_log_observer = | 131 DevToolsNetLogObserver* dev_tools_net_log_observer = |
| 128 DevToolsNetLogObserver::GetInstance(); | 132 DevToolsNetLogObserver::GetInstance(); |
| 129 if (!dev_tools_net_log_observer) | 133 if (!dev_tools_net_log_observer) |
| 130 return; | 134 return; |
| 131 response->response_head.devtools_info = | 135 response->response_head.devtools_info = |
| 132 dev_tools_net_log_observer->GetResourceInfo(source_id); | 136 dev_tools_net_log_observer->GetResourceInfo(source_id); |
| 133 } | 137 } |
| OLD | NEW |