1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MOJO_SERVICES_NETWORK_NETWORK_SERVICE_DELEGATE_H_
#define MOJO_SERVICES_NETWORK_NETWORK_SERVICE_DELEGATE_H_
#include "base/observer_list.h"
#include "base/threading/thread.h"
#include "components/filesystem/public/interfaces/file_system.mojom.h"
#include "mojo/services/network/network_context.h"
#include "mojo/services/network/public/interfaces/cookie_store.mojom.h"
#include "mojo/services/network/public/interfaces/network_service.mojom.h"
#include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h"
#include "mojo/services/network/public/interfaces/web_socket_factory.mojom.h"
#include "mojo/services/tracing/public/cpp/tracing_impl.h"
#include "mojo/shell/public/cpp/interface_factory.h"
#include "mojo/shell/public/cpp/shell.h"
#include "mojo/shell/public/cpp/shell_client.h"
namespace sql {
class ScopedMojoFilesystemVFS;
}
namespace mojo {
class NetworkServiceDelegateObserver;
class NetworkServiceDelegate : public ShellClient,
public InterfaceFactory<NetworkService>,
public InterfaceFactory<CookieStore>,
public InterfaceFactory<WebSocketFactory>,
public InterfaceFactory<URLLoaderFactory>,
public filesystem::FileSystemClient {
public:
NetworkServiceDelegate();
~NetworkServiceDelegate() override;
void AddObserver(NetworkServiceDelegateObserver* observer);
void RemoveObserver(NetworkServiceDelegateObserver* observer);
private:
// Notifies all of our observers of a Shuts down our IO thread. Safe to call
// multiple times.
void EnsureIOThreadShutdown();
// mojo::ShellClient implementation.
void Initialize(Shell* shell, const std::string& url, uint32_t id) override;
bool AcceptConnection(Connection* connection) override;
bool ShellConnectionLost() override;
void Quit() override;
// InterfaceFactory<NetworkService> implementation.
void Create(Connection* connection,
InterfaceRequest<NetworkService> request) override;
// InterfaceFactory<CookieStore> implementation.
void Create(Connection* connection,
InterfaceRequest<CookieStore> request) override;
// InterfaceFactory<WebSocketFactory> implementation.
void Create(Connection* connection,
InterfaceRequest<WebSocketFactory> request) override;
// InterfaceFactory<URLLoaderFactory> implementation.
void Create(Connection* connection,
InterfaceRequest<URLLoaderFactory> request) override;
// Overridden from FileSystemClient:
void OnFileSystemShutdown() override;
private:
Shell* shell_;
mojo::TracingImpl tracing_;
// Observers that want notifications that our worker thread is going away.
base::ObserverList<NetworkServiceDelegateObserver> observers_;
Binding<filesystem::FileSystemClient> binding_;
// A worker thread that blocks for file IO.
scoped_ptr<base::Thread> io_worker_thread_;
// Our connection to the filesystem service, which stores our cookies and
// other data.
filesystem::FileSystemPtr files_;
scoped_ptr<NetworkContext> context_;
};
} // namespace mojo
#endif // MOJO_SERVICES_NETWORK_NETWORK_SERVICE_DELEGATE_H_
|