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

Side by Side Diff: content/browser/renderer_host/render_widget_resize_helper_mac.cc

Issue 396483003: Separate ResizeHelper from RenderWidgetHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Linux build again Created 6 years, 5 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 #include "content/browser/renderer_host/render_widget_resize_helper_mac.h"
piman 2014/07/15 19:56:00 nit: copyright header needed.
ccameron 2014/07/15 20:36:24 Done.
2
3 #include "content/browser/gpu/gpu_process_host_ui_shim.h"
4 #include "content/browser/renderer_host/render_process_host_impl.h"
5 #include "content/public/browser/browser_thread.h"
6
7 namespace content {
8 namespace {
9 base::LazyInstance<RenderWidgetResizeHelper> g_render_widget_task_runner;
10 } // namespace
11
12 // A helper used with DidReceiveBackingStoreMsg that we hold a pointer to in
13 // pending_paints_.
piman 2014/07/15 19:56:00 nit: fix comment.
ccameron 2014/07/15 20:36:24 Done.
14 class RenderWidgetResizeHelper::EnqueuedTask {
15 public:
16 enum Type {
17 RENDERER_IPC,
18 GPU_IPC,
19 };
20 EnqueuedTask(Type type, int process_id, const IPC::Message& m);
21 ~EnqueuedTask();
22 void Run();
23
24 private:
25 Type type_;
26 int process_id_;
27 IPC::Message message_;
28 bool has_run_;
29
30 DISALLOW_COPY_AND_ASSIGN(EnqueuedTask);
31 };
32
33 RenderWidgetResizeHelper::EnqueuedTask::EnqueuedTask(
34 Type type,
35 int process_id,
36 const IPC::Message& m)
37 : type_(type),
38 process_id_(process_id),
39 message_(m),
40 has_run_(false) {
41 }
42
43 RenderWidgetResizeHelper::EnqueuedTask::~EnqueuedTask() {
44 }
45
46 void RenderWidgetResizeHelper::EnqueuedTask::Run() {
47 if (has_run_)
48 return;
49
50 RenderWidgetResizeHelper::Get()->WillRunEnqueuedTask(this);
51 has_run_ = true;
52
53 switch (type_) {
54 case RENDERER_IPC: {
55 RenderProcessHost* host = RenderProcessHost::FromID(process_id_);
56 if (host)
57 host->OnMessageReceived(message_);
58 } break;
piman 2014/07/15 19:56:00 nit: break inside the {}
ccameron 2014/07/15 20:36:24 Done.
59 case GPU_IPC: {
60 GpuProcessHostUIShim* host = GpuProcessHostUIShim::FromID(process_id_);
61 if (host)
62 host->OnMessageReceived(message_);
63 } break;
piman 2014/07/15 19:56:00 nit: here too.
ccameron 2014/07/15 20:36:24 Done.
64 }
65 }
66
67 // static
68 RenderWidgetResizeHelper* RenderWidgetResizeHelper::Get() {
69 return g_render_widget_task_runner.Pointer();
70 }
71
72 bool RenderWidgetResizeHelper::WaitForSingleTaskToRun(
73 const base::TimeDelta& max_delay) {
74 base::TimeTicks time_start = base::TimeTicks::Now();
75
76 for (;;) {
77 // Peek at the message from the front of the queue. Running it will remove
78 // it from the queue.
79 EnqueuedTask* task = NULL;
80 {
81 base::AutoLock lock(task_queue_lock_);
82 if (!task_queue_.empty())
83 task = task_queue_.front();
84 }
85
86 if (task) {
87 task->Run();
88 return true;
89 }
90
91 // Calculate the maximum amount of time that we are willing to sleep.
92 base::TimeDelta max_sleep_time =
93 max_delay - (base::TimeTicks::Now() - time_start);
94 if (max_sleep_time <= base::TimeDelta::FromMilliseconds(0))
95 break;
96
97 base::ThreadRestrictions::ScopedAllowWait allow_wait;
98 event_.TimedWait(max_sleep_time);
99 }
100
101 return false;
102 }
103
104 void RenderWidgetResizeHelper::PostEnqueuedTask(EnqueuedTask* task) {
105 {
106 base::AutoLock lock(task_queue_lock_);
107 task_queue_.push_back(task);
108 }
109
110 // Notify anyone waiting on the UI thread that there is a new entry in the
111 // task map. If they don't find the entry they are looking for, then they
112 // will just continue waiting.
113 event_.Signal();
114
115 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
116 base::Bind(&EnqueuedTask::Run, base::Owned(task)));
117 }
118
119 void RenderWidgetResizeHelper::WillRunEnqueuedTask(EnqueuedTask* task) {
120 base::AutoLock lock(task_queue_lock_);
121 DCHECK(task_queue_.front() == task);
122 task_queue_.pop_front();
123 }
124
125 void RenderWidgetResizeHelper::PostRendererProcessMsg(
126 int render_process_id, const IPC::Message& msg) {
127 PostEnqueuedTask(new EnqueuedTask(
128 EnqueuedTask::RENDERER_IPC, render_process_id, msg));
129 }
130
131 void RenderWidgetResizeHelper::PostGpuProcessMsg(
132 int gpu_host_id, const IPC::Message& msg) {
133 PostEnqueuedTask(new EnqueuedTask(EnqueuedTask::GPU_IPC, gpu_host_id, msg));
134 }
135
136 RenderWidgetResizeHelper::RenderWidgetResizeHelper()
137 #if defined(OS_WIN)
138 : event_(CreateEvent(NULL, FALSE /* auto-reset */, FALSE, NULL)) {}
139 #elif defined(OS_POSIX)
140 : event_(false /* auto-reset */, false) {}
piman 2014/07/15 19:56:00 nit: why not always this path on all platforms? It
ccameron 2014/07/15 20:36:25 This is from the earlier versions of the code -- n
piman 2014/07/15 22:49:36 This probably predates some API unification. Readi
141 #endif
142
143 RenderWidgetResizeHelper::~RenderWidgetResizeHelper() {
144 // The elements of task_queue_ will call back into this object, so we
145 // should not be destroyed unless task_queue_ is empty!
146 DCHECK(task_queue_.empty());
147 }
148
149 } // namespace content
150
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698