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

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

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

Powered by Google App Engine
This is Rietveld 408576698