OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/user_script_loader.h" | 5 #include "extensions/browser/user_script_loader.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 void UserScriptLoader::SetReady(bool ready) { | 352 void UserScriptLoader::SetReady(bool ready) { |
353 bool was_ready = ready_; | 353 bool was_ready = ready_; |
354 ready_ = ready; | 354 ready_ = ready; |
355 if (ready_ && !was_ready) | 355 if (ready_ && !was_ready) |
356 AttemptLoad(); | 356 AttemptLoad(); |
357 } | 357 } |
358 | 358 |
359 void UserScriptLoader::OnScriptsLoaded( | 359 void UserScriptLoader::OnScriptsLoaded( |
360 std::unique_ptr<UserScriptList> user_scripts, | 360 std::unique_ptr<UserScriptList> user_scripts, |
361 std::unique_ptr<base::SharedMemory> shared_memory) { | 361 std::unique_ptr<base::SharedMemory> shared_memory) { |
362 user_scripts_.reset(user_scripts.release()); | 362 user_scripts_ = std::move(user_scripts); |
363 if (pending_load_) { | 363 if (pending_load_) { |
364 // While we were loading, there were further changes. Don't bother | 364 // While we were loading, there were further changes. Don't bother |
365 // notifying about these scripts and instead just immediately reload. | 365 // notifying about these scripts and instead just immediately reload. |
366 pending_load_ = false; | 366 pending_load_ = false; |
367 StartLoad(); | 367 StartLoad(); |
368 return; | 368 return; |
369 } | 369 } |
370 | 370 |
371 if (shared_memory.get() == NULL) { | 371 if (shared_memory.get() == NULL) { |
372 // This can happen if we run out of file descriptors. In that case, we | 372 // This can happen if we run out of file descriptors. In that case, we |
373 // have a choice between silently omitting all user scripts for new tabs, | 373 // have a choice between silently omitting all user scripts for new tabs, |
374 // by nulling out shared_memory_, or only silently omitting new ones by | 374 // by nulling out shared_memory_, or only silently omitting new ones by |
375 // leaving the existing object in place. The second seems less bad, even | 375 // leaving the existing object in place. The second seems less bad, even |
376 // though it removes the possibility that freeing the shared memory block | 376 // though it removes the possibility that freeing the shared memory block |
377 // would open up enough FDs for long enough for a retry to succeed. | 377 // would open up enough FDs for long enough for a retry to succeed. |
378 | 378 |
379 // Pretend the extension change didn't happen. | 379 // Pretend the extension change didn't happen. |
380 return; | 380 return; |
381 } | 381 } |
382 | 382 |
383 // We've got scripts ready to go. | 383 // We've got scripts ready to go. |
384 shared_memory_.reset(shared_memory.release()); | 384 shared_memory_ = std::move(shared_memory); |
385 | 385 |
386 for (content::RenderProcessHost::iterator i( | 386 for (content::RenderProcessHost::iterator i( |
387 content::RenderProcessHost::AllHostsIterator()); | 387 content::RenderProcessHost::AllHostsIterator()); |
388 !i.IsAtEnd(); i.Advance()) { | 388 !i.IsAtEnd(); i.Advance()) { |
389 SendUpdate(i.GetCurrentValue(), shared_memory_.get(), changed_hosts_); | 389 SendUpdate(i.GetCurrentValue(), shared_memory_.get(), changed_hosts_); |
390 } | 390 } |
391 changed_hosts_.clear(); | 391 changed_hosts_.clear(); |
392 | 392 |
393 // TODO(hanxi): Remove the NOTIFICATION_USER_SCRIPTS_UPDATED. | 393 // TODO(hanxi): Remove the NOTIFICATION_USER_SCRIPTS_UPDATED. |
394 content::NotificationService::current()->Notify( | 394 content::NotificationService::current()->Notify( |
(...skipping 26 matching lines...) Expand all Loading... |
421 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) | 421 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) |
422 return; // This can legitimately fail if the renderer asserts at startup. | 422 return; // This can legitimately fail if the renderer asserts at startup. |
423 | 423 |
424 if (base::SharedMemory::IsHandleValid(handle_for_process)) { | 424 if (base::SharedMemory::IsHandleValid(handle_for_process)) { |
425 process->Send(new ExtensionMsg_UpdateUserScripts( | 425 process->Send(new ExtensionMsg_UpdateUserScripts( |
426 handle_for_process, host_id(), changed_hosts, whitelisted_only)); | 426 handle_for_process, host_id(), changed_hosts, whitelisted_only)); |
427 } | 427 } |
428 } | 428 } |
429 | 429 |
430 } // namespace extensions | 430 } // namespace extensions |
OLD | NEW |