Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3035)

Unified Diff: mojo/services/network/network_service_delegate.cc

Issue 1344853002: Teach the network service to clear its disk cache if requested. (Closed) Base URL: https://github.com/domokit/monet.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/services/network/network_service_delegate.cc
diff --git a/mojo/services/network/network_service_delegate.cc b/mojo/services/network/network_service_delegate.cc
index 76e0b6924b2eba979a933e699ebf103a8c042647..8bb54d1379f6df7df96275263b5ccd59a9bc85eb 100644
--- a/mojo/services/network/network_service_delegate.cc
+++ b/mojo/services/network/network_service_delegate.cc
@@ -6,11 +6,21 @@
#include "base/at_exit.h"
#include "base/base_paths.h"
+#include "base/command_line.h"
+#include "base/location.h"
+#include "base/bind.h"
+#include "base/threading/thread.h"
#include "base/files/file_path.h"
#include "base/message_loop/message_loop.h"
+#include "base/memory/scoped_ptr.h"
#include "base/path_service.h"
#include "third_party/mojo/src/mojo/public/cpp/application/application_connection.h"
+namespace {
+void DoNothing() {
+}
+} // namespace
+
NetworkServiceDelegate::NetworkServiceDelegate() {}
NetworkServiceDelegate::~NetworkServiceDelegate() {}
@@ -20,6 +30,22 @@ void NetworkServiceDelegate::Initialize(mojo::ApplicationImpl* app) {
base::FilePath base_path;
CHECK(PathService::Get(base::DIR_TEMP, &base_path));
base_path = base_path.Append(FILE_PATH_LITERAL("network_service"));
+ base::CommandLine command_line(app->args());
+ if (command_line.HasSwitch("clear")) {
+ scoped_ptr<base::Thread> cache_delete_thread(
+ new base::Thread("network cache delete thread"));
+ cache_delete_thread->Start();
+ mojo::NetworkContext::ClearCache(base_path,
+ cache_delete_thread->task_runner());
+ // base::Thread required that Stop() is called on the same thread as
+ // Start(). PostTaskAndReply() with a dummy task ensures that we call Stop()
+ // on the right thread and only after cache deletion was completed (as the
+ // thread task runner is sequential).
+ cache_delete_thread->task_runner()->PostTaskAndReply(
+ FROM_HERE, base::Bind(&DoNothing),
+ base::Bind(&base::Thread::Stop,
+ base::Owned(cache_delete_thread.release())));
qsr 2015/09/16 13:27:05 This seems hacky. Where is the guarantee that Clea
ppi 2015/09/16 14:20:59 Done.
+ }
context_.reset(new mojo::NetworkContext(base_path));
}
« mojo/services/network/network_context.h ('K') | « mojo/services/network/network_context.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698