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
3 // found in the LICENSE file.
5 #ifndef MOJO_SERVICES_NETWORK_NETWORK_SERVICE_DELEGATE_H_
6 #define MOJO_SERVICES_NETWORK_NETWORK_SERVICE_DELEGATE_H_
8 #include "base/observer_list.h"
9 #include "base/threading/thread.h"
10 #include "components/filesystem/public/interfaces/file_system.mojom.h"
11 #include "mojo/application/public/cpp/application_delegate.h"
12 #include "mojo/application/public/cpp/application_impl.h"
13 #include "mojo/application/public/cpp/interface_factory.h"
14 #include "mojo/services/network/network_context.h"
15 #include "mojo/services/network/public/interfaces/cookie_store.mojom.h"
16 #include "mojo/services/network/public/interfaces/network_service.mojom.h"
17 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h"
18 #include "mojo/services/network/public/interfaces/web_socket_factory.mojom.h"
21 class ScopedMojoFilesystemVFS
;
25 class NetworkServiceDelegateObserver
;
27 class NetworkServiceDelegate
: public ApplicationDelegate
,
28 public InterfaceFactory
<NetworkService
>,
29 public InterfaceFactory
<CookieStore
>,
30 public InterfaceFactory
<WebSocketFactory
>,
31 public InterfaceFactory
<URLLoaderFactory
>,
32 public filesystem::FileSystemClient
{
34 NetworkServiceDelegate();
35 ~NetworkServiceDelegate() override
;
37 void AddObserver(NetworkServiceDelegateObserver
* observer
);
38 void RemoveObserver(NetworkServiceDelegateObserver
* observer
);
41 // Notifies all of our observers of a Shuts down our IO thread. Safe to call
43 void EnsureIOThreadShutdown();
45 // ApplicationDelegate implementation.
46 void Initialize(ApplicationImpl
* app
) override
;
47 bool ConfigureIncomingConnection(ApplicationConnection
* connection
) override
;
48 bool OnShellConnectionError() override
;
51 // InterfaceFactory<NetworkService> implementation.
52 void Create(ApplicationConnection
* connection
,
53 InterfaceRequest
<NetworkService
> request
) override
;
55 // InterfaceFactory<CookieStore> implementation.
56 void Create(ApplicationConnection
* connection
,
57 InterfaceRequest
<CookieStore
> request
) override
;
59 // InterfaceFactory<WebSocketFactory> implementation.
60 void Create(ApplicationConnection
* connection
,
61 InterfaceRequest
<WebSocketFactory
> request
) override
;
63 // InterfaceFactory<URLLoaderFactory> implementation.
64 void Create(ApplicationConnection
* connection
,
65 InterfaceRequest
<URLLoaderFactory
> request
) override
;
67 // Overridden from FileSystemClient:
68 void OnFileSystemShutdown() override
;
71 ApplicationImpl
* app_
;
73 // Observers that want notifications that our worker thread is going away.
74 base::ObserverList
<NetworkServiceDelegateObserver
> observers_
;
76 Binding
<filesystem::FileSystemClient
> binding_
;
78 // A worker thread that blocks for file IO.
79 scoped_ptr
<base::Thread
> io_worker_thread_
;
81 // Our connection to the filesystem service, which stores our cookies and
83 filesystem::FileSystemPtr files_
;
85 scoped_ptr
<NetworkContext
> context_
;
90 #endif // MOJO_SERVICES_NETWORK_NETWORK_SERVICE_DELEGATE_H_