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/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 return result; | 244 return result; |
245 } | 245 } |
246 | 246 |
247 void set_view_manager(ViewManagerService* view_manager) { | 247 void set_view_manager(ViewManagerService* view_manager) { |
248 view_manager_ = view_manager; | 248 view_manager_ = view_manager; |
249 SetInstance(this); | 249 SetInstance(this); |
250 } | 250 } |
251 | 251 |
252 private: | 252 private: |
253 friend class TestViewManagerClientConnection; | 253 friend class TestViewManagerClientConnection; |
254 friend class WindowManagerInternalServiceImpl; | 254 friend class TestWindowManagerImpl; |
255 | 255 |
256 void set_router(mojo::internal::Router* router) { router_ = router; } | 256 void set_router(mojo::internal::Router* router) { router_ = router; } |
257 | 257 |
258 void set_window_manager_client(WindowManagerInternalClient* client) { | 258 void set_window_manager_client(WindowManagerInternalClient* client) { |
259 window_manager_client_ = client; | 259 window_manager_client_ = client; |
260 } | 260 } |
261 | 261 |
262 static void RunMainLoop() { | 262 static void RunMainLoop() { |
263 DCHECK(!main_run_loop_); | 263 DCHECK(!main_run_loop_); |
264 main_run_loop_ = new base::RunLoop; | 264 main_run_loop_ = new base::RunLoop; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 tracker_.OnViewPropertyChanged(view, name, new_data.Pass()); | 400 tracker_.OnViewPropertyChanged(view, name, new_data.Pass()); |
401 } | 401 } |
402 | 402 |
403 private: | 403 private: |
404 TestChangeTracker tracker_; | 404 TestChangeTracker tracker_; |
405 ViewManagerProxy proxy_; | 405 ViewManagerProxy proxy_; |
406 | 406 |
407 DISALLOW_COPY_AND_ASSIGN(TestViewManagerClientConnection); | 407 DISALLOW_COPY_AND_ASSIGN(TestViewManagerClientConnection); |
408 }; | 408 }; |
409 | 409 |
410 class WindowManagerInternalServiceImpl | |
411 : public InterfaceImpl<WindowManagerInternalService> { | |
412 public: | |
413 explicit WindowManagerInternalServiceImpl( | |
414 TestViewManagerClientConnection* connection) | |
415 : connection_(connection) {} | |
416 ~WindowManagerInternalServiceImpl() override {} | |
417 | |
418 // InterfaceImpl: | |
419 void OnConnectionEstablished() override { | |
420 connection_->proxy()->set_window_manager_client(client()); | |
421 } | |
422 | |
423 void OnViewInputEvent(mojo::EventPtr event) override {} | |
424 | |
425 private: | |
426 TestViewManagerClientConnection* connection_; | |
427 | |
428 DISALLOW_COPY_AND_ASSIGN(WindowManagerInternalServiceImpl); | |
429 }; | |
430 | |
431 // Used with ViewManagerService::Embed(). Creates a | 410 // Used with ViewManagerService::Embed(). Creates a |
432 // TestViewManagerClientConnection, which creates and owns the ViewManagerProxy. | 411 // TestViewManagerClientConnection, which creates and owns the ViewManagerProxy. |
433 class EmbedApplicationLoader | 412 class EmbedApplicationLoader : public ApplicationLoader, |
434 : public ApplicationLoader, | 413 ApplicationDelegate, |
435 ApplicationDelegate, | 414 public InterfaceFactory<ViewManagerClient> { |
436 public InterfaceFactory<ViewManagerClient>, | |
437 public InterfaceFactory<WindowManagerInternalService> { | |
438 public: | 415 public: |
439 EmbedApplicationLoader() : last_view_manager_client_(nullptr) {} | 416 EmbedApplicationLoader() {} |
440 ~EmbedApplicationLoader() override {} | 417 ~EmbedApplicationLoader() override {} |
441 | 418 |
442 // ApplicationLoader implementation: | 419 // ApplicationLoader implementation: |
443 void Load(ApplicationManager* manager, | 420 void Load(ApplicationManager* manager, |
444 const GURL& url, | 421 const GURL& url, |
445 scoped_refptr<LoadCallbacks> callbacks) override { | 422 scoped_refptr<LoadCallbacks> callbacks) override { |
446 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication(); | 423 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication(); |
447 if (!shell_handle.is_valid()) | 424 if (!shell_handle.is_valid()) |
448 return; | 425 return; |
449 scoped_ptr<ApplicationImpl> app(new ApplicationImpl(this, | 426 scoped_ptr<ApplicationImpl> app(new ApplicationImpl(this, |
450 shell_handle.Pass())); | 427 shell_handle.Pass())); |
451 apps_.push_back(app.release()); | 428 apps_.push_back(app.release()); |
452 } | 429 } |
453 void OnApplicationError(ApplicationManager* manager, | 430 void OnApplicationError(ApplicationManager* manager, |
454 const GURL& url) override {} | 431 const GURL& url) override {} |
455 | 432 |
456 // ApplicationDelegate implementation: | 433 // ApplicationDelegate implementation: |
457 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | 434 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
458 connection->AddService<ViewManagerClient>(this); | 435 connection->AddService<ViewManagerClient>(this); |
459 connection->AddService<WindowManagerInternalService>(this); | |
460 return true; | 436 return true; |
461 } | 437 } |
462 | 438 |
463 // InterfaceFactory<ViewManagerClient> implementation: | 439 // InterfaceFactory<ViewManagerClient> implementation: |
464 void Create(ApplicationConnection* connection, | 440 void Create(ApplicationConnection* connection, |
465 InterfaceRequest<ViewManagerClient> request) override { | 441 InterfaceRequest<ViewManagerClient> request) override { |
466 last_view_manager_client_ = new TestViewManagerClientConnection(); | 442 BindToRequest(new TestViewManagerClientConnection(), &request); |
467 BindToRequest(last_view_manager_client_, &request); | |
468 } | |
469 void Create(ApplicationConnection* connection, | |
470 InterfaceRequest<WindowManagerInternalService> request) override { | |
471 BindToRequest( | |
472 new WindowManagerInternalServiceImpl(last_view_manager_client_), | |
473 &request); | |
474 } | 443 } |
475 | 444 |
476 private: | 445 private: |
477 // Used so that TestViewManagerClientConnection and | |
478 // WindowManagerInternalServiceImpl can share the same TestChangeTracker. | |
479 TestViewManagerClientConnection* last_view_manager_client_; | |
480 ScopedVector<ApplicationImpl> apps_; | 446 ScopedVector<ApplicationImpl> apps_; |
481 | 447 |
482 DISALLOW_COPY_AND_ASSIGN(EmbedApplicationLoader); | 448 DISALLOW_COPY_AND_ASSIGN(EmbedApplicationLoader); |
483 }; | 449 }; |
484 | 450 |
485 class TestWindowManagerImpl | 451 class TestWindowManagerImpl : public InterfaceImpl<WindowManager> { |
486 : public InterfaceImpl<WindowManager>, | |
487 public InterfaceFactory<WindowManagerInternalService> { | |
488 public: | 452 public: |
489 explicit TestWindowManagerImpl(ApplicationConnection* connection) | 453 explicit TestWindowManagerImpl(ApplicationConnection* connection) |
490 : view_manager_client_(nullptr), got_initial_embed_(false) { | 454 : view_manager_client_(nullptr), got_initial_embed_(false) { |
491 // WindowManager is expected to establish initial connection to VM. | 455 // WindowManager is expected to establish initial connection to VM. |
492 ApplicationConnection* view_manager_app = | 456 ApplicationConnection* view_manager_app = |
493 connection->ConnectToApplication("mojo:view_manager"); | 457 connection->ConnectToApplication("mojo:view_manager"); |
494 view_manager_app->AddService<WindowManagerInternalService>(this); | |
495 view_manager_app->ConnectToService(&view_manager_); | 458 view_manager_app->ConnectToService(&view_manager_); |
| 459 view_manager_app->ConnectToService(&window_manager_client_); |
496 | 460 |
497 view_manager_client_ = new TestViewManagerClientConnection(); | 461 view_manager_client_ = new TestViewManagerClientConnection(); |
498 view_manager_.set_client(view_manager_client_); | 462 view_manager_.set_client(view_manager_client_); |
| 463 view_manager_client_->proxy()->set_window_manager_client( |
| 464 window_manager_client_.get()); |
499 view_manager_client_->proxy()->set_view_manager(view_manager_.get()); | 465 view_manager_client_->proxy()->set_view_manager(view_manager_.get()); |
500 } | 466 } |
501 | 467 |
502 virtual ~TestWindowManagerImpl() {} | 468 virtual ~TestWindowManagerImpl() {} |
503 | 469 |
504 TestViewManagerClientConnection* view_manager_client() { | 470 TestViewManagerClientConnection* view_manager_client() { |
505 return view_manager_client_; | 471 return view_manager_client_; |
506 } | 472 } |
507 | 473 |
508 // InterfaceImpl: | 474 // InterfaceImpl: |
509 virtual void OnConnectionEstablished() override {} | 475 virtual void OnConnectionEstablished() override {} |
510 | 476 |
511 // WindowManager: | 477 // WindowManager: |
512 virtual void Embed( | 478 virtual void Embed( |
513 const String& url, | 479 const String& url, |
514 InterfaceRequest<ServiceProvider> service_provider) override { | 480 InterfaceRequest<ServiceProvider> service_provider) override { |
515 if (!got_initial_embed_) { | 481 if (!got_initial_embed_) { |
516 got_initial_embed_ = true; | 482 got_initial_embed_ = true; |
517 return; | 483 return; |
518 } | 484 } |
519 view_manager_client_->tracker()->DelegateEmbed(url); | 485 view_manager_client_->tracker()->DelegateEmbed(url); |
520 } | 486 } |
521 | 487 |
522 // InterfaceFactory<>: | |
523 virtual void Create( | |
524 ApplicationConnection* connection, | |
525 InterfaceRequest<WindowManagerInternalService> request) override { | |
526 BindToRequest(new WindowManagerInternalServiceImpl(view_manager_client_), | |
527 &request); | |
528 } | |
529 | |
530 private: | 488 private: |
531 ViewManagerServicePtr view_manager_; | 489 ViewManagerServicePtr view_manager_; |
532 TestViewManagerClientConnection* view_manager_client_; | 490 TestViewManagerClientConnection* view_manager_client_; |
| 491 WindowManagerInternalClientPtr window_manager_client_; |
533 | 492 |
534 // Did we get Embed() yet? | 493 // Did we get Embed() yet? |
535 bool got_initial_embed_; | 494 bool got_initial_embed_; |
536 | 495 |
537 DISALLOW_COPY_AND_ASSIGN(TestWindowManagerImpl); | 496 DISALLOW_COPY_AND_ASSIGN(TestWindowManagerImpl); |
538 }; | 497 }; |
539 | 498 |
540 class WindowManagerLoader : public ApplicationLoader, | 499 class WindowManagerLoader : public ApplicationLoader, |
541 public ApplicationDelegate, | 500 public ApplicationDelegate, |
542 public InterfaceFactory<WindowManager> { | 501 public InterfaceFactory<WindowManager> { |
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1635 | 1594 |
1636 // TODO(sky): add coverage of test that destroys connections and ensures other | 1595 // TODO(sky): add coverage of test that destroys connections and ensures other |
1637 // connections get deletion notification. | 1596 // connections get deletion notification. |
1638 | 1597 |
1639 // TODO(sky): need to better track changes to initial connection. For example, | 1598 // TODO(sky): need to better track changes to initial connection. For example, |
1640 // that SetBounsdViews/AddView and the like don't result in messages to the | 1599 // that SetBounsdViews/AddView and the like don't result in messages to the |
1641 // originating connection. | 1600 // originating connection. |
1642 | 1601 |
1643 } // namespace service | 1602 } // namespace service |
1644 } // namespace mojo | 1603 } // namespace mojo |
OLD | NEW |