cc: Make picture pile base thread safe.
[chromium-blink-merge.git] / mojo / shell / external_application_registrar_connection.h
blobdbe02e689aaddef483e1ebacd2c4df9a9b8ba43f
1 // Copyright 2014 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_SHELL_EXTERNAL_APPLICATION_REGISTRAR_CONNECTION_H_
6 #define MOJO_SHELL_EXTERNAL_APPLICATION_REGISTRAR_CONNECTION_H_
8 #include "base/callback_forward.h"
9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "mojo/common/common_type_converters.h"
12 #include "mojo/edk/embedder/channel_init.h"
13 #include "mojo/public/cpp/bindings/error_handler.h"
14 #include "mojo/public/interfaces/application/application.mojom.h"
15 #include "mojo/public/interfaces/application/shell.mojom.h"
16 #include "mojo/shell/external_application_registrar.mojom.h"
17 #include "net/socket/socket_descriptor.h"
18 #include "net/socket/unix_domain_client_socket_posix.h"
19 #include "url/gurl.h"
21 namespace mojo {
22 namespace shell {
24 // Externally-running applications can use this class to discover and register
25 // with a running mojo_shell instance.
26 // MUST be run on an IO thread
27 class ExternalApplicationRegistrarConnection : public ErrorHandler {
28 public:
29 // Configures client_socket_ to point at socket_path.
30 explicit ExternalApplicationRegistrarConnection(
31 const base::FilePath& socket_path);
32 ~ExternalApplicationRegistrarConnection() override;
34 // Implementation of ErrorHandler
35 void OnConnectionError() override;
37 // Connects client_socket_ and binds it to registrar_.
38 // Status code is passed to callback upon success or failure.
39 // May return either synchronously or asynchronously, depending on the
40 // status of the underlying socket.
41 void Connect(const net::CompletionCallback& callback);
43 // Registers this app with the shell at the provided URL.
44 // shell is not ready for use until register_complete_callback fires.
45 // TODO(cmasone): Once the pipe for shell can be placed in a FIFO relationship
46 // with the one underlying registrar_, the callback becomes unneeded.
47 void Register(const GURL& app_url,
48 ShellPtr* shell,
49 base::Closure register_complete_callback);
51 private:
52 // Handles the result of Connect(). If it was successful, promotes the socket
53 // to a MessagePipe and binds it to registrar_.
54 // Hands rv to callback regardless.
55 void OnConnect(net::CompletionCallback callback, int rv);
57 scoped_ptr<net::UnixDomainClientSocket> client_socket_;
58 mojo::embedder::ChannelInit channel_init_;
59 ExternalApplicationRegistrarPtr registrar_;
62 } // namespace shell
63 } // namespace mojo
65 #endif // MOJO_SHELL_EXTERNAL_APPLICATION_REGISTRAR_CONNECTION_H_