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

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

Issue 27265002: Implement SharedMemory::NewAnonymousReadOnly(contents). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Mark's comments Created 7 years, 1 month 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
« no previous file with comments | « base/memory/shared_memory_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 base::StringPiece contents = script.js_scripts()[j].GetContent(); 278 base::StringPiece contents = script.js_scripts()[j].GetContent();
279 pickle.WriteData(contents.data(), contents.length()); 279 pickle.WriteData(contents.data(), contents.length());
280 } 280 }
281 for (size_t j = 0; j < script.css_scripts().size(); j++) { 281 for (size_t j = 0; j < script.css_scripts().size(); j++) {
282 base::StringPiece contents = script.css_scripts()[j].GetContent(); 282 base::StringPiece contents = script.css_scripts()[j].GetContent();
283 pickle.WriteData(contents.data(), contents.length()); 283 pickle.WriteData(contents.data(), contents.length());
284 } 284 }
285 } 285 }
286 286
287 // Create the shared memory object. 287 // Create the shared memory object.
288 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); 288 base::SharedMemory shared_memory;
289 289
290 if (!shared_memory->CreateAndMapAnonymous(pickle.size())) 290 if (!shared_memory.CreateAndMapAnonymous(pickle.size()))
291 return NULL; 291 return NULL;
292 292
293 // Copy the pickle to shared memory. 293 // Copy the pickle to shared memory.
294 memcpy(shared_memory->memory(), pickle.data(), pickle.size()); 294 memcpy(shared_memory.memory(), pickle.data(), pickle.size());
295 295
296 return shared_memory.release(); 296 base::SharedMemoryHandle readonly_handle;
297 if (!shared_memory.ShareReadOnlyToProcess(base::GetCurrentProcessHandle(),
298 &readonly_handle))
299 return NULL;
300
301 return new base::SharedMemory(readonly_handle, /*read_only=*/true);
297 } 302 }
298 303
299 // This method will be called on the file thread. 304 // This method will be called on the file thread.
300 void UserScriptMaster::ScriptReloader::RunLoad( 305 void UserScriptMaster::ScriptReloader::RunLoad(
301 const UserScriptList& user_scripts) { 306 const UserScriptList& user_scripts) {
302 LoadUserScripts(const_cast<UserScriptList*>(&user_scripts)); 307 LoadUserScripts(const_cast<UserScriptList*>(&user_scripts));
303 308
304 // Scripts now contains list of up-to-date scripts. Load the content in the 309 // Scripts now contains list of up-to-date scripts. Load the content in the
305 // shared memory and let the master know it's ready. We need to post the task 310 // shared memory and let the master know it's ready. We need to post the task
306 // back even if no scripts ware found to balance the AddRef/Release calls. 311 // back even if no scripts ware found to balance the AddRef/Release calls.
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 458
454 base::SharedMemoryHandle handle_for_process; 459 base::SharedMemoryHandle handle_for_process;
455 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) 460 if (!shared_memory->ShareToProcess(handle, &handle_for_process))
456 return; // This can legitimately fail if the renderer asserts at startup. 461 return; // This can legitimately fail if the renderer asserts at startup.
457 462
458 if (base::SharedMemory::IsHandleValid(handle_for_process)) 463 if (base::SharedMemory::IsHandleValid(handle_for_process))
459 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process)); 464 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process));
460 } 465 }
461 466
462 } // namespace extensions 467 } // namespace extensions
OLDNEW
« no previous file with comments | « base/memory/shared_memory_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698