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

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: Rebase 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_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 class CONTENT_EXPORT ResourceDispatchThrottler : public IPC::Sender {
28 public:
29 // |flush_period| and |max_requests_per_flush| must be strictly positive
30 // in duration/value.
31 ResourceDispatchThrottler(IPC::Sender* proxied_sender,
32 RendererScheduler* scheduler,
33 base::TimeDelta flush_period,
34 uint32 max_requests_per_flush);
35 ~ResourceDispatchThrottler() override;
36
37 // IPC::Sender implementation:
38 bool Send(IPC::Message* msg) override;
39
40 private:
41 friend class ResourceDispatchThrottlerTest;
42
43 // Virtual for testing.
44 virtual base::TimeTicks Now() const;
45 virtual void ScheduleFlush();
46
47 void Flush();
48 bool ForwardRequest(IPC::Message* msg);
49 bool OnRequestResource(IPC::Message* msg);
50 bool OnDidChangePriority(IPC::Message* msg);
51 bool OnReleaseDownloadedFile(IPC::Message* msg);
52 bool OnCancelRequest(IPC::Message* msg);
53
54 base::ThreadChecker thread_checker_;
55
56 IPC::Sender* const proxied_sender_;
57 RendererScheduler* const scheduler_;
58 const base::TimeDelta flush_period_;
59 const uint32 max_requests_per_flush_;
60
61 base::Timer flush_timer_;
62 base::TimeTicks last_sent_request_time_;
63 uint32 sent_requests_since_last_flush_;
64 std::map<int, IPC::Message*> throttled_requests_;
65 bool is_forwarding_request_;
66
67 DISALLOW_COPY_AND_ASSIGN(ResourceDispatchThrottler);
68 };
69
70 } // namespace content
71
72 #endif // CONTENT_RENDERER_RESOURCE_DISPATCH_THROTTLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698