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

Side by Side Diff: content/renderer/resource_dispatch_throttler.h

Issue 847883002: Reland "Throttle resource message requests during user interaction" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review Created 5 years, 11 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 2015 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 CONTENT_RENDERER_RESOURCE_DISPATCH_THROTTLER_H_
6 #define CONTENT_RENDERER_RESOURCE_DISPATCH_THROTTLER_H_
7
8 #include <map>
9
10 #include "base/threading/thread_checker.h"
11 #include "base/time/time.h"
12 #include "base/timer/timer.h"
13 #include "content/common/content_export.h"
14 #include "ipc/ipc_sender.h"
15
16 namespace content {
17
18 class RendererScheduler;
19
20 // Utility class for throttling a stream of resource requests targetted to a
21 // specific IPC sender. The throttling itself is very basic:
22 // * When there is no high-priority work imminent to the main thread, as
23 // indicated by the RendererScheduler, throttling is disabled.
24 // * When >= N requests have been sent in a given time window, requests are
25 // throttled. A timer periodically flushes a portion of the queued requests
26 // until all such requests have been flushed.
27 // TODO(jdduke): Remove this class after resource requests become sufficiently
28 // cheap on the IO thread, crbug.com/440037.
29 class CONTENT_EXPORT ResourceDispatchThrottler : public IPC::Sender {
Sami 2015/01/27 14:06:06 Should this live in content/renderer/scheduler? It
jdduke (slow) 2015/01/27 16:59:09 Yeah, I had it there originally, and I'd be happy
30 public:
31 // |flush_period| and |max_requests_per_flush| must be strictly positive
32 // in duration/value.
33 ResourceDispatchThrottler(IPC::Sender* proxied_sender,
34 RendererScheduler* scheduler,
35 base::TimeDelta flush_period,
36 uint32 max_requests_per_flush);
37 ~ResourceDispatchThrottler() override;
38
39 // IPC::Sender implementation:
40 bool Send(IPC::Message* msg) override;
41
42 private:
43 friend class ResourceDispatchThrottlerTest;
44
45 // Virtual for testing.
46 virtual base::TimeTicks Now() const;
47 virtual void ScheduleFlush();
48
49 void Flush();
50 bool ForwardRequest(IPC::Message* msg);
51 bool OnRequestResource(IPC::Message* msg);
52 bool OnDidChangePriority(IPC::Message* msg);
53 bool OnReleaseDownloadedFile(IPC::Message* msg);
54 bool OnCancelRequest(IPC::Message* msg);
55
56 base::ThreadChecker thread_checker_;
57
58 IPC::Sender* const proxied_sender_;
59 RendererScheduler* const scheduler_;
60 const base::TimeDelta flush_period_;
61 const uint32 max_requests_per_flush_;
62
63 base::Timer flush_timer_;
64 base::TimeTicks last_sent_request_time_;
65 uint32 sent_requests_since_last_flush_;
66 std::map<int, IPC::Message*> throttled_requests_;
67 bool is_forwarding_request_;
68
69 DISALLOW_COPY_AND_ASSIGN(ResourceDispatchThrottler);
70 };
71
72 } // namespace content
73
74 #endif // CONTENT_RENDERER_RESOURCE_DISPATCH_THROTTLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698