diff options
author | droger <droger@chromium.org> | 2015-10-21 14:45:15 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-21 21:46:26 +0000 |
commit | 876c90d6163af7a7187ea6f68ebdbab7bc9a9580 (patch) | |
tree | 11f77fff8501c86e0d8f917a4651f3649a6308b6 /ios/net | |
parent | 4b67fc6b07db9fe1b6360f4e5fba2b97fb37acf2 (diff) | |
download | chromium_src-876c90d6163af7a7187ea6f68ebdbab7bc9a9580.zip chromium_src-876c90d6163af7a7187ea6f68ebdbab7bc9a9580.tar.gz chromium_src-876c90d6163af7a7187ea6f68ebdbab7bc9a9580.tar.bz2 |
[iOS] Split CrNet cache clearing to a helper file.
The new code clears SDCH and QUIC data that were not cleared
in CrNet previously, and thus this changes the CrNet behavior
slightly.
BUG=527722
Review URL: https://codereview.chromium.org/1393973003
Cr-Commit-Position: refs/heads/master@{#355405}
Diffstat (limited to 'ios/net')
-rw-r--r-- | ios/net/http_cache_helper.cc | 94 | ||||
-rw-r--r-- | ios/net/http_cache_helper.h | 26 | ||||
-rw-r--r-- | ios/net/ios_net.gyp | 2 |
3 files changed, 122 insertions, 0 deletions
diff --git a/ios/net/http_cache_helper.cc b/ios/net/http_cache_helper.cc new file mode 100644 index 0000000..4e67b98 --- /dev/null +++ b/ios/net/http_cache_helper.cc @@ -0,0 +1,94 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ios/net/http_cache_helper.h" + +#include "base/bind.h" +#include "base/bind_helpers.h" +#include "base/callback.h" +#include "base/location.h" +#include "base/task_runner.h" +#include "net/base/sdch_manager.h" +#include "net/disk_cache/disk_cache.h" +#include "net/http/http_cache.h" +#include "net/http/http_network_session.h" +#include "net/http/http_transaction_factory.h" +#include "net/quic/quic_stream_factory.h" +#include "net/url_request/url_request_context.h" +#include "net/url_request/url_request_context_getter.h" + +namespace { + +// Posts |callback| on |task_runner|. +void PostCallback(const scoped_refptr<base::TaskRunner>& task_runner, + const net::CompletionCallback& callback, + int error) { + task_runner->PostTask(FROM_HERE, base::Bind(callback, error)); +} + +// Clears the disk_cache::Backend on the IO thread and deletes |backend|. +void DoomHttpCache(scoped_ptr<disk_cache::Backend*> backend, + const scoped_refptr<base::TaskRunner>& client_task_runner, + const net::CompletionCallback& callback, + int error) { + // |*backend| may be null in case of error. + if (*backend) { + (*backend)->DoomAllEntries( + base::Bind(&PostCallback, client_task_runner, callback)); + } else { + client_task_runner->PostTask(FROM_HERE, base::Bind(callback, error)); + } +} + +// Clears various caches synchronously and the disk_cache::Backend +// asynchronously. +void ClearHttpCacheOnIOThread( + const scoped_refptr<net::URLRequestContextGetter>& getter, + const scoped_refptr<base::TaskRunner>& client_task_runner, + const net::CompletionCallback& callback) { + net::HttpCache* http_cache = + getter->GetURLRequestContext()->http_transaction_factory()->GetCache(); + + // Clear QUIC server information from memory and the disk cache. + http_cache->GetSession() + ->quic_stream_factory() + ->ClearCachedStatesInCryptoConfig(); + + // Clear SDCH dictionary state. + net::SdchManager* sdch_manager = + getter->GetURLRequestContext()->sdch_manager(); + // The test is probably overkill, since chrome should always have an + // SdchManager. But in general the URLRequestContext is *not* + // guaranteed to have an SdchManager, so checking is wise. + if (sdch_manager) + sdch_manager->ClearData(); + + scoped_ptr<disk_cache::Backend*> backend(new disk_cache::Backend*(nullptr)); + disk_cache::Backend** backend_ptr = backend.get(); + net::CompletionCallback doom_callback = + base::Bind(&DoomHttpCache, base::Passed(backend.Pass()), + client_task_runner, callback); + + int rv = http_cache->GetBackend(backend_ptr, doom_callback); + + if (rv != net::ERR_IO_PENDING) { + // GetBackend doesn't call the callback if it completes synchronously, so + // call it directly here. + doom_callback.Run(rv); + } +} + +} // namespace + +namespace net { + +void ClearHttpCache(const scoped_refptr<net::URLRequestContextGetter>& getter, + const scoped_refptr<base::TaskRunner>& network_task_runner, + const net::CompletionCallback& callback) { + network_task_runner->PostTask( + FROM_HERE, base::Bind(&ClearHttpCacheOnIOThread, getter, + base::ThreadTaskRunnerHandle::Get(), callback)); +} + +} // namespace net diff --git a/ios/net/http_cache_helper.h b/ios/net/http_cache_helper.h new file mode 100644 index 0000000..6dc59e7 --- /dev/null +++ b/ios/net/http_cache_helper.h @@ -0,0 +1,26 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef IOS_NET_HTTP_CACHE_HELPER_H_ +#define IOS_NET_HTTP_CACHE_HELPER_H_ + +#include "base/callback_forward.h" +#include "base/memory/ref_counted.h" +#include "net/base/completion_callback.h" + +namespace base { +class TaskRunner; +} + +namespace net { +class URLRequestContextGetter; + +// Clears the HTTP cache and calls |closure| back. +void ClearHttpCache(const scoped_refptr<net::URLRequestContextGetter>& getter, + const scoped_refptr<base::TaskRunner>& network_task_runner, + const net::CompletionCallback& callback); + +} // namespace net + +#endif // IOS_NET_HTTP_CACHE_HELPER_H_ diff --git a/ios/net/ios_net.gyp b/ios/net/ios_net.gyp index e5193c4..79a1ffe 100644 --- a/ios/net/ios_net.gyp +++ b/ios/net/ios_net.gyp @@ -45,6 +45,8 @@ 'crn_http_url_response.mm', 'empty_nsurlcache.h', 'empty_nsurlcache.mm', + 'http_cache_helper.cc', + 'http_cache_helper.h', 'http_protocol_logging.h', 'http_protocol_logging.mm', 'http_response_headers_util.h', |