| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 explicit ViewManagerProxy(TestChangeTracker* tracker) | 58 explicit ViewManagerProxy(TestChangeTracker* tracker) |
| 59 : tracker_(tracker), | 59 : tracker_(tracker), |
| 60 main_loop_(nullptr), | 60 main_loop_(nullptr), |
| 61 view_manager_(nullptr), | 61 view_manager_(nullptr), |
| 62 window_manager_client_(nullptr), | 62 window_manager_client_(nullptr), |
| 63 quit_count_(0), | 63 quit_count_(0), |
| 64 router_(nullptr) { | 64 router_(nullptr) { |
| 65 SetInstance(this); | 65 SetInstance(this); |
| 66 } | 66 } |
| 67 | 67 |
| 68 virtual ~ViewManagerProxy() { | 68 ~ViewManagerProxy() override {} |
| 69 } | |
| 70 | 69 |
| 71 // Returns true if in an initial state. If this returns false it means the | 70 // Returns true if in an initial state. If this returns false it means the |
| 72 // last test didn't clean up properly, or most likely didn't invoke | 71 // last test didn't clean up properly, or most likely didn't invoke |
| 73 // WaitForInstance() when it needed to. | 72 // WaitForInstance() when it needed to. |
| 74 static bool IsInInitialState() { return instance_ == NULL; } | 73 static bool IsInInitialState() { return instance_ == NULL; } |
| 75 | 74 |
| 76 // Runs a message loop until the single instance has been created. | 75 // Runs a message loop until the single instance has been created. |
| 77 static ViewManagerProxy* WaitForInstance() { | 76 static ViewManagerProxy* WaitForInstance() { |
| 78 if (!instance_) | 77 if (!instance_) |
| 79 RunMainLoop(); | 78 RunMainLoop(); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 main_run_loop_->Quit(); | 280 main_run_loop_->Quit(); |
| 282 } | 281 } |
| 283 | 282 |
| 284 void GotViewTree(std::vector<TestView>* views, Array<ViewDataPtr> results) { | 283 void GotViewTree(std::vector<TestView>* views, Array<ViewDataPtr> results) { |
| 285 ViewDatasToTestViews(results, views); | 284 ViewDatasToTestViews(results, views); |
| 286 DCHECK(main_run_loop_); | 285 DCHECK(main_run_loop_); |
| 287 main_run_loop_->Quit(); | 286 main_run_loop_->Quit(); |
| 288 } | 287 } |
| 289 | 288 |
| 290 // TestChangeTracker::Delegate: | 289 // TestChangeTracker::Delegate: |
| 291 virtual void OnChangeAdded() override { | 290 void OnChangeAdded() override { |
| 292 if (quit_count_ > 0 && --quit_count_ == 0) | 291 if (quit_count_ > 0 && --quit_count_ == 0) |
| 293 QuitCountReached(); | 292 QuitCountReached(); |
| 294 } | 293 } |
| 295 | 294 |
| 296 static ViewManagerProxy* instance_; | 295 static ViewManagerProxy* instance_; |
| 297 static base::RunLoop* main_run_loop_; | 296 static base::RunLoop* main_run_loop_; |
| 298 static bool in_embed_; | 297 static bool in_embed_; |
| 299 | 298 |
| 300 TestChangeTracker* tracker_; | 299 TestChangeTracker* tracker_; |
| 301 | 300 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 329 public: | 328 public: |
| 330 TestViewManagerClientConnection() : proxy_(&tracker_) { | 329 TestViewManagerClientConnection() : proxy_(&tracker_) { |
| 331 tracker_.set_delegate(&proxy_); | 330 tracker_.set_delegate(&proxy_); |
| 332 } | 331 } |
| 333 | 332 |
| 334 TestChangeTracker* tracker() { return &tracker_; } | 333 TestChangeTracker* tracker() { return &tracker_; } |
| 335 | 334 |
| 336 ViewManagerProxy* proxy() { return &proxy_; } | 335 ViewManagerProxy* proxy() { return &proxy_; } |
| 337 | 336 |
| 338 // InterfaceImpl: | 337 // InterfaceImpl: |
| 339 virtual void OnConnectionEstablished() override { | 338 void OnConnectionEstablished() override { |
| 340 proxy_.set_router(internal_state()->router()); | 339 proxy_.set_router(internal_state()->router()); |
| 341 proxy_.set_view_manager(client()); | 340 proxy_.set_view_manager(client()); |
| 342 } | 341 } |
| 343 | 342 |
| 344 // ViewManagerClient: | 343 // ViewManagerClient: |
| 345 virtual void OnEmbed( | 344 void OnEmbed(ConnectionSpecificId connection_id, |
| 346 ConnectionSpecificId connection_id, | 345 const String& creator_url, |
| 347 const String& creator_url, | 346 ViewDataPtr root, |
| 348 ViewDataPtr root, | 347 InterfaceRequest<ServiceProvider> services) override { |
| 349 InterfaceRequest<ServiceProvider> services) override { | |
| 350 tracker_.OnEmbed(connection_id, creator_url, root.Pass()); | 348 tracker_.OnEmbed(connection_id, creator_url, root.Pass()); |
| 351 } | 349 } |
| 352 virtual void OnViewBoundsChanged(Id view_id, | 350 void OnViewBoundsChanged(Id view_id, |
| 353 RectPtr old_bounds, | 351 RectPtr old_bounds, |
| 354 RectPtr new_bounds) override { | 352 RectPtr new_bounds) override { |
| 355 tracker_.OnViewBoundsChanged(view_id, old_bounds.Pass(), new_bounds.Pass()); | 353 tracker_.OnViewBoundsChanged(view_id, old_bounds.Pass(), new_bounds.Pass()); |
| 356 } | 354 } |
| 357 virtual void OnViewHierarchyChanged(Id view, | 355 void OnViewHierarchyChanged(Id view, |
| 358 Id new_parent, | 356 Id new_parent, |
| 359 Id old_parent, | 357 Id old_parent, |
| 360 Array<ViewDataPtr> views) override { | 358 Array<ViewDataPtr> views) override { |
| 361 tracker_.OnViewHierarchyChanged(view, new_parent, old_parent, views.Pass()); | 359 tracker_.OnViewHierarchyChanged(view, new_parent, old_parent, views.Pass()); |
| 362 } | 360 } |
| 363 virtual void OnViewReordered(Id view_id, | 361 void OnViewReordered(Id view_id, |
| 364 Id relative_view_id, | 362 Id relative_view_id, |
| 365 OrderDirection direction) override { | 363 OrderDirection direction) override { |
| 366 tracker_.OnViewReordered(view_id, relative_view_id, direction); | 364 tracker_.OnViewReordered(view_id, relative_view_id, direction); |
| 367 } | 365 } |
| 368 virtual void OnViewDeleted(Id view) override { tracker_.OnViewDeleted(view); } | 366 void OnViewDeleted(Id view) override { tracker_.OnViewDeleted(view); } |
| 369 virtual void OnViewVisibilityChanged(uint32_t view, bool visible) override { | 367 void OnViewVisibilityChanged(uint32_t view, bool visible) override { |
| 370 tracker_.OnViewVisibilityChanged(view, visible); | 368 tracker_.OnViewVisibilityChanged(view, visible); |
| 371 } | 369 } |
| 372 virtual void OnViewDrawnStateChanged(uint32_t view, bool drawn) override { | 370 void OnViewDrawnStateChanged(uint32_t view, bool drawn) override { |
| 373 tracker_.OnViewDrawnStateChanged(view, drawn); | 371 tracker_.OnViewDrawnStateChanged(view, drawn); |
| 374 } | 372 } |
| 375 virtual void OnViewInputEvent(Id view_id, | 373 void OnViewInputEvent(Id view_id, |
| 376 EventPtr event, | 374 EventPtr event, |
| 377 const Callback<void()>& callback) override { | 375 const Callback<void()>& callback) override { |
| 378 tracker_.OnViewInputEvent(view_id, event.Pass()); | 376 tracker_.OnViewInputEvent(view_id, event.Pass()); |
| 379 } | 377 } |
| 380 | 378 |
| 381 private: | 379 private: |
| 382 TestChangeTracker tracker_; | 380 TestChangeTracker tracker_; |
| 383 ViewManagerProxy proxy_; | 381 ViewManagerProxy proxy_; |
| 384 | 382 |
| 385 DISALLOW_COPY_AND_ASSIGN(TestViewManagerClientConnection); | 383 DISALLOW_COPY_AND_ASSIGN(TestViewManagerClientConnection); |
| 386 }; | 384 }; |
| 387 | 385 |
| 388 class WindowManagerServiceImpl : public InterfaceImpl<WindowManagerService> { | 386 class WindowManagerServiceImpl : public InterfaceImpl<WindowManagerService> { |
| 389 public: | 387 public: |
| 390 explicit WindowManagerServiceImpl(TestViewManagerClientConnection* connection) | 388 explicit WindowManagerServiceImpl(TestViewManagerClientConnection* connection) |
| 391 : connection_(connection) {} | 389 : connection_(connection) {} |
| 392 virtual ~WindowManagerServiceImpl() {} | 390 ~WindowManagerServiceImpl() override {} |
| 393 | 391 |
| 394 // InterfaceImpl: | 392 // InterfaceImpl: |
| 395 virtual void OnConnectionEstablished() override { | 393 void OnConnectionEstablished() override { |
| 396 connection_->proxy()->set_window_manager_client(client()); | 394 connection_->proxy()->set_window_manager_client(client()); |
| 397 } | 395 } |
| 398 | 396 |
| 399 // WindowManagerService: | 397 // WindowManagerService: |
| 400 virtual void Embed( | 398 void Embed(const String& url, |
| 401 const String& url, | 399 InterfaceRequest<ServiceProvider> service_provider) override { |
| 402 InterfaceRequest<ServiceProvider> service_provider) override { | |
| 403 connection_->tracker()->DelegateEmbed(url); | 400 connection_->tracker()->DelegateEmbed(url); |
| 404 } | 401 } |
| 405 virtual void OnViewInputEvent(mojo::EventPtr event) override {} | 402 void OnViewInputEvent(mojo::EventPtr event) override {} |
| 406 | 403 |
| 407 private: | 404 private: |
| 408 TestViewManagerClientConnection* connection_; | 405 TestViewManagerClientConnection* connection_; |
| 409 | 406 |
| 410 DISALLOW_COPY_AND_ASSIGN(WindowManagerServiceImpl); | 407 DISALLOW_COPY_AND_ASSIGN(WindowManagerServiceImpl); |
| 411 }; | 408 }; |
| 412 | 409 |
| 413 // Used with ViewManagerService::Embed(). Creates a | 410 // Used with ViewManagerService::Embed(). Creates a |
| 414 // TestViewManagerClientConnection, which creates and owns the ViewManagerProxy. | 411 // TestViewManagerClientConnection, which creates and owns the ViewManagerProxy. |
| 415 class EmbedApplicationLoader : public ApplicationLoader, | 412 class EmbedApplicationLoader : public ApplicationLoader, |
| 416 ApplicationDelegate, | 413 ApplicationDelegate, |
| 417 public InterfaceFactory<ViewManagerClient>, | 414 public InterfaceFactory<ViewManagerClient>, |
| 418 public InterfaceFactory<WindowManagerService> { | 415 public InterfaceFactory<WindowManagerService> { |
| 419 public: | 416 public: |
| 420 EmbedApplicationLoader() : last_view_manager_client_(nullptr) {} | 417 EmbedApplicationLoader() : last_view_manager_client_(nullptr) {} |
| 421 virtual ~EmbedApplicationLoader() {} | 418 ~EmbedApplicationLoader() override {} |
| 422 | 419 |
| 423 // ApplicationLoader implementation: | 420 // ApplicationLoader implementation: |
| 424 virtual void Load(ApplicationManager* manager, | 421 void Load(ApplicationManager* manager, |
| 425 const GURL& url, | 422 const GURL& url, |
| 426 scoped_refptr<LoadCallbacks> callbacks) override { | 423 scoped_refptr<LoadCallbacks> callbacks) override { |
| 427 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication(); | 424 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication(); |
| 428 if (!shell_handle.is_valid()) | 425 if (!shell_handle.is_valid()) |
| 429 return; | 426 return; |
| 430 scoped_ptr<ApplicationImpl> app(new ApplicationImpl(this, | 427 scoped_ptr<ApplicationImpl> app(new ApplicationImpl(this, |
| 431 shell_handle.Pass())); | 428 shell_handle.Pass())); |
| 432 apps_.push_back(app.release()); | 429 apps_.push_back(app.release()); |
| 433 } | 430 } |
| 434 virtual void OnApplicationError(ApplicationManager* manager, | 431 void OnApplicationError(ApplicationManager* manager, |
| 435 const GURL& url) override {} | 432 const GURL& url) override {} |
| 436 | 433 |
| 437 // ApplicationDelegate implementation: | 434 // ApplicationDelegate implementation: |
| 438 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 435 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
| 439 override { | |
| 440 connection->AddService<ViewManagerClient>(this); | 436 connection->AddService<ViewManagerClient>(this); |
| 441 connection->AddService<WindowManagerService>(this); | 437 connection->AddService<WindowManagerService>(this); |
| 442 return true; | 438 return true; |
| 443 } | 439 } |
| 444 | 440 |
| 445 // InterfaceFactory<ViewManagerClient> implementation: | 441 // InterfaceFactory<ViewManagerClient> implementation: |
| 446 virtual void Create(ApplicationConnection* connection, | 442 void Create(ApplicationConnection* connection, |
| 447 InterfaceRequest<ViewManagerClient> request) override { | 443 InterfaceRequest<ViewManagerClient> request) override { |
| 448 last_view_manager_client_ = new TestViewManagerClientConnection; | 444 last_view_manager_client_ = new TestViewManagerClientConnection; |
| 449 BindToRequest(last_view_manager_client_, &request); | 445 BindToRequest(last_view_manager_client_, &request); |
| 450 } | 446 } |
| 451 virtual void Create(ApplicationConnection* connection, | 447 void Create(ApplicationConnection* connection, |
| 452 InterfaceRequest<WindowManagerService> request) override { | 448 InterfaceRequest<WindowManagerService> request) override { |
| 453 BindToRequest(new WindowManagerServiceImpl(last_view_manager_client_), | 449 BindToRequest(new WindowManagerServiceImpl(last_view_manager_client_), |
| 454 &request); | 450 &request); |
| 455 } | 451 } |
| 456 | 452 |
| 457 private: | 453 private: |
| 458 // Used so that TestViewManagerClientConnection and | 454 // Used so that TestViewManagerClientConnection and |
| 459 // WindowManagerServiceImpl can share the same TestChangeTracker. | 455 // WindowManagerServiceImpl can share the same TestChangeTracker. |
| 460 TestViewManagerClientConnection* last_view_manager_client_; | 456 TestViewManagerClientConnection* last_view_manager_client_; |
| 461 ScopedVector<ApplicationImpl> apps_; | 457 ScopedVector<ApplicationImpl> apps_; |
| 462 | 458 |
| (...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1476 | 1472 |
| 1477 // TODO(sky): add coverage of test that destroys connections and ensures other | 1473 // TODO(sky): add coverage of test that destroys connections and ensures other |
| 1478 // connections get deletion notification. | 1474 // connections get deletion notification. |
| 1479 | 1475 |
| 1480 // TODO(sky): need to better track changes to initial connection. For example, | 1476 // TODO(sky): need to better track changes to initial connection. For example, |
| 1481 // that SetBounsdViews/AddView and the like don't result in messages to the | 1477 // that SetBounsdViews/AddView and the like don't result in messages to the |
| 1482 // originating connection. | 1478 // originating connection. |
| 1483 | 1479 |
| 1484 } // namespace service | 1480 } // namespace service |
| 1485 } // namespace mojo | 1481 } // namespace mojo |
| OLD | NEW |