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 COMPONENTS_FILESYSTEM_FILE_SYSTEM_APP_H_
6 #define COMPONENTS_FILESYSTEM_FILE_SYSTEM_APP_H_
8 #include "base/macros.h"
9 #include "components/filesystem/directory_impl.h"
10 #include "components/filesystem/file_system_impl.h"
11 #include "components/filesystem/public/interfaces/file_system.mojom.h"
12 #include "mojo/application/public/cpp/application_delegate.h"
13 #include "mojo/application/public/cpp/interface_factory.h"
16 class ApplicationImpl
;
19 namespace filesystem
{
21 class FileSystemApp
: public mojo::ApplicationDelegate
,
22 public mojo::InterfaceFactory
<FileSystem
> {
25 ~FileSystemApp() override
;
27 // Called by individual FileSystem objects to register lifetime events.
28 void RegisterDirectoryToClient(DirectoryImpl
* directory
,
29 FileSystemClientPtr client
);
32 // We set the DirectoryImpl's error handler to this function. We do this so
33 // that we can QuitNow() once the last DirectoryImpl has closed itself.
34 void OnDirectoryConnectionError(DirectoryImpl
* directory
);
36 // |ApplicationDelegate| override:
37 void Initialize(mojo::ApplicationImpl
* app
) override
;
38 bool ConfigureIncomingConnection(
39 mojo::ApplicationConnection
* connection
) override
;
40 bool OnShellConnectionError() override
;
42 // |InterfaceFactory<Files>| implementation:
43 void Create(mojo::ApplicationConnection
* connection
,
44 mojo::InterfaceRequest
<FileSystem
> request
) override
;
46 // Use a vector to work around map not letting us use FileSystemClientPtr as
47 // a value in a std::map. The move constructors are to allow us to deal with
48 // FileSystemClientPtr inside a vector.
50 Client(DirectoryImpl
* directory
, FileSystemClientPtr fs_client
);
54 Client
& operator=(Client
&& rhs
);
56 DirectoryImpl
* directory_
;
57 FileSystemClientPtr fs_client_
;
59 std::vector
<Client
> client_mapping_
;
61 mojo::ApplicationImpl
* app_
;
63 // Set to true when our shell connection is closed. On connection error, we
64 // then broadcast a notification to all FileSystemClients that they should
65 // shut down. Once the final one does, then we QuitNow().
68 DISALLOW_COPY_AND_ASSIGN(FileSystemApp
);
71 } // namespace filesystem
73 #endif // COMPONENTS_FILESYSTEM_FILE_SYSTEM_APP_H_