Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Side by Side Diff: chrome/browser/extensions/user_script_master.h

Issue 567037: Initial work on making extensions work in incognito mode. (Closed)
Patch Set: added experimental requirement Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "base/shared_memory.h" 10 #include "base/shared_memory.h"
11 #include "chrome/browser/chrome_thread.h" 11 #include "chrome/browser/chrome_thread.h"
12 #include "chrome/common/extensions/user_script.h" 12 #include "chrome/common/extensions/user_script.h"
13 #include "chrome/common/notification_registrar.h" 13 #include "chrome/common/notification_registrar.h"
14 #include "testing/gtest/include/gtest/gtest_prod.h" 14 #include "testing/gtest/include/gtest/gtest_prod.h"
15 15
16 namespace base { 16 namespace base {
17 class StringPiece; 17 class StringPiece;
18 } 18 }
19 19
20 class Extension;
20 class Profile; 21 class Profile;
21 22
22 // 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
23 // has installed. Lives on the UI thread. 24 // has installed. Lives on the UI thread.
24 class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>, 25 class UserScriptMaster : public base::RefCountedThreadSafe<UserScriptMaster>,
25 public NotificationObserver { 26 public NotificationObserver {
26 public: 27 public:
27 // For testability, the constructor takes the path the scripts live in. 28 // For testability, the constructor takes the path the scripts live in.
28 // This is normally a directory inside the profile. 29 // This is normally a directory inside the profile.
29 explicit UserScriptMaster(const FilePath& script_dir, Profile* profile); 30 explicit UserScriptMaster(const FilePath& script_dir, Profile* profile);
30 31
31 // Kicks off a process on the file thread to reload scripts from disk 32 // Kicks off a process on the file thread to reload scripts from disk
32 // into a new chunk of shared memory and notify renderers. 33 // into a new chunk of shared memory and notify renderers.
33 virtual void StartScan(); 34 virtual void StartScan();
34 35
35 // Gets the segment of shared memory for the scripts. 36 // Gets the segment of shared memory for the scripts.
36 base::SharedMemory* GetSharedMemory() const { 37 base::SharedMemory* GetSharedMemory() const {
37 return shared_memory_.get(); 38 return shared_memory_.get();
38 } 39 }
39 40
40 // Called by the script reloader when new scripts have been loaded. 41 // Called by the script reloader when new scripts have been loaded.
41 void NewScriptsAvailable(base::SharedMemory* handle); 42 void NewScriptsAvailable(base::SharedMemory* handle);
42 43
43 // Return true if we have any scripts ready. 44 // Return true if we have any scripts ready.
44 bool ScriptsReady() const { return shared_memory_.get() != NULL; } 45 bool ScriptsReady() const { return shared_memory_.get() != NULL; }
45 46
46 // Returns the path to the directory user scripts are stored in. 47 // Returns the path to the directory user scripts are stored in.
47 FilePath user_script_dir() const { return user_script_dir_; } 48 FilePath user_script_dir() const { return user_script_dir_; }
48 49
50 // Note: this is only for testing. This will reload the scripts associated
51 // with the given extension. This is only temporary until we get better
52 // machinery in place for toggling incognito-enabled extensions.
53 void ReloadExtensionForTesting(Extension* extension);
54
49 protected: 55 protected:
50 friend class base::RefCountedThreadSafe<UserScriptMaster>; 56 friend class base::RefCountedThreadSafe<UserScriptMaster>;
51 57
52 virtual ~UserScriptMaster(); 58 virtual ~UserScriptMaster();
53 59
54 private: 60 private:
55 FRIEND_TEST(UserScriptMasterTest, Parse1); 61 FRIEND_TEST(UserScriptMasterTest, Parse1);
56 FRIEND_TEST(UserScriptMasterTest, Parse2); 62 FRIEND_TEST(UserScriptMasterTest, Parse2);
57 FRIEND_TEST(UserScriptMasterTest, Parse3); 63 FRIEND_TEST(UserScriptMasterTest, Parse3);
58 FRIEND_TEST(UserScriptMasterTest, Parse4); 64 FRIEND_TEST(UserScriptMasterTest, Parse4);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // finishes. This boolean tracks whether another scan is pending. 157 // finishes. This boolean tracks whether another scan is pending.
152 bool pending_scan_; 158 bool pending_scan_;
153 159
154 // The profile for which the scripts managed here are installed. 160 // The profile for which the scripts managed here are installed.
155 Profile* profile_; 161 Profile* profile_;
156 162
157 DISALLOW_COPY_AND_ASSIGN(UserScriptMaster); 163 DISALLOW_COPY_AND_ASSIGN(UserScriptMaster);
158 }; 164 };
159 165
160 #endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_ 166 #endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/incognito_noscript_apitest.cc ('k') | chrome/browser/extensions/user_script_master.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698