Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: chrome/browser/extensions/extension_webrequest_time_tracker.h

Issue 7693004: Added tracking of time spent waiting on extensions to the webRequest API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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
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();
66 ~RequestTimeLog();
67 };
68
69 // Called after a request finishes, to analyze the delays and warn the user
70 // if necessary.
71 void Analyze(int64 request_id);
72
73 // A map of recent request IDs to timing info for each request.
74 std::map<int64, RequestTimeLog> request_time_logs_;
75
76 // A list of recent request IDs that we know about. Used to limit the size of
77 // the logs.
78 std::queue<int64> request_ids_;
79
80 // The set of recent requests that have been delayed either a large or
81 // moderate amount by extensions.
82 std::set<int64> excessive_delays_;
83 std::set<int64> moderate_delays_;
84
85 FRIEND_TEST_ALL_PREFIXES(ExtensionWebRequestTimeTrackerTest, Basic);
86 FRIEND_TEST_ALL_PREFIXES(ExtensionWebRequestTimeTrackerTest,
87 IgnoreFastRequests);
88 FRIEND_TEST_ALL_PREFIXES(ExtensionWebRequestTimeTrackerTest,
89 CancelOrRedirect);
90 FRIEND_TEST_ALL_PREFIXES(ExtensionWebRequestTimeTrackerTest, Delays);
91
92 DISALLOW_COPY_AND_ASSIGN(ExtensionWebRequestTimeTracker);
93 };
94
95 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_TIME_TRACKER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_webrequest_api.cc ('k') | chrome/browser/extensions/extension_webrequest_time_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698