Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/services/network/network_service_delegate.h" | 5 #include "mojo/services/network/network_service_delegate.h" |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/base_paths.h" | 8 #include "base/base_paths.h" |
| 9 #include "base/command_line.h" | |
| 10 #include "base/location.h" | |
| 11 #include "base/bind.h" | |
| 12 #include "base/threading/thread.h" | |
| 9 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 10 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 12 #include "third_party/mojo/src/mojo/public/cpp/application/application_connectio n.h" | 17 #include "third_party/mojo/src/mojo/public/cpp/application/application_connectio n.h" |
| 13 | 18 |
| 19 namespace { | |
| 20 void DoNothing() { | |
| 21 } | |
| 22 } // namespace | |
| 23 | |
| 14 NetworkServiceDelegate::NetworkServiceDelegate() {} | 24 NetworkServiceDelegate::NetworkServiceDelegate() {} |
| 15 | 25 |
| 16 NetworkServiceDelegate::~NetworkServiceDelegate() {} | 26 NetworkServiceDelegate::~NetworkServiceDelegate() {} |
| 17 | 27 |
| 18 void NetworkServiceDelegate::Initialize(mojo::ApplicationImpl* app) { | 28 void NetworkServiceDelegate::Initialize(mojo::ApplicationImpl* app) { |
| 19 tracing_.Initialize(app); | 29 tracing_.Initialize(app); |
| 20 base::FilePath base_path; | 30 base::FilePath base_path; |
| 21 CHECK(PathService::Get(base::DIR_TEMP, &base_path)); | 31 CHECK(PathService::Get(base::DIR_TEMP, &base_path)); |
| 22 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); | 32 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); |
| 33 base::CommandLine command_line(app->args()); | |
| 34 if (command_line.HasSwitch("clear")) { | |
| 35 scoped_ptr<base::Thread> cache_delete_thread( | |
| 36 new base::Thread("network cache delete thread")); | |
| 37 cache_delete_thread->Start(); | |
| 38 mojo::NetworkContext::ClearCache(base_path, | |
| 39 cache_delete_thread->task_runner()); | |
| 40 // base::Thread required that Stop() is called on the same thread as | |
| 41 // Start(). PostTaskAndReply() with a dummy task ensures that we call Stop() | |
| 42 // on the right thread and only after cache deletion was completed (as the | |
| 43 // thread task runner is sequential). | |
| 44 cache_delete_thread->task_runner()->PostTaskAndReply( | |
| 45 FROM_HERE, base::Bind(&DoNothing), | |
| 46 base::Bind(&base::Thread::Stop, | |
| 47 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.
| |
| 48 } | |
| 23 context_.reset(new mojo::NetworkContext(base_path)); | 49 context_.reset(new mojo::NetworkContext(base_path)); |
| 24 } | 50 } |
| 25 | 51 |
| 26 bool NetworkServiceDelegate::ConfigureIncomingConnection( | 52 bool NetworkServiceDelegate::ConfigureIncomingConnection( |
| 27 mojo::ApplicationConnection* connection) { | 53 mojo::ApplicationConnection* connection) { |
| 28 DCHECK(context_); | 54 DCHECK(context_); |
| 29 connection->AddService(this); | 55 connection->AddService(this); |
| 30 return true; | 56 return true; |
| 31 } | 57 } |
| 32 | 58 |
| 33 void NetworkServiceDelegate::Quit() { | 59 void NetworkServiceDelegate::Quit() { |
| 34 // Destroy the NetworkContext now as it requires MessageLoop::current() upon | 60 // Destroy the NetworkContext now as it requires MessageLoop::current() upon |
| 35 // destruction and it is the last moment we know for sure that it is | 61 // destruction and it is the last moment we know for sure that it is |
| 36 // running. | 62 // running. |
| 37 context_.reset(); | 63 context_.reset(); |
| 38 } | 64 } |
| 39 | 65 |
| 40 void NetworkServiceDelegate::Create( | 66 void NetworkServiceDelegate::Create( |
| 41 mojo::ApplicationConnection* connection, | 67 mojo::ApplicationConnection* connection, |
| 42 mojo::InterfaceRequest<mojo::NetworkService> request) { | 68 mojo::InterfaceRequest<mojo::NetworkService> request) { |
| 43 new mojo::NetworkServiceImpl(request.Pass(), connection, context_.get()); | 69 new mojo::NetworkServiceImpl(request.Pass(), connection, context_.get()); |
| 44 } | 70 } |
| OLD | NEW |