OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef MOJO_SHELL_CONTENT_HANDLER_CONNECTION_H_ | |
6 #define MOJO_SHELL_CONTENT_HANDLER_CONNECTION_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <string> | |
11 | |
12 #include "base/callback.h" | |
13 #include "base/macros.h" | |
14 #include "mojo/shell/identity.h" | |
15 #include "mojo/shell/public/interfaces/content_handler.mojom.h" | |
16 #include "url/gurl.h" | |
17 | |
18 namespace mojo { | |
19 namespace shell { | |
20 class ApplicationManager; | |
21 | |
22 // A ContentHandlerConnection is responsible for creating and maintaining a | |
23 // connection to an app which provides the ContentHandler service. | |
24 // A ContentHandlerConnection can only be destroyed via CloseConnection. | |
25 // A ContentHandlerConnection manages its own lifetime and cannot be used with | |
26 // a scoped_ptr to avoid reentrant calls into ApplicationManager late in | |
27 // destruction. | |
28 class ContentHandlerConnection { | |
29 public: | |
30 using ClosedCallback = base::Callback<void(ContentHandlerConnection*)>; | |
31 // |id| is a unique identifier for this content handler. | |
32 ContentHandlerConnection(ApplicationManager* manager, | |
33 const Identity& source, | |
34 const Identity& content_handler, | |
35 uint32_t id, | |
36 const ClosedCallback& connection_closed_callback); | |
37 | |
38 void StartApplication(InterfaceRequest<mojom::ShellClient> request, | |
39 URLResponsePtr response); | |
40 | |
41 // Closes the connection and destroys |this| object. | |
42 void CloseConnection(); | |
43 | |
44 const Identity& identity() const { return identity_; } | |
45 uint32_t id() const { return id_; } | |
46 | |
47 private: | |
48 ~ContentHandlerConnection(); | |
49 | |
50 void ApplicationDestructed(); | |
51 | |
52 ClosedCallback connection_closed_callback_; | |
53 Identity identity_; | |
54 | |
55 mojom::ContentHandlerPtr content_handler_; | |
56 bool connection_closed_; | |
57 // The id for this content handler. | |
58 const uint32_t id_; | |
59 int ref_count_; | |
60 | |
61 DISALLOW_COPY_AND_ASSIGN(ContentHandlerConnection); | |
62 }; | |
63 | |
64 } // namespace shell | |
65 } // namespace mojo | |
66 | |
67 #endif // MOJO_SHELL_CONTENT_HANDLER_CONNECTION_H_ | |
OLD | NEW |