OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_TIME_TRACKER_H_ | |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_TIME_TRACKER_H_ | |
7 #pragma once | |
8 | |
9 #include <map> | |
10 #include <queue> | |
11 #include <set> | |
12 #include <string> | |
13 | |
14 #include "base/time.h" | |
15 #include "base/gtest_prod_util.h" | |
16 #include "googleurl/src/gurl.h" | |
17 | |
18 namespace base { | |
19 class Time; | |
20 } | |
21 | |
22 // This class keeps monitors how much delay extensions add to network requests | |
battre
2011/08/22 16:23:47
nit: -keeps
| |
23 // by using the webRequest API. If the delay is sufficient, we will warn the | |
24 // user that extensions are slowing down the browser. | |
25 class ExtensionWebRequestTimeTracker { | |
26 public: | |
27 ExtensionWebRequestTimeTracker(); | |
28 ~ExtensionWebRequestTimeTracker(); | |
29 | |
30 // Records the time that a request was created. | |
31 void LogRequestStartTime(int64 request_id, const base::Time& start_time, | |
32 const GURL& url); | |
33 | |
34 // Records the time that a request either completed or encountered an error. | |
35 void LogRequestEndTime(int64 request_id, const base::Time& end_time); | |
36 | |
37 // Records an additional delay for the given request caused by the given | |
38 // extension. | |
39 void IncrementExtensionBlockTime( | |
40 const std::string& extension_id, | |
41 int64 request_id, | |
42 const base::TimeDelta& block_time); | |
43 | |
44 // Records an additional delay for the given request caused by all extensions | |
45 // combined. | |
46 void IncrementTotalBlockTime( | |
47 int64 request_id, | |
48 const base::TimeDelta& block_time); | |
49 | |
50 // Called when an extension has canceled the given request. | |
51 void SetRequestCanceled(int64 request_id); | |
52 | |
53 // Called when an extension has redirected the given request to another URL. | |
54 void SetRequestRedirected(int64 request_id); | |
55 | |
56 private: | |
57 // Timing information for a single request. | |
58 struct RequestTimeLog { | |
59 GURL url; // used for debug purposes only | |
60 bool completed; | |
61 base::Time request_start_time; | |
62 base::TimeDelta request_duration; | |
63 base::TimeDelta block_duration; | |
64 std::map<std::string, base::TimeDelta> extension_block_durations; | |
65 RequestTimeLog() : completed(false) {} | |
66 }; | |
67 | |
68 // Called after a request finishes, to analyze the delays and warn the user | |
69 // if necessary. | |
70 void Analyze(int64 request_id); | |
71 | |
72 // A map of recent request IDs to timing info for each request. | |
73 std::map<int64, RequestTimeLog> request_time_logs_; | |
74 | |
75 // A list of recent request IDs that we know about. Used to limit the size of | |
76 // the logs. | |
77 std::queue<int64> request_ids_; | |
78 | |
79 // The set of recent requests that have been delayed either a large or | |
80 // moderate amount by extensions. | |
81 std::set<int64> excessive_delays_; | |
82 std::set<int64> moderate_delays_; | |
83 | |
84 FRIEND_TEST_ALL_PREFIXES(ExtensionWebRequestTimeTrackerTest, Basic); | |
85 FRIEND_TEST_ALL_PREFIXES(ExtensionWebRequestTimeTrackerTest, | |
86 IgnoreFastRequests); | |
87 FRIEND_TEST_ALL_PREFIXES(ExtensionWebRequestTimeTrackerTest, | |
88 CancelOrRedirect); | |
89 FRIEND_TEST_ALL_PREFIXES(ExtensionWebRequestTimeTrackerTest, Delays); | |
90 | |
91 DISALLOW_COPY_AND_ASSIGN(ExtensionWebRequestTimeTracker); | |
92 }; | |
93 | |
94 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_TIME_TRACKER_H_ | |
OLD | NEW |