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

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: Add errno.h Created 7 years, 2 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) 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 for (size_t j = 0; j < script.js_scripts().size(); j++) { 276 for (size_t j = 0; j < script.js_scripts().size(); j++) {
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 return base::SharedMemory::NewAnonymousReadOnly(
287 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); 287 base::StringPiece(static_cast<const char*>(pickle.data()), pickle.size()))
288 288 .release();
289 if (!shared_memory->CreateAndMapAnonymous(pickle.size()))
290 return NULL;
291
292 // Copy the pickle to shared memory.
293 memcpy(shared_memory->memory(), pickle.data(), pickle.size());
294
295 return shared_memory.release();
296 } 289 }
297 290
298 // This method will be called on the file thread. 291 // This method will be called on the file thread.
299 void UserScriptMaster::ScriptReloader::RunLoad( 292 void UserScriptMaster::ScriptReloader::RunLoad(
300 const UserScriptList& user_scripts) { 293 const UserScriptList& user_scripts) {
301 LoadUserScripts(const_cast<UserScriptList*>(&user_scripts)); 294 LoadUserScripts(const_cast<UserScriptList*>(&user_scripts));
302 295
303 // Scripts now contains list of up-to-date scripts. Load the content in the 296 // 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 297 // 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. 298 // 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
451 444
452 base::SharedMemoryHandle handle_for_process; 445 base::SharedMemoryHandle handle_for_process;
453 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) 446 if (!shared_memory->ShareToProcess(handle, &handle_for_process))
454 return; // This can legitimately fail if the renderer asserts at startup. 447 return; // This can legitimately fail if the renderer asserts at startup.
455 448
456 if (base::SharedMemory::IsHandleValid(handle_for_process)) 449 if (base::SharedMemory::IsHandleValid(handle_for_process))
457 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process)); 450 process->Send(new ExtensionMsg_UpdateUserScripts(handle_for_process));
458 } 451 }
459 452
460 } // namespace extensions 453 } // namespace extensions
OLDNEW
« base/memory/shared_memory_unittest.cc ('K') | « base/memory/shared_memory_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698