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