Chromium Code Reviews| 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_SHELL_CONTENT_HANDLER_CONNECTION_H_ | 5 #ifndef MOJO_SHELL_CONTENT_HANDLER_CONNECTION_H_ |
| 6 #define MOJO_SHELL_CONTENT_HANDLER_CONNECTION_H_ | 6 #define MOJO_SHELL_CONTENT_HANDLER_CONNECTION_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | |
| 10 #include "mojo/application/public/interfaces/content_handler.mojom.h" | 11 #include "mojo/application/public/interfaces/content_handler.mojom.h" |
| 12 #include "mojo/application/public/interfaces/shell.mojom.h" | |
| 11 #include "mojo/shell/capability_filter.h" | 13 #include "mojo/shell/capability_filter.h" |
| 12 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 13 | 15 |
| 14 namespace mojo { | 16 namespace mojo { |
| 15 namespace shell { | 17 namespace shell { |
| 16 | 18 |
| 17 class ApplicationInstance; | 19 class ApplicationInstance; |
| 18 class ApplicationManager; | 20 class ApplicationManager; |
| 19 | 21 |
| 20 // A ContentHandlerConnection is responsible for creating and maintaining a | 22 // A ContentHandlerConnection is responsible for creating and maintaining a |
| 21 // connection to an app which provides the ContentHandler service. | 23 // connection to an app which provides the ContentHandler service. |
| 22 // A ContentHandlerConnection can only be destroyed via CloseConnection. | 24 // A ContentHandlerConnection can only be destroyed via CloseConnection. |
| 23 // A ContentHandlerConnection manages its own lifetime and cannot be used with | 25 // A ContentHandlerConnection manages its own lifetime and cannot be used with |
| 24 // a scoped_ptr to avoid reentrant calls into ApplicationManager late in | 26 // a scoped_ptr to avoid reentrant calls into ApplicationManager late in |
| 25 // destruction. | 27 // destruction. |
| 26 class ContentHandlerConnection { | 28 class ContentHandlerConnection { |
| 27 public: | 29 public: |
| 30 // |id| is a unique identifier for this content handler. | |
| 28 ContentHandlerConnection(ApplicationInstance* originator, | 31 ContentHandlerConnection(ApplicationInstance* originator, |
| 29 ApplicationManager* manager, | 32 ApplicationManager* manager, |
| 30 const GURL& content_handler_url, | 33 const GURL& content_handler_url, |
| 31 const GURL& requestor_url, | 34 const GURL& requestor_url, |
| 32 const std::string& qualifier, | 35 const std::string& qualifier, |
| 33 const CapabilityFilter& filter); | 36 const CapabilityFilter& filter, |
| 37 uint32_t id); | |
| 34 | 38 |
| 35 // Closes the connection and destroys |this| object. | 39 // Closes the connection and destroys |this| object. |
| 36 void CloseConnection(); | 40 void CloseConnection(); |
| 37 | 41 |
| 38 ContentHandler* content_handler() { return content_handler_.get(); } | 42 ContentHandler* content_handler() { return content_handler_.get(); } |
| 39 const GURL& content_handler_url() { return content_handler_url_; } | 43 const GURL& content_handler_url() { return content_handler_url_; } |
| 40 const std::string& content_handler_qualifier() { | 44 const std::string& content_handler_qualifier() { |
| 41 return content_handler_qualifier_; | 45 return content_handler_qualifier_; |
| 42 } | 46 } |
| 47 uint32_t id() const { return id_; } | |
| 48 | |
| 49 // Schedules a callback to be run once the id of any nested content handlers | |
| 50 // are obtained. | |
| 51 void ScheduleTargetIdCallback( | |
|
Ben Goodger (Google)
2015/08/31 17:41:07
rename?
sky
2015/08/31 19:46:07
This was all nuked.
| |
| 52 const Shell::ConnectToApplicationCallback& connect_callback); | |
| 43 | 53 |
| 44 private: | 54 private: |
| 45 ~ContentHandlerConnection(); | 55 ~ContentHandlerConnection(); |
| 46 | 56 |
| 57 // Callback from ConnectToApplication() on the target application. | |
| 58 void OnGotNestedContentHandlerID(uint32_t content_handler_id); | |
| 59 | |
| 60 // Returns the id to supply to the callback from | |
| 61 // Shell::ConnectToApplication(). The returned id is either the id of this | |
| 62 // content handler, or if connecting to the application involved another | |
| 63 // content handler, then the deepest id from that connection. | |
| 64 // | |
| 65 // This is only valid once OnGotNestedContentHandlerID() is received. | |
| 66 uint32_t content_handler_id_for_callback() const; | |
| 67 | |
| 47 ApplicationManager* manager_; | 68 ApplicationManager* manager_; |
| 48 GURL content_handler_url_; | 69 GURL content_handler_url_; |
| 49 std::string content_handler_qualifier_; | 70 std::string content_handler_qualifier_; |
| 50 ContentHandlerPtr content_handler_; | 71 ContentHandlerPtr content_handler_; |
| 51 bool connection_closed_; | 72 bool connection_closed_; |
| 73 // The id for this content handler. | |
| 74 const uint32_t id_; | |
| 75 | |
| 76 // Set to true once OnGotNestedContentHandlerID() has been invoked. At this | |
| 77 // point |nested_content_handler_id_| is valid. | |
| 78 bool got_nested_content_handler_id_; | |
| 79 uint32_t nested_content_handler_id_; | |
| 80 | |
| 81 // Callbacks scheduled before OnGotNestedContentHandlerID() are added here. | |
| 82 // Once OnGotNestedContentHandlerID() is called these are processed. | |
| 83 std::vector<Shell::ConnectToApplicationCallback> | |
| 84 pending_content_handler_id_callbacks_; | |
| 85 | |
| 86 base::WeakPtrFactory<ContentHandlerConnection> weak_ptr_factory_; | |
| 52 | 87 |
| 53 DISALLOW_COPY_AND_ASSIGN(ContentHandlerConnection); | 88 DISALLOW_COPY_AND_ASSIGN(ContentHandlerConnection); |
| 54 }; | 89 }; |
| 55 | 90 |
| 56 } // namespace shell | 91 } // namespace shell |
| 57 } // namespace mojo | 92 } // namespace mojo |
| 58 | 93 |
| 59 #endif // MOJO_SHELL_CONTENT_HANDLER_CONNECTION_H_ | 94 #endif // MOJO_SHELL_CONTENT_HANDLER_CONNECTION_H_ |
| OLD | NEW |