Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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 #ifndef CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/directory_watcher.h" | 10 #include "base/directory_watcher.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/shared_memory.h" | 13 #include "base/shared_memory.h" |
| 14 #include "chrome/common/extensions/user_script.h" | 14 #include "chrome/common/extensions/user_script.h" |
| 15 #include "chrome/common/notification_registrar.h" | 15 #include "chrome/common/notification_registrar.h" |
| 16 #include "testing/gtest/include/gtest/gtest_prod.h" | 16 #include "testing/gtest/include/gtest/gtest_prod.h" |
| 17 | 17 |
| 18 class MessageLoop; | 18 class MessageLoop; |
| 19 namespace base { | 19 namespace base { |
| 20 class StringPiece; | 20 class StringPiece; |
| 21 } | 21 } |
| 22 | 22 |
| 23 // Manages a segment of shared memory that contains the user scripts the user | 23 // Manages a segment of shared memory that contains the user scripts the user |
| 24 // has installed. Lives on the UI thread. | 24 // has installed. Lives on the UI thread. |
| 25 class UserScriptMaster : public base::RefCounted<UserScriptMaster>, | 25 class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>, |
|
Aaron Boodman
2009/09/17 22:59:34
Does this class actually get called on multiple th
| |
| 26 public DirectoryWatcher::Delegate, | 26 public DirectoryWatcher::Delegate, |
| 27 public NotificationObserver { | 27 public NotificationObserver { |
| 28 public: | 28 public: |
| 29 // For testability, the constructor takes the MessageLoop to run the | 29 // For testability, the constructor takes the MessageLoop to run the |
| 30 // script-reloading worker on as well as the path the scripts live in. | 30 // script-reloading worker on as well as the path the scripts live in. |
| 31 // These are normally the file thread and a directory inside the profile. | 31 // These are normally the file thread and a directory inside the profile. |
| 32 UserScriptMaster(MessageLoop* worker, const FilePath& script_dir); | 32 UserScriptMaster(MessageLoop* worker, const FilePath& script_dir); |
| 33 virtual ~UserScriptMaster(); | 33 virtual ~UserScriptMaster(); |
| 34 | 34 |
| 35 // Add a watched directory. All scripts will be reloaded when any file in | 35 // Add a watched directory. All scripts will be reloaded when any file in |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 62 FRIEND_TEST(UserScriptMasterTest, Parse5); | 62 FRIEND_TEST(UserScriptMasterTest, Parse5); |
| 63 FRIEND_TEST(UserScriptMasterTest, Parse6); | 63 FRIEND_TEST(UserScriptMasterTest, Parse6); |
| 64 | 64 |
| 65 // We reload user scripts on the file thread to prevent blocking the UI. | 65 // We reload user scripts on the file thread to prevent blocking the UI. |
| 66 // ScriptReloader lives on the file thread and does the reload | 66 // ScriptReloader lives on the file thread and does the reload |
| 67 // work, and then sends a message back to its master with a new SharedMemory*. | 67 // work, and then sends a message back to its master with a new SharedMemory*. |
| 68 // ScriptReloader is the worker that manages running the script scan | 68 // ScriptReloader is the worker that manages running the script scan |
| 69 // on the file thread. It must be created on, and its public API must only be | 69 // on the file thread. It must be created on, and its public API must only be |
| 70 // called from, the master's thread. | 70 // called from, the master's thread. |
| 71 class ScriptReloader | 71 class ScriptReloader |
| 72 : public base::RefCounted<UserScriptMaster::ScriptReloader> { | 72 : public base::RefCounted<UserScriptMaster::ScriptReloader> { |
|
Aaron Boodman
2009/09/17 22:59:34
It seems like this guy needs to be base::RefCounte
| |
| 73 public: | 73 public: |
| 74 // Parses the includes out of |script| and returns them in |includes|. | 74 // Parses the includes out of |script| and returns them in |includes|. |
| 75 static bool ParseMetadataHeader(const base::StringPiece& script_text, | 75 static bool ParseMetadataHeader(const base::StringPiece& script_text, |
| 76 UserScript* script); | 76 UserScript* script); |
| 77 | 77 |
| 78 static void LoadScriptsFromDirectory(const FilePath& script_dir, | 78 static void LoadScriptsFromDirectory(const FilePath& script_dir, |
| 79 UserScriptList* result); | 79 UserScriptList* result); |
| 80 | 80 |
| 81 explicit ScriptReloader(UserScriptMaster* master); | 81 explicit ScriptReloader(UserScriptMaster* master); |
| 82 | 82 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 | 156 |
| 157 // If the script directory is modified while we're rescanning it, we note | 157 // If the script directory is modified while we're rescanning it, we note |
| 158 // that we're currently mid-scan and then start over again once the scan | 158 // that we're currently mid-scan and then start over again once the scan |
| 159 // finishes. This boolean tracks whether another scan is pending. | 159 // finishes. This boolean tracks whether another scan is pending. |
| 160 bool pending_scan_; | 160 bool pending_scan_; |
| 161 | 161 |
| 162 DISALLOW_COPY_AND_ASSIGN(UserScriptMaster); | 162 DISALLOW_COPY_AND_ASSIGN(UserScriptMaster); |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 #endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_ | 165 #endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_ |
| OLD | NEW |