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

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

Issue 7552028: Injected CSS localization fix (see bug no.) (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Removed race by dropping to IO thread first, before FILE thread. Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 7 #pragma once
8 8
9 #include <map>
10 #include <string>
11
9 #include "base/file_path.h" 12 #include "base/file_path.h"
10 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
11 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
12 #include "base/shared_memory.h" 15 #include "base/shared_memory.h"
16 #include "chrome/browser/extensions/extension_info_map.h"
17 #include "chrome/common/extensions/extension_messages.h"
18 #include "chrome/common/extensions/extension_set.h"
13 #include "chrome/common/extensions/user_script.h" 19 #include "chrome/common/extensions/user_script.h"
14 #include "content/browser/browser_thread.h" 20 #include "content/browser/browser_thread.h"
15 #include "content/common/notification_observer.h" 21 #include "content/common/notification_observer.h"
16 #include "content/common/notification_registrar.h" 22 #include "content/common/notification_registrar.h"
17 23
18 namespace base { 24 namespace base {
19 class StringPiece; 25 class StringPiece;
20 } 26 }
21 27
22 class Profile; 28 class Profile;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // Start loading of scripts. 74 // Start loading of scripts.
69 // Will always send a message to the master upon completion. 75 // Will always send a message to the master upon completion.
70 void StartLoad(const UserScriptList& external_scripts); 76 void StartLoad(const UserScriptList& external_scripts);
71 77
72 // The master is going away; don't call it back. 78 // The master is going away; don't call it back.
73 void DisownMaster() { 79 void DisownMaster() {
74 master_ = NULL; 80 master_ = NULL;
75 } 81 }
76 82
77 private: 83 private:
78 private:
79 FRIEND_TEST_ALL_PREFIXES(UserScriptMasterTest, SkipBOMAtTheBeginning); 84 FRIEND_TEST_ALL_PREFIXES(UserScriptMasterTest, SkipBOMAtTheBeginning);
80 FRIEND_TEST_ALL_PREFIXES(UserScriptMasterTest, LeaveBOMNotAtTheBeginning); 85 FRIEND_TEST_ALL_PREFIXES(UserScriptMasterTest, LeaveBOMNotAtTheBeginning);
81 friend class base::RefCountedThreadSafe<UserScriptMaster::ScriptReloader>; 86 friend class base::RefCountedThreadSafe<UserScriptMaster::ScriptReloader>;
82 87
83 ~ScriptReloader() {} 88 ~ScriptReloader() {}
84 89
85 // Where functions are run: 90 // Where functions are run:
86 // master file 91 // master file io
87 // StartLoad -> RunLoad 92 // StartLoad -> GatherExtensionsInfo
93 // info_map->extensions().Get...
94 // RunLoad <- GatherExtensionsInfo
88 // LoadUserScripts() 95 // LoadUserScripts()
89 // NotifyMaster <- RunLoad 96 // NotifyMaster <- RunLoad
90 97
91 // Runs on the master thread. 98 // Runs on the master thread.
92 // Notify the master that new scripts are available. 99 // Notify the master that new scripts are available.
93 void NotifyMaster(base::SharedMemory* memory); 100 void NotifyMaster(base::SharedMemory* memory);
94 101
102 // Runs on IO thread.
103 // Accesses the extension set in order to populate extensions_info_,
104 // then drops to the File thread to execute RunLoad.
105 void GatherExtensionsInfo(const ExtensionInfoMap* info_map,
106 const UserScriptList& user_scripts);
107
95 // Runs on the File thread. 108 // Runs on the File thread.
96 // Load the specified user scripts, calling NotifyMaster when done. 109 // Load the specified user scripts, calling NotifyMaster when done.
97 // |user_scripts| is intentionally passed by value so its lifetime isn't 110 // |user_scripts| is intentionally passed by value so its lifetime isn't
98 // tied to the caller. 111 // tied to the caller.
99 void RunLoad(const UserScriptList& user_scripts); 112 void RunLoad(const UserScriptList& user_scripts);
100 113
101 static void LoadUserScripts(UserScriptList* user_scripts); 114 void LoadUserScripts(UserScriptList* user_scripts);
115
116 // Uses extensions_info_ to build a map of localization messages.
117 // Returns NULL if |extension_id| is invalid.
118 SubstitutionMap* GetLocalizationMessages(std::string extension_id);
102 119
103 // A pointer back to our master. 120 // A pointer back to our master.
104 // May be NULL if DisownMaster() is called. 121 // May be NULL if DisownMaster() is called.
105 UserScriptMaster* master_; 122 UserScriptMaster* master_;
106 123
124 // Maps extension info needed for localization to an extension ID.
125 std::map<std::string, ExtensionSet::ExtensionPathAndDefaultLocale>
126 extensions_info_;
127
107 // The message loop to call our master back on. 128 // The message loop to call our master back on.
108 // Expected to always outlive us. 129 // Expected to always outlive us.
109 BrowserThread::ID master_thread_id_; 130 BrowserThread::ID master_thread_id_;
110 131
111 DISALLOW_COPY_AND_ASSIGN(ScriptReloader); 132 DISALLOW_COPY_AND_ASSIGN(ScriptReloader);
112 }; 133 };
113 134
114 private: 135 private:
115 // NotificationObserver implementation. 136 // NotificationObserver implementation.
116 virtual void Observe(int type, 137 virtual void Observe(int type,
(...skipping 25 matching lines...) Expand all
142 // finishes. This boolean tracks whether another load is pending. 163 // finishes. This boolean tracks whether another load is pending.
143 bool pending_load_; 164 bool pending_load_;
144 165
145 // The profile for which the scripts managed here are installed. 166 // The profile for which the scripts managed here are installed.
146 Profile* profile_; 167 Profile* profile_;
147 168
148 DISALLOW_COPY_AND_ASSIGN(UserScriptMaster); 169 DISALLOW_COPY_AND_ASSIGN(UserScriptMaster);
149 }; 170 };
150 171
151 #endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_ 172 #endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698