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

Side by Side Diff: chrome/browser/extensions/api/webrequest/webrequest_time_tracker.h

Issue 9701039: Refactor folders in chrome/browser/extensions/api (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Small change to includes in extension_event_router.cc Created 8 years, 9 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEBREQUEST_WEBREQUEST_TIME_TRACKER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_WEBREQUEST_WEBREQUEST_TIME_TRACKER_H_
7 #pragma once
8
9 #include <map>
10 #include <queue>
11 #include <set>
12 #include <string>
13
14 #include "base/gtest_prod_util.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/time.h"
17 #include "googleurl/src/gurl.h"
18
19 namespace base {
20 class Time;
21 }
22
23 class ExtensionWebRequestTimeTrackerDelegate {
24 public:
25 virtual ~ExtensionWebRequestTimeTrackerDelegate() {}
26
27 // Notifies the delegate that |num_delayed_messages| of the last
28 // |total_num_messages| inspected messages were excessively/moderately
29 // delayed. Every excessively delayed message is also counted as a moderately
30 // delayed message.
31 virtual void NotifyExcessiveDelays(
32 void* profile,
33 size_t num_delayed_messages,
34 size_t total_num_messages,
35 const std::set<std::string>& extension_ids) = 0;
36 virtual void NotifyModerateDelays(
37 void* profile,
38 size_t num_delayed_messages,
39 size_t total_num_messages,
40 const std::set<std::string>& extension_ids) = 0;
41 };
42
43 // This class keeps monitors how much delay extensions add to network requests
44 // by using the webRequest API. If the delay is sufficient, we will warn the
45 // user that extensions are slowing down the browser.
46 class ExtensionWebRequestTimeTracker {
47 public:
48 ExtensionWebRequestTimeTracker();
49 ~ExtensionWebRequestTimeTracker();
50
51 // Records the time that a request was created.
52 void LogRequestStartTime(int64 request_id, const base::Time& start_time,
53 const GURL& url, void* profile);
54
55 // Records the time that a request either completed or encountered an error.
56 void LogRequestEndTime(int64 request_id, const base::Time& end_time);
57
58 // Records an additional delay for the given request caused by the given
59 // extension.
60 void IncrementExtensionBlockTime(
61 const std::string& extension_id,
62 int64 request_id,
63 const base::TimeDelta& block_time);
64
65 // Records an additional delay for the given request caused by all extensions
66 // combined.
67 void IncrementTotalBlockTime(
68 int64 request_id,
69 const base::TimeDelta& block_time);
70
71 // Called when an extension has canceled the given request.
72 void SetRequestCanceled(int64 request_id);
73
74 // Called when an extension has redirected the given request to another URL.
75 void SetRequestRedirected(int64 request_id);
76
77 // Takes ownership of |delegate|.
78 void SetDelegate(ExtensionWebRequestTimeTrackerDelegate* delegate);
79
80 private:
81 // Timing information for a single request.
82 struct RequestTimeLog {
83 GURL url; // used for debug purposes only
84 void* profile; // profile that created the request
85 bool completed;
86 base::Time request_start_time;
87 base::TimeDelta request_duration;
88 base::TimeDelta block_duration;
89 std::map<std::string, base::TimeDelta> extension_block_durations;
90 RequestTimeLog();
91 ~RequestTimeLog();
92 };
93
94 // Called after a request finishes, to analyze the delays and warn the user
95 // if necessary.
96 void Analyze(int64 request_id);
97
98 // Returns a list of all extension IDs that contributed to delay for |log|.
99 std::set<std::string> GetExtensionIds(const RequestTimeLog& log) const;
100
101 // A map of recent request IDs to timing info for each request.
102 std::map<int64, RequestTimeLog> request_time_logs_;
103
104 // A list of recent request IDs that we know about. Used to limit the size of
105 // the logs.
106 std::queue<int64> request_ids_;
107
108 // The set of recent requests that have been delayed either a large or
109 // moderate amount by extensions.
110 std::set<int64> excessive_delays_;
111 std::set<int64> moderate_delays_;
112
113 // Defaults to a delegate that sets warnings in the extension service.
114 scoped_ptr<ExtensionWebRequestTimeTrackerDelegate> delegate_;
115
116 FRIEND_TEST_ALL_PREFIXES(ExtensionWebRequestTimeTrackerTest, Basic);
117 FRIEND_TEST_ALL_PREFIXES(ExtensionWebRequestTimeTrackerTest,
118 IgnoreFastRequests);
119 FRIEND_TEST_ALL_PREFIXES(ExtensionWebRequestTimeTrackerTest,
120 CancelOrRedirect);
121 FRIEND_TEST_ALL_PREFIXES(ExtensionWebRequestTimeTrackerTest, Delays);
122
123 DISALLOW_COPY_AND_ASSIGN(ExtensionWebRequestTimeTracker);
124 };
125
126 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBREQUEST_WEBREQUEST_TIME_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698