summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/user_script_master.h
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-17 01:21:47 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-17 01:21:47 +0000
commit0999c45abbe8d57f1c62c65f91459881a4af321a (patch)
tree6844ce69dfaf4cbdfe0e540e6647ef60b3c22451 /chrome/browser/extensions/user_script_master.h
parent2e6189037048f81f5025125a9884f29c1e5f544d (diff)
downloadchromium_src-0999c45abbe8d57f1c62c65f91459881a4af321a.zip
chromium_src-0999c45abbe8d57f1c62c65f91459881a4af321a.tar.gz
chromium_src-0999c45abbe8d57f1c62c65f91459881a4af321a.tar.bz2
Move parsing of metadata header into browser process. This is a prerequisite
to getting user scripts working in extensions because extensions won't express their metadata using the UserScript header, so parsing can't be done in the renderer. Review URL: http://codereview.chromium.org/18308 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8249 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/user_script_master.h')
-rw-r--r--chrome/browser/extensions/user_script_master.h67
1 files changed, 64 insertions, 3 deletions
diff --git a/chrome/browser/extensions/user_script_master.h b/chrome/browser/extensions/user_script_master.h
index 4798bb2..8df49be 100644
--- a/chrome/browser/extensions/user_script_master.h
+++ b/chrome/browser/extensions/user_script_master.h
@@ -7,11 +7,11 @@
#include "base/directory_watcher.h"
#include "base/file_path.h"
+#include "base/message_loop.h"
#include "base/process.h"
#include "base/scoped_ptr.h"
#include "base/shared_memory.h"
-
-class MessageLoop;
+#include "base/string_piece.h"
// Manages a segment of shared memory that contains the user scripts the user
// has installed. Lives on the UI thread.
@@ -39,7 +39,68 @@ class UserScriptMaster : public base::RefCounted<UserScriptMaster>,
FilePath user_script_dir() const { return *user_script_dir_; }
private:
- class ScriptReloader;
+ FRIEND_TEST(UserScriptMasterTest, Parse1);
+ FRIEND_TEST(UserScriptMasterTest, Parse2);
+ FRIEND_TEST(UserScriptMasterTest, Parse3);
+
+ // We reload user scripts on the file thread to prevent blocking the UI.
+ // ScriptReloader lives on the file thread and does the reload
+ // work, and then sends a message back to its master with a new SharedMemory*.
+ // ScriptReloader is the worker that manages running the script scan
+ // on the file thread. It must be created on, and its public API must only be
+ // called from, the master's thread.
+ class ScriptReloader
+ : public base::RefCounted<UserScriptMaster::ScriptReloader> {
+ public:
+ // Parses the includes out of |script| and returns them in |includes|.
+ static void ParseMetadataHeader(const StringPiece& script,
+ std::vector<std::string>* includes);
+
+ ScriptReloader(UserScriptMaster* master)
+ : master_(master), master_message_loop_(MessageLoop::current()) {}
+
+ // Start a scan for scripts.
+ // Will always send a message to the master upon completion.
+ void StartScan(MessageLoop* work_loop, const FilePath& script_dir);
+
+ // The master is going away; don't call it back.
+ void DisownMaster() {
+ master_ = NULL;
+ }
+
+ private:
+ // Where functions are run:
+ // master file
+ // StartScan -> RunScan
+ // GetNewScripts()
+ // ParseMetadataHeader()
+ // NotifyMaster <- RunScan
+
+ // Runs on the master thread.
+ // Notify the master that new scripts are available.
+ void NotifyMaster(base::SharedMemory* memory);
+
+ // Runs on the File thread.
+ // Scan the script directory for scripts, calling NotifyMaster when done.
+ // The path is intentionally passed by value so its lifetime isn't tied
+ // to the caller.
+ void RunScan(const FilePath script_dir);
+
+ // Runs on the File thread.
+ // Scan the script directory for scripts, returning either a
+ // new SharedMemory or NULL on error.
+ base::SharedMemory* GetNewScripts(const FilePath& script_dir);
+
+ // A pointer back to our master.
+ // May be NULL if DisownMaster() is called.
+ UserScriptMaster* master_;
+
+ // The message loop to call our master back on.
+ // Expected to always outlive us.
+ MessageLoop* master_message_loop_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScriptReloader);
+ };
// DirectoryWatcher::Delegate implementation.
virtual void OnDirectoryChanged(const FilePath& path);