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

Side by Side Diff: content/renderer/scheduler/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: Pull out ThreadChecker fix Created 5 years, 10 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_SCHEDULER_RESOURCE_DISPATCH_THROTTLER_H_
6 #define CONTENT_RENDERER_SCHEDULER_RESOURCE_DISPATCH_THROTTLER_H_
7
8 #include <deque>
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 {
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 ResourceDispatchThrottlerForTest;
44
45 // Virtual for testing.
46 virtual base::TimeTicks Now() const;
47 virtual void ScheduleFlush();
48
49 void Flush();
50 void FlushAll();
51 bool ForwardMessage(IPC::Message* msg);
52
53 base::ThreadChecker thread_checker_;
54
55 IPC::Sender* const proxied_sender_;
56 RendererScheduler* const scheduler_;
57 const base::TimeDelta flush_period_;
58 const uint32 max_requests_per_flush_;
59
60 base::Timer flush_timer_;
61 base::TimeTicks last_sent_request_time_;
62 uint32 sent_requests_since_last_flush_;
63 std::deque<IPC::Message*> throttled_messages_;
64
65 DISALLOW_COPY_AND_ASSIGN(ResourceDispatchThrottler);
66 };
67
68 } // namespace content
69
70 #endif // CONTENT_RENDERER_SCHEDULER_RESOURCE_DISPATCH_THROTTLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698