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" |
(...skipping 10 matching lines...) Expand all Loading... |
21 // Manages a segment of shared memory that contains the user scripts the user | 21 // Manages a segment of shared memory that contains the user scripts the user |
22 // has installed. Lives on the UI thread. | 22 // has installed. Lives on the UI thread. |
23 class UserScriptMaster : public base::RefCounted<UserScriptMaster>, | 23 class UserScriptMaster : public base::RefCounted<UserScriptMaster>, |
24 public DirectoryWatcher::Delegate, | 24 public DirectoryWatcher::Delegate, |
25 public NotificationObserver { | 25 public NotificationObserver { |
26 public: | 26 public: |
27 // For testability, the constructor takes the MessageLoop to run the | 27 // For testability, the constructor takes the MessageLoop to run the |
28 // script-reloading worker on as well as the path the scripts live in. | 28 // script-reloading worker on as well as the path the scripts live in. |
29 // These are normally the file thread and a directory inside the profile. | 29 // These are normally the file thread and a directory inside the profile. |
30 UserScriptMaster(MessageLoop* worker, const FilePath& script_dir); | 30 UserScriptMaster(MessageLoop* worker, const FilePath& script_dir); |
31 virtual ~UserScriptMaster(); | 31 ~UserScriptMaster(); |
32 | 32 |
33 // Add a watched directory. All scripts will be reloaded when any file in | 33 // Add a watched directory. All scripts will be reloaded when any file in |
34 // this directory changes. | 34 // this directory changes. |
35 void AddWatchedPath(const FilePath& path); | 35 void AddWatchedPath(const FilePath& path); |
36 | 36 |
37 // Kicks off a process on the file thread to reload scripts from disk | 37 // Kicks off a process on the file thread to reload scripts from disk |
38 // into a new chunk of shared memory and notify renderers. | 38 // into a new chunk of shared memory and notify renderers. |
39 virtual void StartScan(); | 39 void StartScan(); |
40 | 40 |
41 // Gets the segment of shared memory for the scripts. | 41 // Gets the segment of shared memory for the scripts. |
42 base::SharedMemory* GetSharedMemory() const { | 42 base::SharedMemory* GetSharedMemory() const { |
43 return shared_memory_.get(); | 43 return shared_memory_.get(); |
44 } | 44 } |
45 | 45 |
46 // Called by the script reloader when new scripts have been loaded. | 46 // Called by the script reloader when new scripts have been loaded. |
47 void NewScriptsAvailable(base::SharedMemory* handle); | 47 void NewScriptsAvailable(base::SharedMemory* handle); |
48 | 48 |
49 // Return true if we have any scripts ready. | 49 // Return true if we have any scripts ready. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 154 |
155 // If the script directory is modified while we're rescanning it, we note | 155 // If the script directory is modified while we're rescanning it, we note |
156 // that we're currently mid-scan and then start over again once the scan | 156 // that we're currently mid-scan and then start over again once the scan |
157 // finishes. This boolean tracks whether another scan is pending. | 157 // finishes. This boolean tracks whether another scan is pending. |
158 bool pending_scan_; | 158 bool pending_scan_; |
159 | 159 |
160 DISALLOW_COPY_AND_ASSIGN(UserScriptMaster); | 160 DISALLOW_COPY_AND_ASSIGN(UserScriptMaster); |
161 }; | 161 }; |
162 | 162 |
163 #endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_ | 163 #endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_ |
OLD | NEW |