summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/browser_process_impl.cc8
-rw-r--r--chrome/browser/extensions/user_script_listener.cc21
-rw-r--r--chrome/browser/extensions/user_script_listener.h13
-rw-r--r--chrome/browser/extensions/user_script_listener_unittest.cc2
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host.cc9
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host.h6
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host_unittest.cc1
-rw-r--r--content/browser/renderer_host/resource_queue.cc3
-rw-r--r--content/browser/renderer_host/resource_queue.h4
-rw-r--r--content/browser/renderer_host/resource_queue_unittest.cc18
10 files changed, 54 insertions, 31 deletions
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 7391971..01e7038 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -26,6 +26,7 @@
#include "chrome/browser/download/save_file_manager.h"
#include "chrome/browser/extensions/extension_event_router_forwarder.h"
#include "chrome/browser/extensions/extension_tab_id_map.h"
+#include "chrome/browser/extensions/user_script_listener.h"
#include "chrome/browser/first_run/first_run.h"
#include "chrome/browser/google/google_url_tracker.h"
#include "chrome/browser/gpu_process_host_ui_shim.h"
@@ -682,7 +683,12 @@ void BrowserProcessImpl::CreateResourceDispatcherHost() {
resource_dispatcher_host_.get() == NULL);
created_resource_dispatcher_host_ = true;
- resource_dispatcher_host_.reset(new ResourceDispatcherHost());
+ // UserScriptListener will delete itself.
+ ResourceQueue::DelegateSet resource_queue_delegates;
+ resource_queue_delegates.insert(new UserScriptListener());
+
+ resource_dispatcher_host_.reset(
+ new ResourceDispatcherHost(resource_queue_delegates));
resource_dispatcher_host_->Initialize();
}
diff --git a/chrome/browser/extensions/user_script_listener.cc b/chrome/browser/extensions/user_script_listener.cc
index 8247d87..8586b0e 100644
--- a/chrome/browser/extensions/user_script_listener.cc
+++ b/chrome/browser/extensions/user_script_listener.cc
@@ -14,11 +14,10 @@
#include "content/common/notification_service.h"
#include "net/url_request/url_request.h"
-UserScriptListener::UserScriptListener(ResourceQueue* resource_queue)
- : resource_queue_(resource_queue),
+UserScriptListener::UserScriptListener()
+ : resource_queue_(NULL),
user_scripts_ready_(false) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(resource_queue_);
registrar_.Add(this, NotificationType::EXTENSION_LOADED,
NotificationService::AllSources());
@@ -26,11 +25,11 @@ UserScriptListener::UserScriptListener(ResourceQueue* resource_queue)
NotificationService::AllSources());
registrar_.Add(this, NotificationType::USER_SCRIPTS_UPDATED,
NotificationService::AllSources());
+ AddRef(); // Will be balanced in Cleanup().
}
-void UserScriptListener::ShutdownMainThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- registrar_.RemoveAll();
+void UserScriptListener::Initialize(ResourceQueue* resource_queue) {
+ resource_queue_ = resource_queue;
}
bool UserScriptListener::ShouldDelayRequest(
@@ -65,6 +64,10 @@ bool UserScriptListener::ShouldDelayRequest(
void UserScriptListener::WillShutdownResourceQueue() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
resource_queue_ = NULL;
+
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &UserScriptListener::Cleanup));
}
UserScriptListener::~UserScriptListener() {
@@ -98,6 +101,12 @@ void UserScriptListener::ReplaceURLPatterns(const URLPatterns& patterns) {
url_patterns_ = patterns;
}
+void UserScriptListener::Cleanup() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ registrar_.RemoveAll();
+ Release();
+}
+
void UserScriptListener::CollectURLPatterns(const Extension* extension,
URLPatterns* patterns) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
diff --git a/chrome/browser/extensions/user_script_listener.h b/chrome/browser/extensions/user_script_listener.h
index c771a12..f23d471 100644
--- a/chrome/browser/extensions/user_script_listener.h
+++ b/chrome/browser/extensions/user_script_listener.h
@@ -27,19 +27,17 @@ struct GlobalRequestID;
// request.
//
// This class lives mostly on the IO thread. It listens on the UI thread for
-// updates to loaded extensions.
+// updates to loaded extensions. It will delete itself on the UI thread after
+// WillShutdownResourceQueue is called (on the IO thread).
class UserScriptListener
: public base::RefCountedThreadSafe<UserScriptListener>,
public ResourceQueueDelegate,
public NotificationObserver {
public:
- explicit UserScriptListener(ResourceQueue* resource_queue);
-
- // Call this to do necessary cleanup on the main thread before the object
- // is deleted.
- void ShutdownMainThread();
+ UserScriptListener();
// ResourceQueueDelegate:
+ virtual void Initialize(ResourceQueue* resource_queue);
virtual bool ShouldDelayRequest(
net::URLRequest* request,
const ResourceDispatcherHostRequestInfo& request_info,
@@ -64,6 +62,9 @@ class UserScriptListener
// deleted, so user_scripts_ready_ remains unchanged.
void ReplaceURLPatterns(const URLPatterns& patterns);
+ // Cleanup on UI thread.
+ void Cleanup();
+
ResourceQueue* resource_queue_;
// A list of every request that we delayed. Will be flushed when user scripts
diff --git a/chrome/browser/extensions/user_script_listener_unittest.cc b/chrome/browser/extensions/user_script_listener_unittest.cc
index e877bcc..894a397 100644
--- a/chrome/browser/extensions/user_script_listener_unittest.cc
+++ b/chrome/browser/extensions/user_script_listener_unittest.cc
@@ -121,7 +121,7 @@ class UserScriptListenerTest
service_->Init();
MessageLoop::current()->RunAllPending();
- listener_ = new UserScriptListener(&resource_queue_);
+ listener_ = new UserScriptListener();
ResourceQueue::DelegateSet delegates;
delegates.insert(listener_.get());
diff --git a/content/browser/renderer_host/resource_dispatcher_host.cc b/content/browser/renderer_host/resource_dispatcher_host.cc
index d746e15..0e3fafc 100644
--- a/content/browser/renderer_host/resource_dispatcher_host.cc
+++ b/content/browser/renderer_host/resource_dispatcher_host.cc
@@ -22,7 +22,6 @@
#include "chrome/browser/download/download_request_limiter.h"
#include "chrome/browser/download/download_util.h"
#include "chrome/browser/download/save_file_manager.h"
-#include "chrome/browser/extensions/user_script_listener.h"
#include "chrome/browser/external_protocol_handler.h"
#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/browser/net/url_request_tracking.h"
@@ -208,13 +207,13 @@ std::vector<int> GetAllNetErrorCodes() {
} // namespace
-ResourceDispatcherHost::ResourceDispatcherHost()
+ResourceDispatcherHost::ResourceDispatcherHost(
+ const ResourceQueue::DelegateSet& resource_queue_delegates)
: ALLOW_THIS_IN_INITIALIZER_LIST(
download_file_manager_(new DownloadFileManager(this))),
download_request_limiter_(new DownloadRequestLimiter()),
ALLOW_THIS_IN_INITIALIZER_LIST(
save_file_manager_(new SaveFileManager(this))),
- user_script_listener_(new UserScriptListener(&resource_queue_)),
safe_browsing_(SafeBrowsingService::CreateSafeBrowsingService()),
webkit_thread_(new WebKitThread),
request_id_(-1),
@@ -223,16 +222,12 @@ ResourceDispatcherHost::ResourceDispatcherHost()
max_outstanding_requests_cost_per_process_(
kMaxOutstandingRequestsCostPerProcess),
filter_(NULL) {
- ResourceQueue::DelegateSet resource_queue_delegates;
- resource_queue_delegates.insert(user_script_listener_.get());
resource_queue_.Initialize(resource_queue_delegates);
}
ResourceDispatcherHost::~ResourceDispatcherHost() {
AsyncResourceHandler::GlobalCleanup();
STLDeleteValues(&pending_requests_);
-
- user_script_listener_->ShutdownMainThread();
}
void ResourceDispatcherHost::Initialize() {
diff --git a/content/browser/renderer_host/resource_dispatcher_host.h b/content/browser/renderer_host/resource_dispatcher_host.h
index 278c7f2..e3ff805 100644
--- a/content/browser/renderer_host/resource_dispatcher_host.h
+++ b/content/browser/renderer_host/resource_dispatcher_host.h
@@ -41,7 +41,6 @@ class ResourceMessageFilter;
class SafeBrowsingService;
class SaveFileManager;
class SSLClientAuthHandler;
-class UserScriptListener;
class WebKitThread;
struct DownloadSaveInfo;
struct GlobalRequestID;
@@ -71,7 +70,8 @@ class ResourceDispatcherHost : public net::URLRequest::Delegate {
const GURL& new_url) = 0;
};
- ResourceDispatcherHost();
+ explicit ResourceDispatcherHost(
+ const ResourceQueue::DelegateSet& resource_queue_delegates);
~ResourceDispatcherHost();
void Initialize();
@@ -461,8 +461,6 @@ class ResourceDispatcherHost : public net::URLRequest::Delegate {
// We own the save file manager.
scoped_refptr<SaveFileManager> save_file_manager_;
- scoped_refptr<UserScriptListener> user_script_listener_;
-
scoped_refptr<SafeBrowsingService> safe_browsing_;
// We own the WebKit thread and see to its destruction.
diff --git a/content/browser/renderer_host/resource_dispatcher_host_unittest.cc b/content/browser/renderer_host/resource_dispatcher_host_unittest.cc
index 01e55e3..f94d2b2 100644
--- a/content/browser/renderer_host/resource_dispatcher_host_unittest.cc
+++ b/content/browser/renderer_host/resource_dispatcher_host_unittest.cc
@@ -155,6 +155,7 @@ class ResourceDispatcherHostTest : public testing::Test,
: ALLOW_THIS_IN_INITIALIZER_LIST(filter_(new ForwardingFilter(this))),
ui_thread_(BrowserThread::UI, &message_loop_),
io_thread_(BrowserThread::IO, &message_loop_),
+ host_(ResourceQueue::DelegateSet()),
old_factory_(NULL),
resource_type_(ResourceType::SUB_RESOURCE) {
}
diff --git a/content/browser/renderer_host/resource_queue.cc b/content/browser/renderer_host/resource_queue.cc
index 98eddd6..d08b246 100644
--- a/content/browser/renderer_host/resource_queue.cc
+++ b/content/browser/renderer_host/resource_queue.cc
@@ -24,6 +24,9 @@ void ResourceQueue::Initialize(const DelegateSet& delegates) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(delegates_.empty());
delegates_ = delegates;
+
+ for (DelegateSet::iterator i = delegates_.begin(); i != delegates_.end(); ++i)
+ (*i)->Initialize(this);
}
void ResourceQueue::Shutdown() {
diff --git a/content/browser/renderer_host/resource_queue.h b/content/browser/renderer_host/resource_queue.h
index 4bf45d9..835b367 100644
--- a/content/browser/renderer_host/resource_queue.h
+++ b/content/browser/renderer_host/resource_queue.h
@@ -16,12 +16,16 @@ class URLRequest;
} // namespace net
class ResourceDispatcherHostRequestInfo;
+class ResourceQueue;
struct GlobalRequestID;
// Makes decisions about delaying or not each net::URLRequest in the queue.
// All methods are called on the IO thread.
class ResourceQueueDelegate {
public:
+ // Gives the delegate a pointer to the queue object.
+ virtual void Initialize(ResourceQueue* resource_queue) = 0;
+
// Should return true if it wants the |request| to not be started at this
// point. To start the delayed request, ResourceQueue::StartDelayedRequest
// should be used.
diff --git a/content/browser/renderer_host/resource_queue_unittest.cc b/content/browser/renderer_host/resource_queue_unittest.cc
index 3d54729..cf6e669 100644
--- a/content/browser/renderer_host/resource_queue_unittest.cc
+++ b/content/browser/renderer_host/resource_queue_unittest.cc
@@ -98,6 +98,9 @@ class NeverDelayingDelegate : public ResourceQueueDelegate {
NeverDelayingDelegate() {
}
+ virtual void Initialize(ResourceQueue* resource_queue) {
+ }
+
virtual bool ShouldDelayRequest(
net::URLRequest* request,
const ResourceDispatcherHostRequestInfo& request_info,
@@ -114,8 +117,11 @@ class NeverDelayingDelegate : public ResourceQueueDelegate {
class AlwaysDelayingDelegate : public ResourceQueueDelegate {
public:
- explicit AlwaysDelayingDelegate(ResourceQueue* resource_queue)
- : resource_queue_(resource_queue) {
+ AlwaysDelayingDelegate() : resource_queue_(NULL) {
+ }
+
+ virtual void Initialize(ResourceQueue* resource_queue) {
+ resource_queue_ = resource_queue;
}
virtual bool ShouldDelayRequest(
@@ -205,7 +211,7 @@ TEST_F(ResourceQueueTest, NeverDelayingDelegate) {
TEST_F(ResourceQueueTest, AlwaysDelayingDelegate) {
ResourceQueue queue;
- AlwaysDelayingDelegate delegate(&queue);
+ AlwaysDelayingDelegate delegate;
InitializeQueue(&queue, &delegate);
net::URLRequest request(GURL(kTestUrl), this);
@@ -224,7 +230,7 @@ TEST_F(ResourceQueueTest, AlwaysDelayingDelegate) {
TEST_F(ResourceQueueTest, AlwaysDelayingDelegateAfterShutdown) {
ResourceQueue queue;
- AlwaysDelayingDelegate delegate(&queue);
+ AlwaysDelayingDelegate delegate;
InitializeQueue(&queue, &delegate);
net::URLRequest request(GURL(kTestUrl), this);
@@ -244,7 +250,7 @@ TEST_F(ResourceQueueTest, AlwaysDelayingDelegateAfterShutdown) {
TEST_F(ResourceQueueTest, TwoDelegates) {
ResourceQueue queue;
- AlwaysDelayingDelegate always_delaying_delegate(&queue);
+ AlwaysDelayingDelegate always_delaying_delegate;
NeverDelayingDelegate never_delaying_delegate;
InitializeQueue(&queue, &always_delaying_delegate, &never_delaying_delegate);
@@ -264,7 +270,7 @@ TEST_F(ResourceQueueTest, TwoDelegates) {
TEST_F(ResourceQueueTest, RemoveRequest) {
ResourceQueue queue;
- AlwaysDelayingDelegate delegate(&queue);
+ AlwaysDelayingDelegate delegate;
InitializeQueue(&queue, &delegate);
net::URLRequest request(GURL(kTestUrl), this);