OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/renderer/user_script_idle_scheduler.h" | |
6 | |
7 #include "base/message_loop.h" | |
8 #include "chrome/renderer/render_view.h" | |
9 | |
10 namespace { | |
11 // The length of time to wait after the DOM is complete to try and run user | |
12 // scripts. | |
13 const int kUserScriptIdleTimeoutMs = 200; | |
14 } | |
15 | |
16 UserScriptIdleScheduler::UserScriptIdleScheduler(RenderView* view, | |
17 WebKit::WebFrame* frame) | |
18 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), view_(view), | |
19 frame_(frame), has_run_(false) { | |
abarth-chromium
2009/10/31 07:07:39
These should each be on a different line according
| |
20 } | |
21 | |
22 void UserScriptIdleScheduler::DidFinishDocumentLoad() { | |
23 MessageLoop::current()->PostDelayedTask(FROM_HERE, | |
24 method_factory_.NewRunnableMethod(&UserScriptIdleScheduler::MaybeRun), | |
25 kUserScriptIdleTimeoutMs); | |
26 } | |
27 | |
28 void UserScriptIdleScheduler::DidFinishLoad() { | |
29 // Ensure that running scripts does not keep any progress UI running. | |
30 MessageLoop::current()->PostTask(FROM_HERE, | |
31 method_factory_.NewRunnableMethod(&UserScriptIdleScheduler::MaybeRun)); | |
32 } | |
33 | |
34 void UserScriptIdleScheduler::Cancel() { | |
35 view_ = NULL; | |
36 frame_ = NULL; | |
37 } | |
38 | |
39 void UserScriptIdleScheduler::MaybeRun() { | |
40 if (!view_) | |
41 return; | |
42 | |
43 DCHECK(frame_); | |
44 view_->OnUserScriptIdleLocation(frame_); | |
45 Cancel(); | |
46 has_run_ = true; | |
47 } | |
OLD | NEW |