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

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

Issue 8176001: Warn user in case extension delays network traffic too much. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed Glen's comments Created 9 years, 2 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
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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/memory/singleton.h" 14 #include "base/memory/singleton.h"
15 #include "base/time.h" 15 #include "base/time.h"
16 #include "chrome/browser/extensions/extension_function.h" 16 #include "chrome/browser/extensions/extension_function.h"
17 #include "chrome/browser/extensions/extension_webrequest_time_tracker.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/extensions/url_pattern_set.h" 19 #include "chrome/common/extensions/url_pattern_set.h"
19 #include "ipc/ipc_message.h" 20 #include "ipc/ipc_message.h"
20 #include "net/base/completion_callback.h" 21 #include "net/base/completion_callback.h"
21 #include "net/http/http_request_headers.h" 22 #include "net/http/http_request_headers.h"
22 #include "webkit/glue/resource_type.h" 23 #include "webkit/glue/resource_type.h"
23 24
24 class ExtensionInfoMap; 25 class ExtensionInfoMap;
25 class ExtensionWebRequestTimeTracker;
26 class GURL; 26 class GURL;
27 27
28 namespace base { 28 namespace base {
29 class DictionaryValue; 29 class DictionaryValue;
30 class ListValue; 30 class ListValue;
31 class StringValue; 31 class StringValue;
32 } 32 }
33 33
34 namespace net { 34 namespace net {
35 class AuthChallengeInfo; 35 class AuthChallengeInfo;
36 class HostPortPair; 36 class HostPortPair;
37 class HttpRequestHeaders; 37 class HttpRequestHeaders;
38 class HttpResponseHeaders; 38 class HttpResponseHeaders;
39 class URLRequest; 39 class URLRequest;
40 } 40 }
41 41
42 // This class observes network events and routes them to the appropriate 42 // This class observes network events and routes them to the appropriate
43 // extensions listening to those events. All methods must be called on the IO 43 // extensions listening to those events. All methods must be called on the IO
44 // thread unless otherwise specified. 44 // thread unless otherwise specified.
45 class ExtensionWebRequestEventRouter { 45 class ExtensionWebRequestEventRouter
46 : public ExtensionWebRequestTimeTrackerDelegate {
46 public: 47 public:
47 enum EventTypes { 48 enum EventTypes {
48 kInvalidEvent = 0, 49 kInvalidEvent = 0,
49 kOnBeforeRequest = 1 << 0, 50 kOnBeforeRequest = 1 << 0,
50 kOnBeforeSendHeaders = 1 << 1, 51 kOnBeforeSendHeaders = 1 << 1,
51 kOnSendHeaders = 1 << 2, 52 kOnSendHeaders = 1 << 2,
52 kOnHeadersReceived = 1 << 3, 53 kOnHeadersReceived = 1 << 3,
53 kOnBeforeRedirect = 1 << 4, 54 kOnBeforeRedirect = 1 << 4,
54 kOnAuthRequired = 1 << 5, 55 kOnAuthRequired = 1 << 5,
55 kOnResponseStarted = 1 << 6, 56 kOnResponseStarted = 1 << 6,
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 struct EventListener; 265 struct EventListener;
265 struct BlockedRequest; 266 struct BlockedRequest;
266 typedef std::map<std::string, std::set<EventListener> > ListenerMapForProfile; 267 typedef std::map<std::string, std::set<EventListener> > ListenerMapForProfile;
267 typedef std::map<void*, ListenerMapForProfile> ListenerMap; 268 typedef std::map<void*, ListenerMapForProfile> ListenerMap;
268 typedef std::map<uint64, BlockedRequest> BlockedRequestMap; 269 typedef std::map<uint64, BlockedRequest> BlockedRequestMap;
269 // Map of request_id -> bit vector of EventTypes already signaled 270 // Map of request_id -> bit vector of EventTypes already signaled
270 typedef std::map<uint64, int> SignaledRequestMap; 271 typedef std::map<uint64, int> SignaledRequestMap;
271 typedef std::map<void*, void*> CrossProfileMap; 272 typedef std::map<void*, void*> CrossProfileMap;
272 273
273 ExtensionWebRequestEventRouter(); 274 ExtensionWebRequestEventRouter();
274 ~ExtensionWebRequestEventRouter(); 275 virtual ~ExtensionWebRequestEventRouter();
275 276
276 bool DispatchEvent( 277 bool DispatchEvent(
277 void* profile, 278 void* profile,
278 net::URLRequest* request, 279 net::URLRequest* request,
279 const std::vector<const EventListener*>& listeners, 280 const std::vector<const EventListener*>& listeners,
280 const base::ListValue& args); 281 const base::ListValue& args);
281 282
282 // Returns a list of event listeners that care about the given event, based 283 // Returns a list of event listeners that care about the given event, based
283 // on their filter parameters. |extra_info_spec| will contain the combined 284 // on their filter parameters. |extra_info_spec| will contain the combined
284 // set of extra_info_spec flags that every matching listener asked for. 285 // set of extra_info_spec flags that every matching listener asked for.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 void MergeOnBeforeRequestResponses( 341 void MergeOnBeforeRequestResponses(
341 BlockedRequest* request, 342 BlockedRequest* request,
342 std::list<std::string>* conflicting_extensions) const; 343 std::list<std::string>* conflicting_extensions) const;
343 void MergeOnBeforeSendHeadersResponses( 344 void MergeOnBeforeSendHeadersResponses(
344 BlockedRequest* request, 345 BlockedRequest* request,
345 std::list<std::string>* conflicting_extensions) const; 346 std::list<std::string>* conflicting_extensions) const;
346 void MergeOnHeadersReceivedResponses( 347 void MergeOnHeadersReceivedResponses(
347 BlockedRequest* request, 348 BlockedRequest* request,
348 std::list<std::string>* conflicting_extensions) const; 349 std::list<std::string>* conflicting_extensions) const;
349 350
351 // Implementation for ExtensionWebRequestTimeTrackerDelegate:
352 virtual void NotifyExcessiveDelays(
353 void* profile,
354 size_t num_delayed_messages,
355 size_t total_num_messages,
356 const std::set<std::string>& extension_ids) OVERRIDE;
357 virtual void NotifyModerateDelays(
358 void* profile,
359 size_t num_delayed_messages,
360 size_t total_num_messages,
361 const std::set<std::string>& extension_ids) OVERRIDE;
362
350 // A map for each profile that maps an event name to a set of extensions that 363 // A map for each profile that maps an event name to a set of extensions that
351 // are listening to that event. 364 // are listening to that event.
352 ListenerMap listeners_; 365 ListenerMap listeners_;
353 366
354 // A map of network requests that are waiting for at least one event handler 367 // A map of network requests that are waiting for at least one event handler
355 // to respond. 368 // to respond.
356 BlockedRequestMap blocked_requests_; 369 BlockedRequestMap blocked_requests_;
357 370
358 // A map of request ids to a bitvector indicating which events have been 371 // A map of request ids to a bitvector indicating which events have been
359 // signaled and should not be sent again. 372 // signaled and should not be sent again.
(...skipping 23 matching lines...) Expand all
383 }; 396 };
384 397
385 class WebRequestHandlerBehaviorChanged : public AsyncExtensionFunction { 398 class WebRequestHandlerBehaviorChanged : public AsyncExtensionFunction {
386 public: 399 public:
387 virtual bool RunImpl(); 400 virtual bool RunImpl();
388 DECLARE_EXTENSION_FUNCTION_NAME( 401 DECLARE_EXTENSION_FUNCTION_NAME(
389 "experimental.webRequest.handlerBehaviorChanged"); 402 "experimental.webRequest.handlerBehaviorChanged");
390 }; 403 };
391 404
392 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_ 405 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698