OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/extensions/user_script_master.h" | 5 #include "chrome/browser/extensions/user_script_master.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 base::StringPiece contents = script.js_scripts()[j].GetContent(); | 277 base::StringPiece contents = script.js_scripts()[j].GetContent(); |
278 pickle.WriteData(contents.data(), contents.length()); | 278 pickle.WriteData(contents.data(), contents.length()); |
279 } | 279 } |
280 for (size_t j = 0; j < script.css_scripts().size(); j++) { | 280 for (size_t j = 0; j < script.css_scripts().size(); j++) { |
281 base::StringPiece contents = script.css_scripts()[j].GetContent(); | 281 base::StringPiece contents = script.css_scripts()[j].GetContent(); |
282 pickle.WriteData(contents.data(), contents.length()); | 282 pickle.WriteData(contents.data(), contents.length()); |
283 } | 283 } |
284 } | 284 } |
285 | 285 |
286 // Create the shared memory object. | 286 // Create the shared memory object. |
287 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); | 287 base::SharedMemory shared_memory; |
288 | 288 |
289 if (!shared_memory->CreateAndMapAnonymous(pickle.size())) | 289 if (!shared_memory.CreateAndMapAnonymous(pickle.size())) |
290 return NULL; | 290 return NULL; |
291 | 291 |
292 // Copy the pickle to shared memory. | 292 // Copy the pickle to shared memory. |
293 memcpy(shared_memory->memory(), pickle.data(), pickle.size()); | 293 memcpy(shared_memory.memory(), pickle.data(), pickle.size()); |
294 | 294 |
295 return shared_memory.release(); | 295 base::SharedMemoryHandle readonly_handle; |
| 296 if (!shared_memory.ShareReadOnlyToProcess(base::GetCurrentProcessHandle(), |
| 297 &readonly_handle)) |
| 298 return NULL; |
| 299 |
| 300 return new base::SharedMemory(readonly_handle, /*read_only=*/true); |
296 } | 301 } |
297 | 302 |
298 // This method will be called on the file thread. | 303 // This method will be called on the file thread. |
299 void UserScriptMaster::ScriptReloader::RunLoad( | 304 void UserScriptMaster::ScriptReloader::RunLoad( |
300 const UserScriptList& user_scripts) { | 305 const UserScriptList& user_scripts) { |
301 LoadUserScripts(const_cast<UserScriptList*>(&user_scripts)); | 306 LoadUserScripts(const_cast<UserScriptList*>(&user_scripts)); |
302 | 307 |
303 // Scripts now contains list of up-to-date scripts. Load the content in the | 308 // Scripts now contains list of up-to-date scripts. Load the content in the |
304 // shared memory and let the master know it's ready. We need to post the task | 309 // shared memory and let the master know it's ready. We need to post the task |
305 // back even if no scripts ware found to balance the AddRef/Release calls. | 310 // back even if no scripts ware found to balance the AddRef/Release calls. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 | 456 |
452 base::SharedMemoryHandle handle_for_process; | 457 base::SharedMemoryHandle handle_for_process; |
453 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) | 458 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) |
454 return; // This can legitimately fail if the renderer asserts at startup. | 459 return; // This can legitimately fail if the renderer asserts at startup. |
455 | 460 |
456 if (base::SharedMemory::IsHandleValid(handle_for_process)) | 461 if (base::SharedMemory::IsHandleValid(handle_for_process)) |
457 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process)); | 462 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process)); |
458 } | 463 } |
459 | 464 |
460 } // namespace extensions | 465 } // namespace extensions |
OLD | NEW |