summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/user_script_idle_scheduler.h
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-03 05:02:30 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-03 05:02:30 +0000
commitfa7b6b547368d12ccd61f6cbf251f2ff0d37b504 (patch)
treec28ef0f99dc70cd1dc8acf70f3cc8af5d2cb9072 /chrome/renderer/user_script_idle_scheduler.h
parentd12f7a9539c490b3e008d234526a67d0496972b3 (diff)
downloadchromium_src-fa7b6b547368d12ccd61f6cbf251f2ff0d37b504.zip
chromium_src-fa7b6b547368d12ccd61f6cbf251f2ff0d37b504.tar.gz
chromium_src-fa7b6b547368d12ccd61f6cbf251f2ff0d37b504.tar.bz2
Re-commit "Add new user script injection point:
document_idle." Original code review: http://codereview.chromium.org/339064 BUG=26126 TBR=rafaelw@chromium.org git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30796 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/user_script_idle_scheduler.h')
-rw-r--r--chrome/renderer/user_script_idle_scheduler.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/chrome/renderer/user_script_idle_scheduler.h b/chrome/renderer/user_script_idle_scheduler.h
new file mode 100644
index 0000000..772d652
--- /dev/null
+++ b/chrome/renderer/user_script_idle_scheduler.h
@@ -0,0 +1,58 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_RENDERER_USER_SCRIPT_IDLE_SCHEDULER_H_
+#define CHROME_RENDERER_USER_SCRIPT_IDLE_SCHEDULER_H_
+
+#include "base/task.h"
+
+class RenderView;
+
+namespace WebKit {
+class WebFrame;
+}
+
+// Implements support for injecting scripts at "document idle". Currently,
+// determining idleness is simple: it is whichever of the following happens
+// first:
+//
+// a) When the initial DOM for a page is complete + kUserScriptIdleTimeout,
+// b) or when the page has completely loaded including all subresources.
+//
+// The intent of this mechanism is to prevent user scripts from slowing down
+// fast pages (run after load), while still allowing them to run relatively
+// timelily for pages with lots of slow subresources.
+class UserScriptIdleScheduler {
+ public:
+ UserScriptIdleScheduler(RenderView* view, WebKit::WebFrame* frame);
+
+ bool has_run() { return has_run_; }
+
+ // Called when the DOM has been completely constructed.
+ void DidFinishDocumentLoad();
+
+ // Called when the document has completed loading.
+ void DidFinishLoad();
+
+ // Called when the client has gone away and we should no longer run scripts.
+ void Cancel();
+
+ private:
+ // Run user scripts, except if they've already run for this frame, or the
+ // frame has been destroyed.
+ void MaybeRun();
+
+ ScopedRunnableMethodFactory<UserScriptIdleScheduler> method_factory_;
+
+ // The RenderView we will call back to when it is time to run scripts.
+ RenderView* view_;
+
+ // The Frame we will run scripts in.
+ WebKit::WebFrame* frame_;
+
+ // Whether we have already run scripts.
+ bool has_run_;
+};
+
+#endif // CHROME_RENDERER_USER_SCRIPT_IDLE_SCHEDULER_H_