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

Side by Side Diff: chrome/browser/renderer_host/buffered_resource_handler.cc

Issue 342068: Third patch in getting rid of caching MessageLoop pointers and always using C... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/renderer_host/buffered_resource_handler.h" 5 #include "chrome/browser/renderer_host/buffered_resource_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/histogram.h" 9 #include "base/histogram.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 397
398 // Schedule plugin loading on the file thread. 398 // Schedule plugin loading on the file thread.
399 // Note: it's possible that the only reference to this object is the task. If 399 // Note: it's possible that the only reference to this object is the task. If
400 // If the task executes on the file thread, and before it returns, the task it 400 // If the task executes on the file thread, and before it returns, the task it
401 // posts to the IO thread runs, then this object will get destructed on the 401 // posts to the IO thread runs, then this object will get destructed on the
402 // file thread. This breaks assumptions in other message handlers (i.e. when 402 // file thread. This breaks assumptions in other message handlers (i.e. when
403 // unregistering with NotificationService in the destructor). 403 // unregistering with NotificationService in the destructor).
404 AddRef(); 404 AddRef();
405 ChromeThread::PostTask( 405 ChromeThread::PostTask(
406 ChromeThread::FILE, FROM_HERE, 406 ChromeThread::FILE, FROM_HERE,
407 NewRunnableFunction(&BufferedResourceHandler::LoadPlugins, 407 NewRunnableFunction(&BufferedResourceHandler::LoadPlugins, this));
408 this, host_->ui_loop()));
409 return true; 408 return true;
410 } 409 }
411 410
412 // This test mirrors the decision that WebKit makes in 411 // This test mirrors the decision that WebKit makes in
413 // WebFrameLoaderClient::dispatchDecidePolicyForMIMEType. 412 // WebFrameLoaderClient::dispatchDecidePolicyForMIMEType.
414 bool BufferedResourceHandler::ShouldDownload(bool* need_plugin_list) { 413 bool BufferedResourceHandler::ShouldDownload(bool* need_plugin_list) {
415 if (need_plugin_list) 414 if (need_plugin_list)
416 *need_plugin_list = false; 415 *need_plugin_list = false;
417 std::string type = StringToLowerASCII(response_->response_head.mime_type); 416 std::string type = StringToLowerASCII(response_->response_head.mime_type);
418 std::string disposition; 417 std::string disposition;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 DCHECK(NPAPI::PluginList::Singleton()->PluginsLoaded()); 461 DCHECK(NPAPI::PluginList::Singleton()->PluginsLoaded());
463 } 462 }
464 463
465 // Finally, check the plugin list. 464 // Finally, check the plugin list.
466 WebPluginInfo info; 465 WebPluginInfo info;
467 bool allow_wildcard = false; 466 bool allow_wildcard = false;
468 return !NPAPI::PluginList::Singleton()->GetPluginInfo( 467 return !NPAPI::PluginList::Singleton()->GetPluginInfo(
469 GURL(), type, allow_wildcard, &info, NULL); 468 GURL(), type, allow_wildcard, &info, NULL);
470 } 469 }
471 470
472 void BufferedResourceHandler::LoadPlugins(BufferedResourceHandler* handler, 471 void BufferedResourceHandler::LoadPlugins(BufferedResourceHandler* handler) {
473 MessageLoop* main_message_loop) {
474 std::vector<WebPluginInfo> plugins; 472 std::vector<WebPluginInfo> plugins;
475 NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins); 473 NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins);
476 474
477 // Note, we want to get to the IO thread now, but the file thread outlives it 475 ChromeThread::PostTask(
478 // so we can't post a task to it directly as it might be in the middle of 476 ChromeThread::IO, FROM_HERE,
479 // destruction. So hop through the main thread, where the destruction of the 477 NewRunnableFunction(&BufferedResourceHandler::OnPluginsLoaded,
480 // IO thread happens and hence no race conditions exist.
481 main_message_loop->PostTask(FROM_HERE,
482 NewRunnableFunction(&BufferedResourceHandler::NotifyPluginsLoaded,
483 handler)); 478 handler));
484 } 479 }
485 480
486 void BufferedResourceHandler::NotifyPluginsLoaded( 481 void BufferedResourceHandler::OnPluginsLoaded(
487 BufferedResourceHandler* handler) { 482 BufferedResourceHandler* handler) {
488 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, 483 handler->wait_for_plugins_ = false;
489 NewRunnableMethod(handler, &BufferedResourceHandler::OnPluginsLoaded)); 484 if (handler->request_) {
485 ResourceDispatcherHostRequestInfo* info =
486 ResourceDispatcherHost::InfoForRequest(handler->request_);
487 handler->host_->PauseRequest(info->child_id(), info->request_id(), false);
488 if (!handler->CompleteResponseStarted(info->request_id(), false))
489 handler->host_->CancelRequest(
490 info->child_id(), info->request_id(), false);
491 }
492 handler->Release();
490 } 493 }
491
492 void BufferedResourceHandler::OnPluginsLoaded() {
493 wait_for_plugins_ = false;
494 if (request_) {
495 ResourceDispatcherHostRequestInfo* info =
496 ResourceDispatcherHost::InfoForRequest(request_);
497 host_->PauseRequest(info->child_id(), info->request_id(), false);
498 if (!CompleteResponseStarted(info->request_id(), false))
499 host_->CancelRequest(info->child_id(), info->request_id(), false);
500 }
501 Release();
502 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/buffered_resource_handler.h ('k') | chrome/browser/renderer_host/render_widget_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698