| Index: mojo/services/network/network_context.cc
|
| diff --git a/mojo/services/network/network_context.cc b/mojo/services/network/network_context.cc
|
| index cd5a8ab828027c2d9b956185e5eed30c494a5f2e..c674fa28f236e4ebc17a58407f6615cbcfa2bc66 100644
|
| --- a/mojo/services/network/network_context.cc
|
| +++ b/mojo/services/network/network_context.cc
|
| @@ -10,6 +10,7 @@
|
| #include "base/base_paths.h"
|
| #include "base/bind.h"
|
| #include "base/command_line.h"
|
| +#include "base/files/file_util.h"
|
| #include "base/path_service.h"
|
| #include "mojo/common/user_agent.h"
|
| #include "mojo/services/network/url_loader_impl.h"
|
| @@ -24,6 +25,10 @@ namespace mojo {
|
| namespace {
|
| // Logs network information to the specified file.
|
| const char kLogNetLog[] = "log-net-log";
|
| +
|
| +base::FilePath GetCacheDirectory(const base::FilePath& base_path) {
|
| + return base_path.Append(FILE_PATH_LITERAL("Cache"));
|
| +}
|
| }
|
|
|
| class NetworkContext::MojoNetLog : public net::NetLog {
|
| @@ -64,6 +69,32 @@ class NetworkContext::MojoNetLog : public net::NetLog {
|
| DISALLOW_COPY_AND_ASSIGN(MojoNetLog);
|
| };
|
|
|
| +// static
|
| +void NetworkContext::ClearCache(const base::FilePath& base_path,
|
| + scoped_refptr<base::TaskRunner> task_runner,
|
| + const base::Closure& clear_finished_callback) {
|
| + base::FilePath trash_dir = base_path.Append(FILE_PATH_LITERAL("Trash"));
|
| + base::CreateDirectory(trash_dir);
|
| + base::FilePath dest_dir;
|
| + base::CreateTemporaryDirInDir(trash_dir, "", &dest_dir);
|
| +
|
| + // Move the current cache directory, if present, into trash.
|
| + base::FilePath cache_dir = GetCacheDirectory(base_path);
|
| + if (PathExists(cache_dir)) {
|
| + base::File::Error error;
|
| + if (!base::ReplaceFile(cache_dir, dest_dir, &error)) {
|
| + LOG(ERROR) << "Failed to clear cache content: " << error;
|
| + }
|
| + }
|
| + // Recreate the cache directory.
|
| + base::CreateDirectory(cache_dir);
|
| +
|
| + task_runner->PostTaskAndReply(
|
| + FROM_HERE,
|
| + base::Bind(base::IgnoreResult(&base::DeleteFile), trash_dir, true),
|
| + clear_finished_callback);
|
| +}
|
| +
|
| NetworkContext::NetworkContext(
|
| scoped_ptr<net::URLRequestContext> url_request_context)
|
| : net_log_(new MojoNetLog),
|
| @@ -120,7 +151,7 @@ scoped_ptr<net::URLRequestContext> NetworkContext::MakeURLRequestContext(
|
| // On Android, we store the cache on disk becase we can run only a single
|
| // instance of the shell at a time.
|
| cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK;
|
| - cache_params.path = base_path.Append(FILE_PATH_LITERAL("Cache"));
|
| + cache_params.path = GetCacheDirectory(base_path);
|
| #else
|
| // On desktop, we store the cache in memory so we can run many shells
|
| // in parallel when running tests, otherwise the network services in each
|
|
|