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

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

Issue 2118903002: scheduler: Move the Blink scheduler into Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 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 2015 The Chromium Authors. All rights reserved. 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 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 CONTENT_RENDERER_SCHEDULER_RESOURCE_DISPATCH_THROTTLER_H_ 5 #ifndef CONTENT_RENDERER_SCHEDULER_RESOURCE_DISPATCH_THROTTLER_H_
6 #define CONTENT_RENDERER_SCHEDULER_RESOURCE_DISPATCH_THROTTLER_H_ 6 #define CONTENT_RENDERER_SCHEDULER_RESOURCE_DISPATCH_THROTTLER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <deque> 10 #include <deque>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/threading/thread_checker.h" 13 #include "base/threading/thread_checker.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "base/timer/timer.h" 15 #include "base/timer/timer.h"
16 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
17 #include "ipc/ipc_sender.h" 17 #include "ipc/ipc_sender.h"
18 18
19 namespace blink {
19 namespace scheduler { 20 namespace scheduler {
20 class RendererScheduler; 21 class RendererScheduler;
21 } 22 }
23 }
22 24
23 namespace content { 25 namespace content {
24 26
25 // Utility class for throttling a stream of resource requests targetted to a 27 // Utility class for throttling a stream of resource requests targetted to a
26 // specific IPC sender. The throttling itself is very basic: 28 // specific IPC sender. The throttling itself is very basic:
27 // * When there is no high-priority work imminent to the main thread, as 29 // * When there is no high-priority work imminent to the main thread, as
28 // indicated by the RendererScheduler, throttling is disabled. 30 // indicated by the RendererScheduler, throttling is disabled.
29 // * When >= N requests have been sent in a given time window, requests are 31 // * When >= N requests have been sent in a given time window, requests are
30 // throttled. A timer periodically flushes a portion of the queued requests 32 // throttled. A timer periodically flushes a portion of the queued requests
31 // until all such requests have been flushed. 33 // until all such requests have been flushed.
32 // TODO(jdduke): Remove this class after resource requests become sufficiently 34 // TODO(jdduke): Remove this class after resource requests become sufficiently
33 // cheap on the IO thread, crbug.com/440037. 35 // cheap on the IO thread, crbug.com/440037.
34 class CONTENT_EXPORT ResourceDispatchThrottler : public IPC::Sender { 36 class CONTENT_EXPORT ResourceDispatchThrottler : public IPC::Sender {
35 public: 37 public:
36 // |flush_period| and |max_requests_per_flush| must be strictly positive 38 // |flush_period| and |max_requests_per_flush| must be strictly positive
37 // in duration/value. 39 // in duration/value.
38 ResourceDispatchThrottler(IPC::Sender* proxied_sender, 40 ResourceDispatchThrottler(IPC::Sender* proxied_sender,
39 scheduler::RendererScheduler* scheduler, 41 blink::scheduler::RendererScheduler* scheduler,
40 base::TimeDelta flush_period, 42 base::TimeDelta flush_period,
41 uint32_t max_requests_per_flush); 43 uint32_t max_requests_per_flush);
42 ~ResourceDispatchThrottler() override; 44 ~ResourceDispatchThrottler() override;
43 45
44 // IPC::Sender implementation: 46 // IPC::Sender implementation:
45 bool Send(IPC::Message* msg) override; 47 bool Send(IPC::Message* msg) override;
46 48
47 private: 49 private:
48 friend class ResourceDispatchThrottlerForTest; 50 friend class ResourceDispatchThrottlerForTest;
49 51
50 // Virtual for testing. 52 // Virtual for testing.
51 virtual base::TimeTicks Now() const; 53 virtual base::TimeTicks Now() const;
52 virtual void ScheduleFlush(); 54 virtual void ScheduleFlush();
53 55
54 void Flush(); 56 void Flush();
55 void FlushAll(); 57 void FlushAll();
56 void LogFlush(); 58 void LogFlush();
57 bool ForwardMessage(IPC::Message* msg); 59 bool ForwardMessage(IPC::Message* msg);
58 60
59 base::ThreadChecker thread_checker_; 61 base::ThreadChecker thread_checker_;
60 62
61 IPC::Sender* const proxied_sender_; 63 IPC::Sender* const proxied_sender_;
62 scheduler::RendererScheduler* const scheduler_; 64 blink::scheduler::RendererScheduler* const scheduler_;
63 const base::TimeDelta flush_period_; 65 const base::TimeDelta flush_period_;
64 const uint32_t max_requests_per_flush_; 66 const uint32_t max_requests_per_flush_;
65 67
66 base::Timer flush_timer_; 68 base::Timer flush_timer_;
67 base::TimeTicks last_flush_time_; 69 base::TimeTicks last_flush_time_;
68 uint32_t sent_requests_since_last_flush_; 70 uint32_t sent_requests_since_last_flush_;
69 std::deque<IPC::Message*> throttled_messages_; 71 std::deque<IPC::Message*> throttled_messages_;
70 72
71 DISALLOW_COPY_AND_ASSIGN(ResourceDispatchThrottler); 73 DISALLOW_COPY_AND_ASSIGN(ResourceDispatchThrottler);
72 }; 74 };
73 75
74 } // namespace content 76 } // namespace content
75 77
76 #endif // CONTENT_RENDERER_SCHEDULER_RESOURCE_DISPATCH_THROTTLER_H_ 78 #endif // CONTENT_RENDERER_SCHEDULER_RESOURCE_DISPATCH_THROTTLER_H_
OLDNEW
« no previous file with comments | « content/renderer/renderer_main.cc ('k') | content/renderer/scheduler/resource_dispatch_throttler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698