diff --git a/src/core/url_request_context_getter_qt.cpp b/src/core/url_request_context_getter_qt.cpp index 0a604eaaa4e9157935961e42b7eb9be68bb96f0e..2536e9ddbf25c9f32f73859f2b5ec16abcd30248 100644 --- a/src/core/url_request_context_getter_qt.cpp +++ b/src/core/url_request_context_getter_qt.cpp @@ -75,9 +75,6 @@ using content::BrowserThread; URLRequestContextGetterQt::URLRequestContextGetterQt(BrowserContextAdapter *browserContext, content::ProtocolHandlerMap *protocolHandlers) : m_ignoreCertificateErrors(false) - , m_updateStorageSettings(false) - , m_updateCookieStore(false) - , m_updateHttpCache(false) , m_browserContext(browserContext) { std::swap(m_protocolHandlers, *protocolHandlers); @@ -85,6 +82,11 @@ URLRequestContextGetterQt::URLRequestContextGetterQt(BrowserContextAdapter *brow updateStorageSettings(); } +URLRequestContextGetterQt::~URLRequestContextGetterQt() +{ + delete m_proxyConfigService.fetchAndStoreAcquire(0); +} + net::URLRequestContext *URLRequestContextGetterQt::GetURLRequestContext() { if (!m_urlRequestContext) { @@ -103,31 +105,28 @@ net::URLRequestContext *URLRequestContextGetterQt::GetURLRequestContext() void URLRequestContextGetterQt::updateStorageSettings() { Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - if (!m_proxyConfigService) { + if (!m_proxyConfigService.loadAcquire()) { // We must create the proxy config service on the UI loop on Linux because it // must synchronously run on the glib message loop. This will be passed to // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). - m_proxyConfigService.reset(net::ProxyService::CreateSystemProxyConfigService( + m_proxyConfigService = net::ProxyService::CreateSystemProxyConfigService( content::BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), - content::BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)) + content::BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE) ); - } - if (m_storage && !m_updateStorageSettings) { - m_updateStorageSettings = true; - content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestContextGetterQt::generateStorage, this)); + if (m_storage) + content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestContextGetterQt::generateStorage, this)); } } void URLRequestContextGetterQt::generateStorage() { Q_ASSERT(m_urlRequestContext); - Q_ASSERT(m_proxyConfigService); - if (!m_proxyConfigService) - return; - m_updateStorageSettings = false; m_storage.reset(new net::URLRequestContextStorage(m_urlRequestContext.get())); + net::ProxyConfigService *proxyConfigService = m_proxyConfigService.fetchAndStoreAcquire(0); + Q_ASSERT(proxyConfigService); + generateCookieStore(); generateUserAgent(); @@ -136,8 +135,7 @@ void URLRequestContextGetterQt::generateStorage() base::WorkerPool::GetTaskRunner(true))); m_storage->set_cert_verifier(net::CertVerifier::CreateDefault()); - m_storage->set_proxy_service(net::ProxyService::CreateUsingSystemProxyResolver( - m_proxyConfigService.release(), 0, NULL)); + m_storage->set_proxy_service(net::ProxyService::CreateUsingSystemProxyResolver(proxyConfigService, 0, NULL)); m_storage->set_ssl_config_service(new net::SSLConfigServiceDefaults); m_storage->set_transport_security_state(new net::TransportSecurityState()); @@ -153,8 +151,8 @@ void URLRequestContextGetterQt::generateStorage() void URLRequestContextGetterQt::updateCookieStore() { - if (m_urlRequestContext && !m_updateCookieStore && !m_updateStorageSettings) { - m_updateCookieStore = true; + if (m_urlRequestContext && !m_updateCookieStore && !m_proxyConfigService) { + m_updateCookieStore = 1; content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestContextGetterQt::generateCookieStore, this)); } } @@ -163,7 +161,7 @@ void URLRequestContextGetterQt::generateCookieStore() { Q_ASSERT(m_urlRequestContext); Q_ASSERT(m_storage); - m_updateCookieStore = false; + m_updateCookieStore = 0; // Unset it first to get a chance to destroy and flush the old cookie store before before opening a new on possibly the same file. m_storage->set_cookie_store(0); @@ -200,7 +198,7 @@ void URLRequestContextGetterQt::generateCookieStore() void URLRequestContextGetterQt::updateUserAgent() { - if (m_urlRequestContext && !m_updateStorageSettings) + if (m_urlRequestContext && !m_proxyConfigService) content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestContextGetterQt::generateUserAgent, this)); } @@ -215,8 +213,8 @@ void URLRequestContextGetterQt::generateUserAgent() void URLRequestContextGetterQt::updateHttpCache() { - if (m_urlRequestContext && !m_updateHttpCache && !m_updateStorageSettings) { - m_updateHttpCache = true; + if (m_urlRequestContext && !m_updateHttpCache && !m_proxyConfigService) { + m_updateHttpCache = 1; content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestContextGetterQt::generateHttpCache, this)); } } @@ -225,7 +223,7 @@ void URLRequestContextGetterQt::generateHttpCache() { Q_ASSERT(m_urlRequestContext); Q_ASSERT(m_storage); - m_updateHttpCache = false; + m_updateHttpCache = 0; net::HttpCache::DefaultBackend* main_backend = 0; switch (m_browserContext->httpCacheType()) { diff --git a/src/core/url_request_context_getter_qt.h b/src/core/url_request_context_getter_qt.h index 953481e2d3cd1e1ac9b1fe0ce4137fdbf7dc4b26..8e8d9159662d785217e000a37f4961493defe958 100644 --- a/src/core/url_request_context_getter_qt.h +++ b/src/core/url_request_context_getter_qt.h @@ -49,6 +49,7 @@ #include "net/url_request/url_request_job_factory_impl.h" #include "qglobal.h" +#include <qatomic.h> namespace net { class MappedHostResolver; @@ -72,7 +73,7 @@ public: void updateHttpCache(); private: - virtual ~URLRequestContextGetterQt() {} + virtual ~URLRequestContextGetterQt(); // Called on the IO thread: void generateStorage(); @@ -82,13 +83,12 @@ private: void generateJobFactory(); bool m_ignoreCertificateErrors; - volatile bool m_updateStorageSettings; - volatile bool m_updateCookieStore; - volatile bool m_updateHttpCache; + QAtomicInt m_updateCookieStore; + QAtomicInt m_updateHttpCache; BrowserContextAdapter *m_browserContext; content::ProtocolHandlerMap m_protocolHandlers; - scoped_ptr<net::ProxyConfigService> m_proxyConfigService; + QAtomicPointer<net::ProxyConfigService> m_proxyConfigService; scoped_ptr<net::URLRequestContext> m_urlRequestContext; scoped_ptr<net::NetworkDelegate> m_networkDelegate; scoped_ptr<net::URLRequestContextStorage> m_storage;