Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/extension_webrequest_time_tracker.h" | 5 #include "chrome/browser/extensions/extension_webrequest_time_tracker.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 const double kThresholdExcessiveDelay = 0.50; | 28 const double kThresholdExcessiveDelay = 0.50; |
| 29 | 29 |
| 30 // If this many requests (of the past kMaxRequestsLogged) have had "too much" | 30 // If this many requests (of the past kMaxRequestsLogged) have had "too much" |
| 31 // delay, then we will warn the user. | 31 // delay, then we will warn the user. |
| 32 const size_t kNumModerateDelaysBeforeWarning = 50u; | 32 const size_t kNumModerateDelaysBeforeWarning = 50u; |
| 33 const size_t kNumExcessiveDelaysBeforeWarning = 10u; | 33 const size_t kNumExcessiveDelaysBeforeWarning = 10u; |
| 34 | 34 |
| 35 // Handles ExtensionWebRequestTimeTrackerDelegate calls on UI thread. | 35 // Handles ExtensionWebRequestTimeTrackerDelegate calls on UI thread. |
| 36 void NotifyNetworkDelaysOnUI(void* profile, | 36 void NotifyNetworkDelaysOnUI(void* profile, |
| 37 std::set<std::string> extension_ids) { | 37 std::set<std::string> extension_ids) { |
| 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
|
Matt Perry
2011/10/14 23:18:16
why not just comment out the implementation here?
| |
| 39 Profile* p = reinterpret_cast<Profile*>(profile); | 39 Profile* p = reinterpret_cast<Profile*>(profile); |
| 40 if (!p || !g_browser_process->profile_manager()->IsValidProfile(p)) | 40 if (!p || !g_browser_process->profile_manager()->IsValidProfile(p)) |
| 41 return; | 41 return; |
| 42 | 42 |
| 43 ExtensionWarningSet* warnings = | 43 ExtensionWarningSet* warnings = |
| 44 p->GetExtensionService()->extension_warnings(); | 44 p->GetExtensionService()->extension_warnings(); |
| 45 | 45 |
| 46 for (std::set<std::string>::const_iterator i = extension_ids.begin(); | 46 for (std::set<std::string>::const_iterator i = extension_ids.begin(); |
| 47 i != extension_ids.end(); ++i) { | 47 i != extension_ids.end(); ++i) { |
| 48 warnings->SetWarning(ExtensionWarningSet::kNetworkDelay, *i); | 48 warnings->SetWarning(ExtensionWarningSet::kNetworkDelay, *i); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 66 size_t num_delayed_messages, | 66 size_t num_delayed_messages, |
| 67 size_t total_num_messages, | 67 size_t total_num_messages, |
| 68 const std::set<std::string>& extension_ids) OVERRIDE; | 68 const std::set<std::string>& extension_ids) OVERRIDE; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 void DefaultDelegate::NotifyExcessiveDelays( | 71 void DefaultDelegate::NotifyExcessiveDelays( |
| 72 void* profile, | 72 void* profile, |
| 73 size_t num_delayed_messages, | 73 size_t num_delayed_messages, |
| 74 size_t total_num_messages, | 74 size_t total_num_messages, |
| 75 const std::set<std::string>& extension_ids) { | 75 const std::set<std::string>& extension_ids) { |
| 76 BrowserThread::PostTask( | 76 // TODO(battre) Enable warning the user if extensions misbehave as soon as we |
| 77 BrowserThread::UI, | 77 // have data that allows us to decide on reasonable limits for triggering the |
| 78 FROM_HERE, | 78 // warnings. |
| 79 base::Bind(&NotifyNetworkDelaysOnUI, profile, extension_ids)); | 79 // BrowserThread::PostTask( |
| 80 // BrowserThread::UI, | |
| 81 // FROM_HERE, | |
| 82 // base::Bind(&NotifyNetworkDelaysOnUI, profile, extension_ids)); | |
| 80 } | 83 } |
| 81 | 84 |
| 82 void DefaultDelegate::NotifyModerateDelays( | 85 void DefaultDelegate::NotifyModerateDelays( |
| 83 void* profile, | 86 void* profile, |
| 84 size_t num_delayed_messages, | 87 size_t num_delayed_messages, |
| 85 size_t total_num_messages, | 88 size_t total_num_messages, |
| 86 const std::set<std::string>& extension_ids) { | 89 const std::set<std::string>& extension_ids) { |
| 87 BrowserThread::PostTask( | 90 // TODO(battre) Enable warning the user if extensions misbehave as soon as we |
| 88 BrowserThread::UI, | 91 // have data that allows us to decide on reasonable limits for triggering the |
| 89 FROM_HERE, | 92 // warnings. |
| 90 base::Bind(&NotifyNetworkDelaysOnUI, profile, extension_ids)); | 93 // BrowserThread::PostTask( |
| 94 // BrowserThread::UI, | |
| 95 // FROM_HERE, | |
| 96 // base::Bind(&NotifyNetworkDelaysOnUI, profile, extension_ids)); | |
| 91 } | 97 } |
| 92 | 98 |
| 93 } // namespace | 99 } // namespace |
| 94 | 100 |
| 95 ExtensionWebRequestTimeTracker::RequestTimeLog::RequestTimeLog() | 101 ExtensionWebRequestTimeTracker::RequestTimeLog::RequestTimeLog() |
| 96 : profile(NULL), completed(false) { | 102 : profile(NULL), completed(false) { |
| 97 } | 103 } |
| 98 | 104 |
| 99 ExtensionWebRequestTimeTracker::RequestTimeLog::~RequestTimeLog() { | 105 ExtensionWebRequestTimeTracker::RequestTimeLog::~RequestTimeLog() { |
| 100 } | 106 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 RequestTimeLog& log = request_time_logs_[request_id]; | 178 RequestTimeLog& log = request_time_logs_[request_id]; |
| 173 | 179 |
| 174 // Ignore really short requests. Time spent on these is negligible, and any | 180 // Ignore really short requests. Time spent on these is negligible, and any |
| 175 // extra delay the extension adds is likely to be noise. | 181 // extra delay the extension adds is likely to be noise. |
| 176 if (log.request_duration.InMilliseconds() < kMinRequestTimeToCareMs) | 182 if (log.request_duration.InMilliseconds() < kMinRequestTimeToCareMs) |
| 177 return; | 183 return; |
| 178 | 184 |
| 179 double percentage = | 185 double percentage = |
| 180 log.block_duration.InMillisecondsF() / | 186 log.block_duration.InMillisecondsF() / |
| 181 log.request_duration.InMillisecondsF(); | 187 log.request_duration.InMillisecondsF(); |
| 182 LOG(ERROR) << "WR percent " << request_id << ": " << log.url << ": " << | 188 VLOG(1) << "WR percent " << request_id << ": " << log.url << ": " << |
| 183 log.block_duration.InMilliseconds() << "/" << | 189 log.block_duration.InMilliseconds() << "/" << |
| 184 log.request_duration.InMilliseconds() << " = " << percentage; | 190 log.request_duration.InMilliseconds() << " = " << percentage; |
| 185 | 191 |
| 186 // TODO(mpcomplete): blame a specific extension. Maybe go through the list | 192 // TODO(mpcomplete): blame a specific extension. Maybe go through the list |
| 187 // of recent requests and find the extension that has caused the most delays. | 193 // of recent requests and find the extension that has caused the most delays. |
| 188 if (percentage > kThresholdExcessiveDelay) { | 194 if (percentage > kThresholdExcessiveDelay) { |
| 189 excessive_delays_.insert(request_id); | 195 excessive_delays_.insert(request_id); |
| 190 if (excessive_delays_.size() > kNumExcessiveDelaysBeforeWarning) { | 196 if (excessive_delays_.size() > kNumExcessiveDelaysBeforeWarning) { |
| 191 LOG(ERROR) << "WR excessive delays:" << excessive_delays_.size(); | 197 VLOG(1) << "WR excessive delays:" << excessive_delays_.size(); |
| 192 if (delegate_.get()) { | 198 if (delegate_.get()) { |
| 193 delegate_->NotifyExcessiveDelays(log.profile, | 199 delegate_->NotifyExcessiveDelays(log.profile, |
| 194 excessive_delays_.size(), | 200 excessive_delays_.size(), |
| 195 request_ids_.size(), | 201 request_ids_.size(), |
| 196 GetExtensionIds(log)); | 202 GetExtensionIds(log)); |
| 197 } | 203 } |
| 198 } | 204 } |
| 199 } else if (percentage > kThresholdModerateDelay) { | 205 } else if (percentage > kThresholdModerateDelay) { |
| 200 moderate_delays_.insert(request_id); | 206 moderate_delays_.insert(request_id); |
| 201 if (moderate_delays_.size() + excessive_delays_.size() > | 207 if (moderate_delays_.size() + excessive_delays_.size() > |
| 202 kNumModerateDelaysBeforeWarning) { | 208 kNumModerateDelaysBeforeWarning) { |
| 203 LOG(ERROR) << "WR moderate delays:" << moderate_delays_.size(); | 209 VLOG(1) << "WR moderate delays:" << moderate_delays_.size(); |
| 204 if (delegate_.get()) { | 210 if (delegate_.get()) { |
| 205 delegate_->NotifyModerateDelays( | 211 delegate_->NotifyModerateDelays( |
| 206 log.profile, | 212 log.profile, |
| 207 moderate_delays_.size() + excessive_delays_.size(), | 213 moderate_delays_.size() + excessive_delays_.size(), |
| 208 request_ids_.size(), | 214 request_ids_.size(), |
| 209 GetExtensionIds(log)); | 215 GetExtensionIds(log)); |
| 210 } | 216 } |
| 211 } | 217 } |
| 212 } | 218 } |
| 213 } | 219 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 // When a request is redirected, we have no way of knowing how long the | 251 // When a request is redirected, we have no way of knowing how long the |
| 246 // request would have taken, so we can't say how much an extension slowed | 252 // request would have taken, so we can't say how much an extension slowed |
| 247 // down this request. Just ignore it. | 253 // down this request. Just ignore it. |
| 248 request_time_logs_.erase(request_id); | 254 request_time_logs_.erase(request_id); |
| 249 } | 255 } |
| 250 | 256 |
| 251 void ExtensionWebRequestTimeTracker::SetDelegate( | 257 void ExtensionWebRequestTimeTracker::SetDelegate( |
| 252 ExtensionWebRequestTimeTrackerDelegate* delegate) { | 258 ExtensionWebRequestTimeTrackerDelegate* delegate) { |
| 253 delegate_.reset(delegate); | 259 delegate_.reset(delegate); |
| 254 } | 260 } |
| OLD | NEW |