summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-02-20 12:30:20 +0100
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-02-20 17:31:44 +0000
commit88ca68c1b3ceff005f6a3a33fc8fc0d551c53a70 (patch)
treef9f69f684c4cb9dd1c24313acec78cd23c3d0724 /src/core
parent61dec11a8bc36d37ed36acc6ad897653735d4564 (diff)
Synchronize with QAtomic instead of volatile
Replaces the three volatile bool with two atomic ints and an atomic pointer. Change-Id: Iad41aef4952bbf7de77523ffd729bd00ace68ee9 Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/url_request_context_getter_qt.cpp44
-rw-r--r--src/core/url_request_context_getter_qt.h10
2 files changed, 26 insertions, 28 deletions
diff --git a/src/core/url_request_context_getter_qt.cpp b/src/core/url_request_context_getter_qt.cpp
index 0a604eaaa..2536e9ddb 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 953481e2d..8e8d91596 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;