| OLD | NEW |
| 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 #include <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 const char kTestServiceURL[] = "mojo:test_url"; | 36 const char kTestServiceURL[] = "mojo:test_url"; |
| 37 | 37 |
| 38 // ViewManagerProxy is a proxy to an IViewManager. It handles invoking | 38 // ViewManagerProxy is a proxy to an IViewManager. It handles invoking |
| 39 // IViewManager functions on the right thread in a synchronous manner (each | 39 // IViewManager functions on the right thread in a synchronous manner (each |
| 40 // IViewManager cover function blocks until the response from the IViewManager | 40 // IViewManager cover function blocks until the response from the IViewManager |
| 41 // is returned). In addition it tracks the set of IViewManagerClient messages | 41 // is returned). In addition it tracks the set of IViewManagerClient messages |
| 42 // received by way of a vector of Changes. Use DoRunLoopUntilChangesCount() to | 42 // received by way of a vector of Changes. Use DoRunLoopUntilChangesCount() to |
| 43 // wait for a certain number of messages to be received. | 43 // wait for a certain number of messages to be received. |
| 44 class ViewManagerProxy : public TestChangeTracker::Delegate { | 44 class ViewManagerProxy : public TestChangeTracker::Delegate { |
| 45 public: | 45 public: |
| 46 ViewManagerProxy(TestChangeTracker* tracker, base::MessageLoop* loop) | 46 explicit ViewManagerProxy(TestChangeTracker* tracker) |
| 47 : tracker_(tracker), | 47 : tracker_(tracker), |
| 48 main_loop_(loop), | |
| 49 background_loop_(base::MessageLoop::current()), | |
| 50 view_manager_(NULL), | 48 view_manager_(NULL), |
| 51 quit_count_(0), | 49 quit_count_(0), |
| 52 router_(NULL) { | 50 router_(NULL) { |
| 53 main_loop_->PostTask(FROM_HERE, | 51 SetInstance(this); |
| 54 base::Bind(&ViewManagerProxy::SetInstance, this)); | |
| 55 } | 52 } |
| 56 | 53 |
| 57 virtual ~ViewManagerProxy() { | 54 virtual ~ViewManagerProxy() {} |
| 58 } | |
| 59 | 55 |
| 60 // Runs a message loop until the single instance has been created. | 56 // Runs a message loop until the single instance has been created. |
| 61 static ViewManagerProxy* WaitForInstance() { | 57 static ViewManagerProxy* WaitForInstance() { |
| 62 if (!instance_) | 58 if (!instance_) |
| 63 RunMainLoop(); | 59 RunMainLoop(); |
| 64 ViewManagerProxy* instance = instance_; | 60 ViewManagerProxy* instance = instance_; |
| 65 instance_ = NULL; | 61 instance_ = NULL; |
| 66 return instance; | 62 return instance; |
| 67 } | 63 } |
| 68 | 64 |
| 69 // Runs the main loop until |count| changes have been received. | 65 // Runs the main loop until |count| changes have been received. |
| 70 std::vector<Change> DoRunLoopUntilChangesCount(size_t count) { | 66 std::vector<Change> DoRunLoopUntilChangesCount(size_t count) { |
| 71 background_loop_->PostTask(FROM_HERE, | 67 DCHECK_EQ(0u, quit_count_); |
| 72 base::Bind(&ViewManagerProxy::SetQuitCount, | 68 if (tracker_->changes()->size() >= count) { |
| 73 base::Unretained(this), count)); | 69 CopyChangesFromTracker(); |
| 70 return changes_; |
| 71 } |
| 72 quit_count_ = count - tracker_->changes()->size(); |
| 74 // Run the current message loop. When |count| Changes have been received, | 73 // Run the current message loop. When |count| Changes have been received, |
| 75 // we'll quit. | 74 // we'll quit. |
| 76 RunMainLoop(); | 75 RunMainLoop(); |
| 77 return changes_; | 76 return changes_; |
| 78 } | 77 } |
| 79 | 78 |
| 80 const std::vector<Change>& changes() const { return changes_; } | 79 const std::vector<Change>& changes() const { return changes_; } |
| 81 | 80 |
| 82 // Destroys the connection, blocking until done. | 81 // Destroys the connection, blocking until done. |
| 83 void Destroy() { | 82 void Destroy() { |
| 84 background_loop_->PostTask( | 83 router_->CloseMessagePipe(); |
| 85 FROM_HERE, | |
| 86 base::Bind(&ViewManagerProxy::DestroyOnBackgroundThread, | |
| 87 base::Unretained(this))); | |
| 88 RunMainLoop(); | |
| 89 } | 84 } |
| 90 | 85 |
| 91 // The following functions mirror that of IViewManager. They bounce the | 86 // The following functions are cover methods for IViewManager. They block |
| 92 // function to the right thread and return the result. | 87 // until the result is received. |
| 93 bool CreateNode(TransportNodeId node_id) { | 88 bool CreateNode(TransportNodeId node_id) { |
| 94 changes_.clear(); | 89 changes_.clear(); |
| 95 bool result = false; | 90 bool result = false; |
| 96 background_loop_->PostTask( | 91 view_manager_->CreateNode(node_id, |
| 97 FROM_HERE, | 92 base::Bind(&ViewManagerProxy::GotResult, |
| 98 base::Bind(&ViewManagerProxy::CreateNodeOnBackgroundThread, | 93 base::Unretained(this), &result)); |
| 99 base::Unretained(this), node_id, &result)); | |
| 100 RunMainLoop(); | 94 RunMainLoop(); |
| 101 return result; | 95 return result; |
| 102 } | 96 } |
| 103 bool AddNode(TransportNodeId parent, | 97 bool AddNode(TransportNodeId parent, |
| 104 TransportNodeId child, | 98 TransportNodeId child, |
| 105 TransportChangeId server_change_id) { | 99 TransportChangeId server_change_id) { |
| 106 changes_.clear(); | 100 changes_.clear(); |
| 107 bool result = false; | 101 bool result = false; |
| 108 background_loop_->PostTask( | 102 view_manager_->AddNode(parent, child, server_change_id, |
| 109 FROM_HERE, | 103 base::Bind(&ViewManagerProxy::GotResult, |
| 110 base::Bind(&ViewManagerProxy::AddNodeOnBackgroundThread, | 104 base::Unretained(this), &result)); |
| 111 base::Unretained(this), parent, child, server_change_id, | |
| 112 &result)); | |
| 113 RunMainLoop(); | 105 RunMainLoop(); |
| 114 return result; | 106 return result; |
| 115 } | 107 } |
| 116 bool RemoveNodeFromParent(TransportNodeId node_id, | 108 bool RemoveNodeFromParent(TransportNodeId node_id, |
| 117 TransportChangeId server_change_id) { | 109 TransportChangeId server_change_id) { |
| 118 changes_.clear(); | 110 changes_.clear(); |
| 119 bool result = false; | 111 bool result = false; |
| 120 background_loop_->PostTask( | 112 view_manager_->RemoveNodeFromParent(node_id, server_change_id, |
| 121 FROM_HERE, | 113 base::Bind(&ViewManagerProxy::GotResult, |
| 122 base::Bind(&ViewManagerProxy::RemoveNodeFromParentOnBackgroundThread, | 114 base::Unretained(this), &result)); |
| 123 base::Unretained(this), node_id, server_change_id, &result)); | |
| 124 RunMainLoop(); | 115 RunMainLoop(); |
| 125 return result; | 116 return result; |
| 126 } | 117 } |
| 127 bool SetView(TransportNodeId node_id, TransportViewId view_id) { | 118 bool SetView(TransportNodeId node_id, TransportViewId view_id) { |
| 128 changes_.clear(); | 119 changes_.clear(); |
| 129 bool result = false; | 120 bool result = false; |
| 130 background_loop_->PostTask( | 121 view_manager_->SetView(node_id, view_id, |
| 131 FROM_HERE, | 122 base::Bind(&ViewManagerProxy::GotResult, |
| 132 base::Bind(&ViewManagerProxy::SetViewOnBackgroundThread, | 123 base::Unretained(this), &result)); |
| 133 base::Unretained(this), node_id, view_id, &result)); | |
| 134 RunMainLoop(); | 124 RunMainLoop(); |
| 135 return result; | 125 return result; |
| 136 } | 126 } |
| 137 bool CreateView(TransportViewId view_id) { | 127 bool CreateView(TransportViewId view_id) { |
| 138 changes_.clear(); | 128 changes_.clear(); |
| 139 bool result = false; | 129 bool result = false; |
| 140 background_loop_->PostTask( | 130 view_manager_->CreateView(view_id, |
| 141 FROM_HERE, | 131 base::Bind(&ViewManagerProxy::GotResult, |
| 142 base::Bind(&ViewManagerProxy::CreateViewOnBackgroundThread, | 132 base::Unretained(this), &result)); |
| 143 base::Unretained(this), view_id, &result)); | |
| 144 RunMainLoop(); | 133 RunMainLoop(); |
| 145 return result; | 134 return result; |
| 146 } | 135 } |
| 147 void GetNodeTree(TransportNodeId node_id, std::vector<TestNode>* nodes) { | 136 void GetNodeTree(TransportNodeId node_id, std::vector<TestNode>* nodes) { |
| 148 changes_.clear(); | 137 changes_.clear(); |
| 149 background_loop_->PostTask( | 138 view_manager_->GetNodeTree(node_id, |
| 150 FROM_HERE, | 139 base::Bind(&ViewManagerProxy::GotNodeTree, |
| 151 base::Bind(&ViewManagerProxy::GetNodeTreeOnBackgroundThread, | 140 base::Unretained(this), nodes)); |
| 152 base::Unretained(this), node_id, nodes)); | |
| 153 RunMainLoop(); | 141 RunMainLoop(); |
| 154 } | 142 } |
| 155 bool Connect(const std::vector<TransportNodeId>& nodes) { | 143 bool Connect(const std::vector<TransportNodeId>& nodes) { |
| 156 changes_.clear(); | 144 changes_.clear(); |
| 157 base::AutoReset<bool> auto_reset(&in_connect_, true); | 145 base::AutoReset<bool> auto_reset(&in_connect_, true); |
| 158 bool result = false; | 146 bool result = false; |
| 159 background_loop_->PostTask( | 147 view_manager_->Connect(kTestServiceURL, Array<TransportNodeId>::From(nodes), |
| 160 FROM_HERE, | 148 base::Bind(&ViewManagerProxy::GotResult, |
| 161 base::Bind(&ViewManagerProxy::ConnectOnBackgroundThread, | 149 base::Unretained(this), &result)); |
| 162 base::Unretained(this), nodes, &result)); | |
| 163 RunMainLoop(); | 150 RunMainLoop(); |
| 164 return result; | 151 return result; |
| 165 } | 152 } |
| 166 bool DeleteNode(TransportNodeId node_id) { | 153 bool DeleteNode(TransportNodeId node_id) { |
| 167 changes_.clear(); | 154 changes_.clear(); |
| 168 bool result = false; | 155 bool result = false; |
| 169 background_loop_->PostTask( | 156 view_manager_->DeleteNode(node_id, |
| 170 FROM_HERE, | 157 base::Bind(&ViewManagerProxy::GotResult, |
| 171 base::Bind(&ViewManagerProxy::DeleteNodeOnBackgroundThread, | 158 base::Unretained(this), &result)); |
| 172 base::Unretained(this), node_id, &result)); | |
| 173 RunMainLoop(); | 159 RunMainLoop(); |
| 174 return result; | 160 return result; |
| 175 } | 161 } |
| 176 bool DeleteView(TransportViewId node_id) { | 162 bool DeleteView(TransportViewId view_id) { |
| 177 changes_.clear(); | 163 changes_.clear(); |
| 178 bool result = false; | 164 bool result = false; |
| 179 background_loop_->PostTask( | 165 view_manager_->DeleteView(view_id, |
| 180 FROM_HERE, | 166 base::Bind(&ViewManagerProxy::GotResult, |
| 181 base::Bind(&ViewManagerProxy::DeleteViewOnBackgroundThread, | 167 base::Unretained(this), &result)); |
| 182 base::Unretained(this), node_id, &result)); | |
| 183 RunMainLoop(); | 168 RunMainLoop(); |
| 184 return result; | 169 return result; |
| 185 } | 170 } |
| 186 bool SetNodeBounds(TransportNodeId node_id, const gfx::Rect& rect) { | 171 bool SetNodeBounds(TransportNodeId node_id, const gfx::Rect& bounds) { |
| 172 changes_.clear(); |
| 187 bool result = false; | 173 bool result = false; |
| 188 background_loop_->PostTask( | 174 view_manager_->SetNodeBounds(node_id, Rect::From(bounds), |
| 189 FROM_HERE, | 175 base::Bind(&ViewManagerProxy::GotResult, |
| 190 base::Bind(&ViewManagerProxy::SetNodeBoundsOnBackgroundThread, | 176 base::Unretained(this), &result)); |
| 191 base::Unretained(this), node_id, rect, &result)); | |
| 192 RunMainLoop(); | 177 RunMainLoop(); |
| 193 return result; | 178 return result; |
| 194 } | 179 } |
| 195 | 180 |
| 196 private: | 181 private: |
| 197 friend class TestViewManagerClientConnection; | 182 friend class TestViewManagerClientConnection; |
| 198 | 183 |
| 199 void set_router(mojo::internal::Router* router) { router_ = router; } | 184 void set_router(mojo::internal::Router* router) { router_ = router; } |
| 200 | 185 |
| 201 void set_view_manager(IViewManager* view_manager) { | 186 void set_view_manager(IViewManager* view_manager) { |
| 202 view_manager_ = view_manager; | 187 view_manager_ = view_manager; |
| 203 } | 188 } |
| 204 | 189 |
| 205 void DestroyOnBackgroundThread() { | |
| 206 router_->CloseMessagePipe(); | |
| 207 main_loop_->PostTask( | |
| 208 FROM_HERE, | |
| 209 base::Bind(&ViewManagerProxy::QuitOnMainThread, | |
| 210 base::Unretained(this))); | |
| 211 } | |
| 212 | |
| 213 void SetQuitCount(size_t count) { | |
| 214 DCHECK_EQ(background_loop_, base::MessageLoop::current()); | |
| 215 if (tracker_->changes()->size() >= count) { | |
| 216 QuitCountReached(); | |
| 217 return; | |
| 218 } | |
| 219 quit_count_ = count - tracker_->changes()->size(); | |
| 220 } | |
| 221 | |
| 222 static void RunMainLoop() { | 190 static void RunMainLoop() { |
| 223 DCHECK(!main_run_loop_); | 191 DCHECK(!main_run_loop_); |
| 224 main_run_loop_ = new base::RunLoop; | 192 main_run_loop_ = new base::RunLoop; |
| 225 main_run_loop_->Run(); | 193 main_run_loop_->Run(); |
| 226 delete main_run_loop_; | 194 delete main_run_loop_; |
| 227 main_run_loop_ = NULL; | 195 main_run_loop_ = NULL; |
| 228 } | 196 } |
| 229 | 197 |
| 230 void QuitCountReached() { | 198 void QuitCountReached() { |
| 231 std::vector<Change> changes; | 199 CopyChangesFromTracker(); |
| 232 tracker_->changes()->swap(changes); | |
| 233 main_loop_->PostTask( | |
| 234 FROM_HERE, | |
| 235 base::Bind(&ViewManagerProxy::QuitCountReachedOnMain, | |
| 236 base::Unretained(this), changes)); | |
| 237 } | |
| 238 | |
| 239 void QuitCountReachedOnMain(const std::vector<Change>& changes) { | |
| 240 changes_ = changes; | |
| 241 DCHECK(main_run_loop_); | |
| 242 main_run_loop_->Quit(); | 200 main_run_loop_->Quit(); |
| 243 } | 201 } |
| 244 | 202 |
| 203 void CopyChangesFromTracker() { |
| 204 std::vector<Change> changes; |
| 205 tracker_->changes()->swap(changes); |
| 206 changes_.swap(changes); |
| 207 } |
| 208 |
| 245 static void SetInstance(ViewManagerProxy* instance) { | 209 static void SetInstance(ViewManagerProxy* instance) { |
| 246 DCHECK(!instance_); | 210 DCHECK(!instance_); |
| 247 instance_ = instance; | 211 instance_ = instance; |
| 248 // Connect() runs its own run loop that is quit when the result is | 212 // Connect() runs its own run loop that is quit when the result is |
| 249 // received. Connect() also results in a new instance. If we quit here while | 213 // received. Connect() also results in a new instance. If we quit here while |
| 250 // waiting for a Connect() we would prematurely return before we got the | 214 // waiting for a Connect() we would prematurely return before we got the |
| 251 // result from Connect(). | 215 // result from Connect(). |
| 252 if (!in_connect_ && main_run_loop_) | 216 if (!in_connect_ && main_run_loop_) |
| 253 main_run_loop_->Quit(); | 217 main_run_loop_->Quit(); |
| 254 } | 218 } |
| 255 | 219 |
| 256 // Callbacks from the various IViewManager functions. | 220 // Callbacks from the various IViewManager functions. |
| 257 void GotResultOnBackgroundThread(bool* result_cache, bool result) { | 221 void GotResult(bool* result_cache, bool result) { |
| 258 *result_cache = result; | 222 *result_cache = result; |
| 259 main_loop_->PostTask( | |
| 260 FROM_HERE, | |
| 261 base::Bind(&ViewManagerProxy::QuitOnMainThread, | |
| 262 base::Unretained(this))); | |
| 263 } | |
| 264 | |
| 265 void GotNodeTreeOnBackgroundThread(std::vector<TestNode>* nodes, | |
| 266 Array<INodePtr> results) { | |
| 267 INodesToTestNodes(results, nodes); | |
| 268 main_loop_->PostTask( | |
| 269 FROM_HERE, | |
| 270 base::Bind(&ViewManagerProxy::QuitOnMainThread, | |
| 271 base::Unretained(this))); | |
| 272 } | |
| 273 | |
| 274 void QuitOnMainThread() { | |
| 275 DCHECK(main_run_loop_); | 223 DCHECK(main_run_loop_); |
| 276 main_run_loop_->Quit(); | 224 main_run_loop_->Quit(); |
| 277 } | 225 } |
| 278 | 226 |
| 279 // The following functions correspond to the IViewManager functions. These run | 227 void GotNodeTree(std::vector<TestNode>* nodes, Array<INodePtr> results) { |
| 280 // on the background thread. | 228 INodesToTestNodes(results, nodes); |
| 281 void CreateNodeOnBackgroundThread(TransportNodeId node_id, bool* result) { | 229 DCHECK(main_run_loop_); |
| 282 view_manager_->CreateNode( | 230 main_run_loop_->Quit(); |
| 283 node_id, | |
| 284 base::Bind(&ViewManagerProxy::GotResultOnBackgroundThread, | |
| 285 base::Unretained(this), result)); | |
| 286 } | |
| 287 void AddNodeOnBackgroundThread(TransportNodeId parent, | |
| 288 TransportNodeId child, | |
| 289 TransportChangeId server_change_id, | |
| 290 bool* result) { | |
| 291 view_manager_->AddNode( | |
| 292 parent, child, server_change_id, | |
| 293 base::Bind(&ViewManagerProxy::GotResultOnBackgroundThread, | |
| 294 base::Unretained(this), result)); | |
| 295 } | |
| 296 void RemoveNodeFromParentOnBackgroundThread( | |
| 297 TransportNodeId node_id, | |
| 298 TransportChangeId server_change_id, | |
| 299 bool* result) { | |
| 300 view_manager_->RemoveNodeFromParent(node_id, server_change_id, | |
| 301 base::Bind(&ViewManagerProxy::GotResultOnBackgroundThread, | |
| 302 base::Unretained(this), result)); | |
| 303 } | |
| 304 void SetViewOnBackgroundThread(TransportNodeId node_id, | |
| 305 TransportViewId view_id, | |
| 306 bool* result) { | |
| 307 view_manager_->SetView(node_id, view_id, | |
| 308 base::Bind(&ViewManagerProxy::GotResultOnBackgroundThread, | |
| 309 base::Unretained(this), result)); | |
| 310 } | |
| 311 void CreateViewOnBackgroundThread(TransportViewId view_id, bool* result) { | |
| 312 view_manager_->CreateView(view_id, | |
| 313 base::Bind(&ViewManagerProxy::GotResultOnBackgroundThread, | |
| 314 base::Unretained(this), result)); | |
| 315 } | |
| 316 void GetNodeTreeOnBackgroundThread(TransportNodeId node_id, | |
| 317 std::vector<TestNode>* nodes) { | |
| 318 view_manager_->GetNodeTree(node_id, | |
| 319 base::Bind(&ViewManagerProxy::GotNodeTreeOnBackgroundThread, | |
| 320 base::Unretained(this), nodes)); | |
| 321 } | |
| 322 void ConnectOnBackgroundThread(const std::vector<TransportNodeId>& ids, | |
| 323 bool* result) { | |
| 324 view_manager_->Connect(kTestServiceURL, | |
| 325 Array<TransportNodeId>::From(ids), | |
| 326 base::Bind(&ViewManagerProxy::GotResultOnBackgroundThread, | |
| 327 base::Unretained(this), result)); | |
| 328 } | |
| 329 void DeleteNodeOnBackgroundThread(TransportNodeId node_id, bool* result) { | |
| 330 view_manager_->DeleteNode(node_id, | |
| 331 base::Bind(&ViewManagerProxy::GotResultOnBackgroundThread, | |
| 332 base::Unretained(this), result)); | |
| 333 } | |
| 334 void DeleteViewOnBackgroundThread(TransportViewId view_id, bool* result) { | |
| 335 view_manager_->DeleteView(view_id, | |
| 336 base::Bind(&ViewManagerProxy::GotResultOnBackgroundThread, | |
| 337 base::Unretained(this), result)); | |
| 338 } | |
| 339 void SetNodeBoundsOnBackgroundThread(TransportNodeId node_id, | |
| 340 const gfx::Rect& bounds, | |
| 341 bool* result) { | |
| 342 view_manager_->SetNodeBounds(node_id, Rect::From(bounds), | |
| 343 base::Bind(&ViewManagerProxy::GotResultOnBackgroundThread, | |
| 344 base::Unretained(this), result)); | |
| 345 } | 231 } |
| 346 | 232 |
| 347 // TestChangeTracker::Delegate: | 233 // TestChangeTracker::Delegate: |
| 348 virtual void OnChangeAdded() OVERRIDE { | 234 virtual void OnChangeAdded() OVERRIDE { |
| 349 if (quit_count_ > 0 && --quit_count_ == 0) | 235 if (quit_count_ > 0 && --quit_count_ == 0) |
| 350 QuitCountReached(); | 236 QuitCountReached(); |
| 351 } | 237 } |
| 352 | 238 |
| 353 static ViewManagerProxy* instance_; | 239 static ViewManagerProxy* instance_; |
| 354 static base::RunLoop* main_run_loop_; | 240 static base::RunLoop* main_run_loop_; |
| 355 static bool in_connect_; | 241 static bool in_connect_; |
| 356 | 242 |
| 357 TestChangeTracker* tracker_; | 243 TestChangeTracker* tracker_; |
| 358 | 244 |
| 359 // MessageLoop of the test. | 245 // MessageLoop of the test. |
| 360 base::MessageLoop* main_loop_; | 246 base::MessageLoop* main_loop_; |
| 361 | 247 |
| 362 // MessageLoop ViewManagerProxy lives on. | |
| 363 base::MessageLoop* background_loop_; | |
| 364 | |
| 365 IViewManager* view_manager_; | 248 IViewManager* view_manager_; |
| 366 | 249 |
| 367 // Number of changes we're waiting on until we quit the current loop. | 250 // Number of changes we're waiting on until we quit the current loop. |
| 368 size_t quit_count_; | 251 size_t quit_count_; |
| 369 | 252 |
| 370 std::vector<Change> changes_; | 253 std::vector<Change> changes_; |
| 371 | 254 |
| 372 mojo::internal::Router* router_; | 255 mojo::internal::Router* router_; |
| 373 | 256 |
| 374 DISALLOW_COPY_AND_ASSIGN(ViewManagerProxy); | 257 DISALLOW_COPY_AND_ASSIGN(ViewManagerProxy); |
| 375 }; | 258 }; |
| 376 | 259 |
| 377 // static | 260 // static |
| 378 ViewManagerProxy* ViewManagerProxy::instance_ = NULL; | 261 ViewManagerProxy* ViewManagerProxy::instance_ = NULL; |
| 379 | 262 |
| 380 // static | 263 // static |
| 381 base::RunLoop* ViewManagerProxy::main_run_loop_ = NULL; | 264 base::RunLoop* ViewManagerProxy::main_run_loop_ = NULL; |
| 382 | 265 |
| 383 // static | 266 // static |
| 384 bool ViewManagerProxy::in_connect_ = false; | 267 bool ViewManagerProxy::in_connect_ = false; |
| 385 | 268 |
| 386 class TestViewManagerClientConnection | 269 class TestViewManagerClientConnection |
| 387 : public InterfaceImpl<IViewManagerClient> { | 270 : public InterfaceImpl<IViewManagerClient> { |
| 388 public: | 271 public: |
| 389 explicit TestViewManagerClientConnection(base::MessageLoop* loop) | 272 TestViewManagerClientConnection() : connection_(&tracker_) { |
| 390 : connection_(&tracker_, loop) { | |
| 391 tracker_.set_delegate(&connection_); | 273 tracker_.set_delegate(&connection_); |
| 392 } | 274 } |
| 393 | 275 |
| 394 // InterfaceImp: | 276 // InterfaceImp: |
| 395 virtual void OnConnectionEstablished() OVERRIDE { | 277 virtual void OnConnectionEstablished() OVERRIDE { |
| 396 connection_.set_router(internal_state()->router()); | 278 connection_.set_router(internal_state()->router()); |
| 397 connection_.set_view_manager(client()); | 279 connection_.set_view_manager(client()); |
| 398 } | 280 } |
| 399 | 281 |
| 400 // IViewMangerClient: | 282 // IViewMangerClient: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 TestChangeTracker tracker_; | 322 TestChangeTracker tracker_; |
| 441 ViewManagerProxy connection_; | 323 ViewManagerProxy connection_; |
| 442 | 324 |
| 443 DISALLOW_COPY_AND_ASSIGN(TestViewManagerClientConnection); | 325 DISALLOW_COPY_AND_ASSIGN(TestViewManagerClientConnection); |
| 444 }; | 326 }; |
| 445 | 327 |
| 446 // Used with IViewManager::Connect(). Creates a TestViewManagerClientConnection, | 328 // Used with IViewManager::Connect(). Creates a TestViewManagerClientConnection, |
| 447 // which creates and owns the ViewManagerProxy. | 329 // which creates and owns the ViewManagerProxy. |
| 448 class ConnectServiceLoader : public ServiceLoader { | 330 class ConnectServiceLoader : public ServiceLoader { |
| 449 public: | 331 public: |
| 450 ConnectServiceLoader() : initial_loop_(base::MessageLoop::current()) { | 332 ConnectServiceLoader() {} |
| 451 } | 333 virtual ~ConnectServiceLoader() {} |
| 452 virtual ~ConnectServiceLoader() { | |
| 453 } | |
| 454 | 334 |
| 455 // ServiceLoader: | 335 // ServiceLoader: |
| 456 virtual void LoadService(ServiceManager* manager, | 336 virtual void LoadService(ServiceManager* manager, |
| 457 const GURL& url, | 337 const GURL& url, |
| 458 ScopedMessagePipeHandle shell_handle) OVERRIDE { | 338 ScopedMessagePipeHandle shell_handle) OVERRIDE { |
| 459 scoped_ptr<Application> app(new Application(shell_handle.Pass())); | 339 scoped_ptr<Application> app(new Application(shell_handle.Pass())); |
| 460 app->AddService<TestViewManagerClientConnection>(initial_loop_); | 340 app->AddService<TestViewManagerClientConnection>(); |
| 461 apps_.push_back(app.release()); | 341 apps_.push_back(app.release()); |
| 462 } | 342 } |
| 463 virtual void OnServiceError(ServiceManager* manager, | 343 virtual void OnServiceError(ServiceManager* manager, |
| 464 const GURL& url) OVERRIDE { | 344 const GURL& url) OVERRIDE { |
| 465 } | 345 } |
| 466 | 346 |
| 467 private: | 347 private: |
| 468 base::MessageLoop* initial_loop_; | |
| 469 ScopedVector<Application> apps_; | 348 ScopedVector<Application> apps_; |
| 470 | 349 |
| 471 DISALLOW_COPY_AND_ASSIGN(ConnectServiceLoader); | 350 DISALLOW_COPY_AND_ASSIGN(ConnectServiceLoader); |
| 472 }; | 351 }; |
| 473 | 352 |
| 474 // Creates an id used for transport from the specified parameters. | 353 // Creates an id used for transport from the specified parameters. |
| 475 TransportNodeId BuildNodeId(TransportConnectionId connection_id, | 354 TransportNodeId BuildNodeId(TransportConnectionId connection_id, |
| 476 TransportConnectionSpecificNodeId node_id) { | 355 TransportConnectionSpecificNodeId node_id) { |
| 477 return (connection_id << 16) | node_id; | 356 return (connection_id << 16) | node_id; |
| 478 } | 357 } |
| (...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1321 // TODO(sky): add coverage of test that destroys connections and ensures other | 1200 // TODO(sky): add coverage of test that destroys connections and ensures other |
| 1322 // connections get deletion notification (or advanced server id). | 1201 // connections get deletion notification (or advanced server id). |
| 1323 | 1202 |
| 1324 // TODO(sky): need to better track changes to initial connection. For example, | 1203 // TODO(sky): need to better track changes to initial connection. For example, |
| 1325 // that SetBounsdNodes/AddNode and the like don't result in messages to the | 1204 // that SetBounsdNodes/AddNode and the like don't result in messages to the |
| 1326 // originating connection. | 1205 // originating connection. |
| 1327 | 1206 |
| 1328 } // namespace service | 1207 } // namespace service |
| 1329 } // namespace view_manager | 1208 } // namespace view_manager |
| 1330 } // namespace mojo | 1209 } // namespace mojo |
| OLD | NEW |