| 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 #include "ash/system/cast/tray_cast.h" | 5 #include "ash/system/cast/tray_cast.h" |
| 6 | 6 |
| 7 #include "ash/session/session_state_delegate.h" | 7 #include "ash/session/session_state_delegate.h" |
| 8 #include "ash/shelf/shelf_types.h" | 8 #include "ash/shelf/shelf_types.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/system/chromeos/screen_security/screen_tray_item.h" | 10 #include "ash/system/chromeos/screen_security/screen_tray_item.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 namespace ash { | 36 namespace ash { |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 const int kMaximumStatusStringLength = 100; | 40 const int kMaximumStatusStringLength = 100; |
| 41 const int kStopButtonRightPadding = 18; | 41 const int kStopButtonRightPadding = 18; |
| 42 | 42 |
| 43 // Returns the active CastConfigDelegate instance. | 43 // Returns the active CastConfigDelegate instance. |
| 44 ash::CastConfigDelegate* GetCastConfigDelegate() { | 44 ash::CastConfigDelegate* GetCastConfigDelegate() { |
| 45 // When shutting down Chrome, there may not be a shell or a delegate instance. | |
| 46 if (!ash::Shell::GetInstance() || | |
| 47 !ash::Shell::GetInstance()->system_tray_delegate()) { | |
| 48 return nullptr; | |
| 49 } | |
| 50 | |
| 51 return ash::Shell::GetInstance() | 45 return ash::Shell::GetInstance() |
| 52 ->system_tray_delegate() | 46 ->system_tray_delegate() |
| 53 ->GetCastConfigDelegate(); | 47 ->GetCastConfigDelegate(); |
| 54 } | 48 } |
| 55 | 49 |
| 56 // Helper method to elide the given string to the maximum length. If a string is | 50 // Helper method to elide the given string to the maximum length. If a string is |
| 57 // contains user-input and is displayed, we should elide it. | 51 // contains user-input and is displayed, we should elide it. |
| 58 // TODO(jdufault): This does not properly trim unicode characters. We should | 52 // TODO(jdufault): This does not properly trim unicode characters. We should |
| 59 // implement this properly by using views::Label::SetElideBehavior(...). See | 53 // implement this properly by using views::Label::SetElideBehavior(...). See |
| 60 // crbug.com/532496. | 54 // crbug.com/532496. |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 } | 547 } |
| 554 } | 548 } |
| 555 | 549 |
| 556 } // namespace tray | 550 } // namespace tray |
| 557 | 551 |
| 558 TrayCast::TrayCast(SystemTray* system_tray) : SystemTrayItem(system_tray) { | 552 TrayCast::TrayCast(SystemTray* system_tray) : SystemTrayItem(system_tray) { |
| 559 Shell::GetInstance()->AddShellObserver(this); | 553 Shell::GetInstance()->AddShellObserver(this); |
| 560 } | 554 } |
| 561 | 555 |
| 562 TrayCast::~TrayCast() { | 556 TrayCast::~TrayCast() { |
| 563 // TODO(jdufault): Remove these if checks (and the ones in | 557 Shell::GetInstance()->RemoveShellObserver(this); |
| 564 // GetCastConfigDelegate) by fixing deinit order. See crbug.com/577413. | 558 if (added_observer_) |
| 565 if (Shell::GetInstance()) | 559 GetCastConfigDelegate()->RemoveObserver(this); |
| 566 Shell::GetInstance()->RemoveShellObserver(this); | |
| 567 | |
| 568 ash::CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate(); | |
| 569 if (added_observer_ && cast_config_delegate) | |
| 570 cast_config_delegate->RemoveObserver(this); | |
| 571 } | 560 } |
| 572 | 561 |
| 573 void TrayCast::StartCastForTest(const std::string& receiver_id) { | 562 void TrayCast::StartCastForTest(const std::string& receiver_id) { |
| 574 if (detailed_ != nullptr) | 563 if (detailed_ != nullptr) |
| 575 detailed_->SimulateViewClickedForTest(receiver_id); | 564 detailed_->SimulateViewClickedForTest(receiver_id); |
| 576 } | 565 } |
| 577 | 566 |
| 578 void TrayCast::StopCastForTest() { | 567 void TrayCast::StopCastForTest() { |
| 579 default_->cast_view()->StopCasting(); | 568 default_->cast_view()->StopCasting(); |
| 580 } | 569 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 is_casting_ = started; | 679 is_casting_ = started; |
| 691 UpdatePrimaryView(); | 680 UpdatePrimaryView(); |
| 692 } | 681 } |
| 693 | 682 |
| 694 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 683 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 695 if (tray_) | 684 if (tray_) |
| 696 tray_->UpdateAlignment(alignment); | 685 tray_->UpdateAlignment(alignment); |
| 697 } | 686 } |
| 698 | 687 |
| 699 } // namespace ash | 688 } // namespace ash |
| OLD | NEW |