| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "chrome/renderer/user_script_idle_scheduler.h" | 5 #include "chrome/renderer/user_script_idle_scheduler.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "chrome/renderer/render_view.h" | 8 #include "chrome/renderer/render_view.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 MessageLoop::current()->PostTask(FROM_HERE, | 30 MessageLoop::current()->PostTask(FROM_HERE, |
| 31 method_factory_.NewRunnableMethod(&UserScriptIdleScheduler::MaybeRun)); | 31 method_factory_.NewRunnableMethod(&UserScriptIdleScheduler::MaybeRun)); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void UserScriptIdleScheduler::Cancel() { | 34 void UserScriptIdleScheduler::Cancel() { |
| 35 view_ = NULL; | 35 view_ = NULL; |
| 36 frame_ = NULL; | 36 frame_ = NULL; |
| 37 } | 37 } |
| 38 | 38 |
| 39 void UserScriptIdleScheduler::MaybeRun() { | 39 void UserScriptIdleScheduler::MaybeRun() { |
| 40 if (!view_) | 40 if (!view_ || has_run()) |
| 41 return; | 41 return; |
| 42 | 42 |
| 43 // Note: we must set this before calling OnUserScriptIdleTriggered, because |
| 44 // that may result in a synchronous call back into MaybeRun if there is a |
| 45 // pending task currently in the queue. |
| 46 // http://code.google.com/p/chromium/issues/detail?id=29644 |
| 47 has_run_ = true; |
| 48 |
| 43 DCHECK(frame_); | 49 DCHECK(frame_); |
| 44 view_->OnUserScriptIdleTriggered(frame_); | 50 view_->OnUserScriptIdleTriggered(frame_); |
| 45 Cancel(); | 51 Cancel(); |
| 46 has_run_ = true; | |
| 47 } | 52 } |
| OLD | NEW |