| 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/devtools/devtools_netlog_observer.h" | 5 #include "content/browser/devtools/devtools_netlog_observer.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/browser/content_browser_client.h" | 10 #include "content/public/browser/content_browser_client.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // The events that the Observer is interested in only occur on the IO thread. | 39 // The events that the Observer is interested in only occur on the IO thread. |
| 40 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) | 40 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) |
| 41 return; | 41 return; |
| 42 | 42 |
| 43 if (entry.source().type == net::NetLog::SOURCE_URL_REQUEST) | 43 if (entry.source().type == net::NetLog::SOURCE_URL_REQUEST) |
| 44 OnAddURLRequestEntry(entry); | 44 OnAddURLRequestEntry(entry); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void DevToolsNetLogObserver::OnAddURLRequestEntry( | 47 void DevToolsNetLogObserver::OnAddURLRequestEntry( |
| 48 const net::NetLog::Entry& entry) { | 48 const net::NetLog::Entry& entry) { |
| 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 49 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 50 | 50 |
| 51 bool is_begin = entry.phase() == net::NetLog::PHASE_BEGIN; | 51 bool is_begin = entry.phase() == net::NetLog::PHASE_BEGIN; |
| 52 bool is_end = entry.phase() == net::NetLog::PHASE_END; | 52 bool is_end = entry.phase() == net::NetLog::PHASE_END; |
| 53 | 53 |
| 54 if (entry.type() == net::NetLog::TYPE_URL_REQUEST_START_JOB) { | 54 if (entry.type() == net::NetLog::TYPE_URL_REQUEST_START_JOB) { |
| 55 if (is_begin) { | 55 if (is_begin) { |
| 56 int load_flags; | 56 int load_flags; |
| 57 scoped_ptr<base::Value> event_param(entry.ParametersToValue()); | 57 scoped_ptr<base::Value> event_param(entry.ParametersToValue()); |
| 58 if (!net::StartEventLoadFlagsFromEventParams(event_param.get(), | 58 if (!net::StartEventLoadFlagsFromEventParams(event_param.get(), |
| 59 &load_flags)) { | 59 &load_flags)) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 void DevToolsNetLogObserver::Attach() { | 167 void DevToolsNetLogObserver::Attach() { |
| 168 DCHECK(!instance_); | 168 DCHECK(!instance_); |
| 169 net::NetLog* net_log = GetContentClient()->browser()->GetNetLog(); | 169 net::NetLog* net_log = GetContentClient()->browser()->GetNetLog(); |
| 170 if (net_log) { | 170 if (net_log) { |
| 171 instance_ = new DevToolsNetLogObserver(); | 171 instance_ = new DevToolsNetLogObserver(); |
| 172 net_log->AddThreadSafeObserver(instance_, net::NetLog::LOG_ALL_BUT_BYTES); | 172 net_log->AddThreadSafeObserver(instance_, net::NetLog::LOG_ALL_BUT_BYTES); |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 | 175 |
| 176 void DevToolsNetLogObserver::Detach() { | 176 void DevToolsNetLogObserver::Detach() { |
| 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 177 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 178 | 178 |
| 179 if (instance_) { | 179 if (instance_) { |
| 180 // Safest not to do this in the destructor to maintain thread safety across | 180 // Safest not to do this in the destructor to maintain thread safety across |
| 181 // refactorings. | 181 // refactorings. |
| 182 instance_->net_log()->RemoveThreadSafeObserver(instance_); | 182 instance_->net_log()->RemoveThreadSafeObserver(instance_); |
| 183 delete instance_; | 183 delete instance_; |
| 184 instance_ = NULL; | 184 instance_ = NULL; |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 | 187 |
| 188 DevToolsNetLogObserver* DevToolsNetLogObserver::GetInstance() { | 188 DevToolsNetLogObserver* DevToolsNetLogObserver::GetInstance() { |
| 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 189 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 190 | 190 |
| 191 return instance_; | 191 return instance_; |
| 192 } | 192 } |
| 193 | 193 |
| 194 // static | 194 // static |
| 195 void DevToolsNetLogObserver::PopulateResponseInfo( | 195 void DevToolsNetLogObserver::PopulateResponseInfo( |
| 196 net::URLRequest* request, | 196 net::URLRequest* request, |
| 197 ResourceResponse* response) { | 197 ResourceResponse* response) { |
| 198 if (!(request->load_flags() & net::LOAD_REPORT_RAW_HEADERS)) | 198 if (!(request->load_flags() & net::LOAD_REPORT_RAW_HEADERS)) |
| 199 return; | 199 return; |
| 200 | 200 |
| 201 uint32 source_id = request->net_log().source().id; | 201 uint32 source_id = request->net_log().source().id; |
| 202 DevToolsNetLogObserver* dev_tools_net_log_observer = | 202 DevToolsNetLogObserver* dev_tools_net_log_observer = |
| 203 DevToolsNetLogObserver::GetInstance(); | 203 DevToolsNetLogObserver::GetInstance(); |
| 204 if (dev_tools_net_log_observer == NULL) | 204 if (dev_tools_net_log_observer == NULL) |
| 205 return; | 205 return; |
| 206 response->head.devtools_info = | 206 response->head.devtools_info = |
| 207 dev_tools_net_log_observer->GetResourceInfo(source_id); | 207 dev_tools_net_log_observer->GetResourceInfo(source_id); |
| 208 } | 208 } |
| 209 | 209 |
| 210 } // namespace content | 210 } // namespace content |
| OLD | NEW |