Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: mojo/application_manager/application_manager.h

Issue 696563002: Cache ShellImpl by resolved URL, not initial URL (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebase Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | mojo/application_manager/application_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ 5 #ifndef MOJO_APPLICATION_MANAGER_APPLICATION_MANAGER_H_
6 #define MOJO_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ 6 #define MOJO_APPLICATION_MANAGER_APPLICATION_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "mojo/application_manager/application_loader.h" 15 #include "mojo/application_manager/application_loader.h"
16 #include "mojo/application_manager/application_manager_export.h" 16 #include "mojo/application_manager/application_manager_export.h"
17 #include "mojo/public/interfaces/application/service_provider.mojom.h" 17 #include "mojo/public/interfaces/application/service_provider.mojom.h"
18 #include "url/gurl.h" 18 #include "url/gurl.h"
19 19
20 namespace mojo { 20 namespace mojo {
21 21
22 class MOJO_APPLICATION_MANAGER_EXPORT ApplicationManager { 22 class MOJO_APPLICATION_MANAGER_EXPORT ApplicationManager {
23 public: 23 public:
24 class MOJO_APPLICATION_MANAGER_EXPORT Delegate { 24 class MOJO_APPLICATION_MANAGER_EXPORT Delegate {
25 public: 25 public:
26 virtual ~Delegate(); 26 virtual ~Delegate();
27 // Send when the Application holding the handle on the other end of the 27 // Send when the Application holding the handle on the other end of the
28 // Shell pipe goes away. 28 // Shell pipe goes away.
29 virtual void OnApplicationError(const GURL& url) = 0; 29 virtual void OnApplicationError(const GURL& url);
30 virtual GURL ResolveURL(const GURL& url);
30 }; 31 };
31 32
32 // API for testing. 33 // API for testing.
33 class MOJO_APPLICATION_MANAGER_EXPORT TestAPI { 34 class MOJO_APPLICATION_MANAGER_EXPORT TestAPI {
34 public: 35 public:
35 explicit TestAPI(ApplicationManager* manager); 36 explicit TestAPI(ApplicationManager* manager);
36 ~TestAPI(); 37 ~TestAPI();
37 38
38 // Returns true if the shared instance has been created. 39 // Returns true if the shared instance has been created.
39 static bool HasCreatedInstance(); 40 static bool HasCreatedInstance();
40 // Returns true if there is a ShellImpl for this URL. 41 // Returns true if there is a ShellImpl for this URL.
41 bool HasFactoryForURL(const GURL& url) const; 42 bool HasFactoryForURL(const GURL& url) const;
42 43
43 private: 44 private:
44 ApplicationManager* manager_; 45 ApplicationManager* manager_;
45 46
46 DISALLOW_COPY_AND_ASSIGN(TestAPI); 47 DISALLOW_COPY_AND_ASSIGN(TestAPI);
47 }; 48 };
48 49
49 // Interface class for debugging only. 50 // Interface class for debugging only.
50 class Interceptor { 51 class Interceptor {
51 public: 52 public:
52 virtual ~Interceptor() {} 53 virtual ~Interceptor() {}
53 // Called when ApplicationManager::Connect is called. 54 // Called when ApplicationManager::Connect is called.
54 virtual ServiceProviderPtr OnConnectToClient( 55 virtual ServiceProviderPtr OnConnectToClient(
55 const GURL& url, 56 const GURL& url,
56 ServiceProviderPtr service_provider) = 0; 57 ServiceProviderPtr service_provider) = 0;
57 }; 58 };
58 59
59 ApplicationManager(); 60 ApplicationManager(Delegate* delegate);
60 ~ApplicationManager(); 61 ~ApplicationManager();
61 62
62 // Returns a shared instance, creating it if necessary.
63 static ApplicationManager* GetInstance();
64
65 void SetDelegate(Delegate* delegate) { delegate_ = delegate; }
66
67 // Loads a service if necessary and establishes a new client connection. 63 // Loads a service if necessary and establishes a new client connection.
68 void ConnectToApplication(const GURL& application_url, 64 void ConnectToApplication(const GURL& application_url,
69 const GURL& requestor_url, 65 const GURL& requestor_url,
70 ServiceProviderPtr service_provider); 66 ServiceProviderPtr service_provider);
71 67
72 template <typename Interface> 68 template <typename Interface>
73 inline void ConnectToService(const GURL& application_url, 69 inline void ConnectToService(const GURL& application_url,
74 InterfacePtr<Interface>* ptr) { 70 InterfacePtr<Interface>* ptr) {
75 ScopedMessagePipeHandle service_handle = 71 ScopedMessagePipeHandle service_handle =
76 ConnectToServiceByName(application_url, Interface::Name_); 72 ConnectToServiceByName(application_url, Interface::Name_);
77 ptr->Bind(service_handle.Pass()); 73 ptr->Bind(service_handle.Pass());
78 } 74 }
79 75
80 ScopedMessagePipeHandle ConnectToServiceByName( 76 ScopedMessagePipeHandle ConnectToServiceByName(
81 const GURL& application_url, 77 const GURL& application_url,
82 const std::string& interface_name); 78 const std::string& interface_name);
83 79
84 void RegisterExternalApplication(const GURL& application_url, 80 void RegisterExternalApplication(const GURL& application_url,
85 ScopedMessagePipeHandle shell); 81 ScopedMessagePipeHandle shell);
86 82
87 void set_delegate(Delegate* delegate) { delegate_ = delegate; }
88
89 // Sets the default Loader to be used if not overridden by SetLoaderForURL() 83 // Sets the default Loader to be used if not overridden by SetLoaderForURL()
90 // or SetLoaderForScheme(). 84 // or SetLoaderForScheme().
91 void set_default_loader(scoped_ptr<ApplicationLoader> loader) { 85 void set_default_loader(scoped_ptr<ApplicationLoader> loader) {
92 default_loader_ = loader.Pass(); 86 default_loader_ = loader.Pass();
93 } 87 }
94 // Sets a Loader to be used for a specific url. 88 // Sets a Loader to be used for a specific url.
95 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url); 89 void SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, const GURL& url);
96 // Sets a Loader to be used for a specific url scheme. 90 // Sets a Loader to be used for a specific url scheme.
97 void SetLoaderForScheme(scoped_ptr<ApplicationLoader> loader, 91 void SetLoaderForScheme(scoped_ptr<ApplicationLoader> loader,
98 const std::string& scheme); 92 const std::string& scheme);
99 // These strings will be passed to the Initialize() method when an 93 // These strings will be passed to the Initialize() method when an
100 // Application is instantiated. 94 // Application is instantiated.
101 void SetArgsForURL(const std::vector<std::string>& args, const GURL& url); 95 void SetArgsForURL(const std::vector<std::string>& args, const GURL& url);
102 96
103 // Allows to interpose a debugger to service connections. 97 // Allows to interpose a debugger to service connections.
104 void SetInterceptor(Interceptor* interceptor); 98 void SetInterceptor(Interceptor* interceptor);
105 99
106 // Destroys all Shell-ends of connections established with Applications. 100 // Destroys all Shell-ends of connections established with Applications.
107 // Applications connected by this ApplicationManager will observe pipe errors 101 // Applications connected by this ApplicationManager will observe pipe errors
108 // and have a chance to shutdown. 102 // and have a chance to shutdown.
109 void TerminateShellConnections(); 103 void TerminateShellConnections();
110 104
111 private: 105 private:
106 enum IncludeDefaultLoader {
107 INCLUDE_DEFAULT_LOADER,
108 DONT_INCLUDE_DEFAULT_LOADER,
109 };
110
112 class ContentHandlerConnection; 111 class ContentHandlerConnection;
113 class LoadCallbacksImpl; 112 class LoadCallbacksImpl;
114 class ShellImpl; 113 class ShellImpl;
115 114
116 typedef std::map<std::string, ApplicationLoader*> SchemeToLoaderMap; 115 typedef std::map<std::string, ApplicationLoader*> SchemeToLoaderMap;
117 typedef std::map<GURL, ApplicationLoader*> URLToLoaderMap; 116 typedef std::map<GURL, ApplicationLoader*> URLToLoaderMap;
118 typedef std::map<GURL, ShellImpl*> URLToShellImplMap; 117 typedef std::map<GURL, ShellImpl*> URLToShellImplMap;
119 typedef std::map<GURL, ContentHandlerConnection*> URLToContentHandlerMap; 118 typedef std::map<GURL, ContentHandlerConnection*> URLToContentHandlerMap;
120 typedef std::map<GURL, std::vector<std::string> > URLToArgsMap; 119 typedef std::map<GURL, std::vector<std::string> > URLToArgsMap;
121 120
121 void ConnectToApplicationImpl(const GURL& url,
122 const GURL& original_url,
123 const GURL& requestor_url,
124 ServiceProviderPtr service_provider,
125 ApplicationLoader* loader);
126
122 void ConnectToClient(ShellImpl* shell_impl, 127 void ConnectToClient(ShellImpl* shell_impl,
123 const GURL& url, 128 const GURL& url,
124 const GURL& requestor_url, 129 const GURL& requestor_url,
125 ServiceProviderPtr service_provider); 130 ServiceProviderPtr service_provider);
126 131
127 void RegisterLoadedApplication(const GURL& service_url, 132 void RegisterLoadedApplication(const GURL& requested_url,
133 const GURL& resolved_url,
128 const GURL& requestor_url, 134 const GURL& requestor_url,
129 ServiceProviderPtr service_provider, 135 ServiceProviderPtr service_provider,
130 ScopedMessagePipeHandle* shell_handle); 136 ScopedMessagePipeHandle* shell_handle);
131 137
132 void LoadWithContentHandler(const GURL& content_url, 138 void LoadWithContentHandler(const GURL& requested_url,
139 const GURL& resolved_url,
133 const GURL& requestor_url, 140 const GURL& requestor_url,
134 const GURL& content_handler_url, 141 const GURL& content_handler_url,
135 URLResponsePtr url_response, 142 URLResponsePtr url_response,
136 ServiceProviderPtr service_provider); 143 ServiceProviderPtr service_provider);
137 144
138 // Returns the Loader to use for a url (using default if not overridden.) 145 // Return the appropriate loader for |url|. This can return NULL if there is
139 // The preference is to use a loader that's been specified for an url first, 146 // no default loader configured.
140 // then one that's been specified for a scheme, then the default. 147 ApplicationLoader* GetLoaderForURL(const GURL& url,
141 ApplicationLoader* GetLoaderForURL(const GURL& url); 148 IncludeDefaultLoader fallback);
142 149
143 // Removes a ShellImpl when it encounters an error. 150 // Removes a ShellImpl when it encounters an error.
144 void OnShellImplError(ShellImpl* shell_impl); 151 void OnShellImplError(ShellImpl* shell_impl);
145 // 152 //
146 // Removes a ContentHandler when it encounters an error. 153 // Removes a ContentHandler when it encounters an error.
147 void OnContentHandlerError(ContentHandlerConnection* content_handler); 154 void OnContentHandlerError(ContentHandlerConnection* content_handler);
148 155
149 // Returns the arguments for the given url. 156 // Returns the arguments for the given url.
150 Array<String> GetArgsForURL(const GURL& url); 157 Array<String> GetArgsForURL(const GURL& url);
151 158
(...skipping 10 matching lines...) Expand all
162 std::set<ShellImpl*> content_shell_impls_; 169 std::set<ShellImpl*> content_shell_impls_;
163 170
164 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_; 171 base::WeakPtrFactory<ApplicationManager> weak_ptr_factory_;
165 172
166 DISALLOW_COPY_AND_ASSIGN(ApplicationManager); 173 DISALLOW_COPY_AND_ASSIGN(ApplicationManager);
167 }; 174 };
168 175
169 } // namespace mojo 176 } // namespace mojo
170 177
171 #endif // MOJO_APPLICATION_MANAGER_APPLICATION_MANAGER_H_ 178 #endif // MOJO_APPLICATION_MANAGER_APPLICATION_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/application_manager/application_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698