| 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/bind.h" |
| 11 #include "base/threading/thread.h" |
| 9 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 10 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 12 #include "third_party/mojo/src/mojo/public/cpp/application/application_connectio
n.h" | 16 #include "third_party/mojo/src/mojo/public/cpp/application/application_connectio
n.h" |
| 13 | 17 |
| 14 NetworkServiceDelegate::NetworkServiceDelegate() {} | 18 NetworkServiceDelegate::NetworkServiceDelegate() {} |
| 15 | 19 |
| 16 NetworkServiceDelegate::~NetworkServiceDelegate() {} | 20 NetworkServiceDelegate::~NetworkServiceDelegate() {} |
| 17 | 21 |
| 18 void NetworkServiceDelegate::Initialize(mojo::ApplicationImpl* app) { | 22 void NetworkServiceDelegate::Initialize(mojo::ApplicationImpl* app) { |
| 19 tracing_.Initialize(app); | 23 tracing_.Initialize(app); |
| 20 base::FilePath base_path; | 24 base::FilePath base_path; |
| 21 CHECK(PathService::Get(base::DIR_TEMP, &base_path)); | 25 CHECK(PathService::Get(base::DIR_TEMP, &base_path)); |
| 22 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); | 26 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); |
| 27 base::CommandLine command_line(app->args()); |
| 28 if (command_line.HasSwitch("clear")) { |
| 29 scoped_ptr<base::Thread> cache_delete_thread( |
| 30 new base::Thread("network cache delete thread")); |
| 31 cache_delete_thread->Start(); |
| 32 mojo::NetworkContext::ClearCache( |
| 33 base_path, cache_delete_thread->task_runner(), |
| 34 base::Bind(&base::Thread::Stop, |
| 35 base::Owned(cache_delete_thread.release()))); |
| 36 } |
| 23 context_.reset(new mojo::NetworkContext(base_path)); | 37 context_.reset(new mojo::NetworkContext(base_path)); |
| 24 } | 38 } |
| 25 | 39 |
| 26 bool NetworkServiceDelegate::ConfigureIncomingConnection( | 40 bool NetworkServiceDelegate::ConfigureIncomingConnection( |
| 27 mojo::ApplicationConnection* connection) { | 41 mojo::ApplicationConnection* connection) { |
| 28 DCHECK(context_); | 42 DCHECK(context_); |
| 29 connection->AddService(this); | 43 connection->AddService(this); |
| 30 return true; | 44 return true; |
| 31 } | 45 } |
| 32 | 46 |
| 33 void NetworkServiceDelegate::Quit() { | 47 void NetworkServiceDelegate::Quit() { |
| 34 // Destroy the NetworkContext now as it requires MessageLoop::current() upon | 48 // 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 | 49 // destruction and it is the last moment we know for sure that it is |
| 36 // running. | 50 // running. |
| 37 context_.reset(); | 51 context_.reset(); |
| 38 } | 52 } |
| 39 | 53 |
| 40 void NetworkServiceDelegate::Create( | 54 void NetworkServiceDelegate::Create( |
| 41 mojo::ApplicationConnection* connection, | 55 mojo::ApplicationConnection* connection, |
| 42 mojo::InterfaceRequest<mojo::NetworkService> request) { | 56 mojo::InterfaceRequest<mojo::NetworkService> request) { |
| 43 new mojo::NetworkServiceImpl(request.Pass(), connection, context_.get()); | 57 new mojo::NetworkServiceImpl(request.Pass(), connection, context_.get()); |
| 44 } | 58 } |
| OLD | NEW |