Chromium Code Reviews| 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 if (!ash::Shell::GetInstance() || | |
| 46 !ash::Shell::GetInstance()->system_tray_delegate()) | |
| 47 return nullptr; | |
|
stevenjb
2016/01/12 23:31:49
nit: {}
jdufault
2016/01/12 23:59:22
Done.
| |
| 48 | |
| 45 return ash::Shell::GetInstance() | 49 return ash::Shell::GetInstance() |
| 46 ->system_tray_delegate() | 50 ->system_tray_delegate() |
| 47 ->GetCastConfigDelegate(); | 51 ->GetCastConfigDelegate(); |
| 48 } | 52 } |
| 49 | 53 |
| 50 // Helper method to elide the given string to the maximum length. If a string is | 54 // Helper method to elide the given string to the maximum length. If a string is |
| 51 // contains user-input and is displayed, we should elide it. | 55 // contains user-input and is displayed, we should elide it. |
| 52 // TODO(jdufault): This does not properly trim unicode characters. We should | 56 // TODO(jdufault): This does not properly trim unicode characters. We should |
| 53 // implement this properly by using views::Label::SetElideBehavior(...). See | 57 // implement this properly by using views::Label::SetElideBehavior(...). See |
| 54 // crbug.com/532496. | 58 // crbug.com/532496. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 // Overridden from views::ButtonListener. | 122 // Overridden from views::ButtonListener. |
| 119 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 123 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 120 | 124 |
| 121 // The cast activity id that we are displaying. If the user stops a cast, we | 125 // The cast activity id that we are displaying. If the user stops a cast, we |
| 122 // send this value to the config delegate so that we stop the right cast. | 126 // send this value to the config delegate so that we stop the right cast. |
| 123 std::string displayed_activity_id_; | 127 std::string displayed_activity_id_; |
| 124 | 128 |
| 125 views::ImageView* icon_; | 129 views::ImageView* icon_; |
| 126 views::Label* label_; | 130 views::Label* label_; |
| 127 TrayPopupLabelButton* stop_button_; | 131 TrayPopupLabelButton* stop_button_; |
| 128 base::WeakPtrFactory<CastCastView> weak_ptr_factory_; | |
| 129 | 132 |
| 130 DISALLOW_COPY_AND_ASSIGN(CastCastView); | 133 DISALLOW_COPY_AND_ASSIGN(CastCastView); |
| 131 }; | 134 }; |
| 132 | 135 |
| 133 CastCastView::CastCastView() : weak_ptr_factory_(this) { | 136 CastCastView::CastCastView() { |
| 134 // We will initialize the primary tray view which shows a stop button here. | 137 // We will initialize the primary tray view which shows a stop button here. |
| 135 | 138 |
| 136 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 139 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 137 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 140 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 138 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 141 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
| 139 kTrayPopupPaddingHorizontal, 0, | 142 kTrayPopupPaddingHorizontal, 0, |
| 140 kTrayPopupPaddingBetweenItems)); | 143 kTrayPopupPaddingBetweenItems)); |
| 141 icon_ = new FixedSizedImageView(0, kTrayPopupItemHeight); | 144 icon_ = new FixedSizedImageView(0, kTrayPopupItemHeight); |
| 142 icon_->SetImage( | 145 icon_->SetImage( |
| 143 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAST_ENABLED).ToImageSkia()); | 146 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAST_ENABLED).ToImageSkia()); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 // Overridden from ViewClickListener. | 408 // Overridden from ViewClickListener. |
| 406 void OnViewClicked(views::View* sender) override; | 409 void OnViewClicked(views::View* sender) override; |
| 407 | 410 |
| 408 user::LoginStatus login_; | 411 user::LoginStatus login_; |
| 409 views::View* options_ = nullptr; | 412 views::View* options_ = nullptr; |
| 410 // A mapping from the receiver id to the receiver/activity data. | 413 // A mapping from the receiver id to the receiver/activity data. |
| 411 std::map<std::string, CastConfigDelegate::ReceiverAndActivity> | 414 std::map<std::string, CastConfigDelegate::ReceiverAndActivity> |
| 412 receivers_and_activities_; | 415 receivers_and_activities_; |
| 413 // A mapping from the view pointer to the associated activity id. | 416 // A mapping from the view pointer to the associated activity id. |
| 414 std::map<views::View*, std::string> receiver_activity_map_; | 417 std::map<views::View*, std::string> receiver_activity_map_; |
| 415 base::WeakPtrFactory<CastDetailedView> weak_ptr_factory_; | |
| 416 | 418 |
| 417 DISALLOW_COPY_AND_ASSIGN(CastDetailedView); | 419 DISALLOW_COPY_AND_ASSIGN(CastDetailedView); |
| 418 }; | 420 }; |
| 419 | 421 |
| 420 CastDetailedView::CastDetailedView( | 422 CastDetailedView::CastDetailedView( |
| 421 SystemTrayItem* owner, | 423 SystemTrayItem* owner, |
| 422 user::LoginStatus login, | 424 user::LoginStatus login, |
| 423 const CastConfigDelegate::ReceiversAndActivities& receivers_and_activities) | 425 const CastConfigDelegate::ReceiversAndActivities& receivers_and_activities) |
| 424 : TrayDetailsView(owner), login_(login), weak_ptr_factory_(this) { | 426 : TrayDetailsView(owner), login_(login) { |
| 425 CreateItems(); | 427 CreateItems(); |
| 426 UpdateReceiverList(receivers_and_activities); | 428 UpdateReceiverList(receivers_and_activities); |
| 427 } | 429 } |
| 428 | 430 |
| 429 CastDetailedView::~CastDetailedView() { | 431 CastDetailedView::~CastDetailedView() { |
| 430 } | 432 } |
| 431 | 433 |
| 432 void CastDetailedView::SimulateViewClickedForTest( | 434 void CastDetailedView::SimulateViewClickedForTest( |
| 433 const std::string& receiver_id) { | 435 const std::string& receiver_id) { |
| 434 for (auto& it : receiver_activity_map_) { | 436 for (auto& it : receiver_activity_map_) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 if (it != receiver_activity_map_.end()) { | 546 if (it != receiver_activity_map_.end()) { |
| 545 cast_config_delegate->CastToReceiver(it->second); | 547 cast_config_delegate->CastToReceiver(it->second); |
| 546 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 548 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 547 ash::UMA_STATUS_AREA_DETAILED_CAST_VIEW_LAUNCH_CAST); | 549 ash::UMA_STATUS_AREA_DETAILED_CAST_VIEW_LAUNCH_CAST); |
| 548 } | 550 } |
| 549 } | 551 } |
| 550 } | 552 } |
| 551 | 553 |
| 552 } // namespace tray | 554 } // namespace tray |
| 553 | 555 |
| 554 TrayCast::TrayCast(SystemTray* system_tray) | 556 TrayCast::TrayCast(SystemTray* system_tray) : SystemTrayItem(system_tray) { |
| 555 : SystemTrayItem(system_tray), | |
| 556 weak_ptr_factory_(this) { | |
| 557 Shell::GetInstance()->AddShellObserver(this); | 557 Shell::GetInstance()->AddShellObserver(this); |
| 558 } | 558 } |
| 559 | 559 |
| 560 TrayCast::~TrayCast() { | 560 TrayCast::~TrayCast() { |
| 561 Shell::GetInstance()->RemoveShellObserver(this); | 561 Shell::GetInstance()->RemoveShellObserver(this); |
| 562 | |
| 563 if (GetCastConfigDelegate()) | |
| 564 GetCastConfigDelegate()->RemoveObserver(this); | |
| 562 } | 565 } |
| 563 | 566 |
| 564 void TrayCast::StartCastForTest(const std::string& receiver_id) { | 567 void TrayCast::StartCastForTest(const std::string& receiver_id) { |
| 565 if (detailed_ != nullptr) | 568 if (detailed_ != nullptr) |
| 566 detailed_->SimulateViewClickedForTest(receiver_id); | 569 detailed_->SimulateViewClickedForTest(receiver_id); |
| 567 } | 570 } |
| 568 | 571 |
| 569 void TrayCast::StopCastForTest() { | 572 void TrayCast::StopCastForTest() { |
| 570 default_->cast_view()->StopCasting(); | 573 default_->cast_view()->StopCasting(); |
| 571 } | 574 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 590 | 593 |
| 591 if (HasCastExtension()) { | 594 if (HasCastExtension()) { |
| 592 ash::CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate(); | 595 ash::CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate(); |
| 593 | 596 |
| 594 // We add the cast listener here instead of in the ctor for two reasons: | 597 // We add the cast listener here instead of in the ctor for two reasons: |
| 595 // - The ctor gets called too early in the initialization cycle (at least | 598 // - The ctor gets called too early in the initialization cycle (at least |
| 596 // for the tests); the correct profile hasn't been setup yet. | 599 // for the tests); the correct profile hasn't been setup yet. |
| 597 // - The listener is only added if there is a cast extension. If the call | 600 // - The listener is only added if there is a cast extension. If the call |
| 598 // below were in the ctor, then the cast tray item would not appear if the | 601 // below were in the ctor, then the cast tray item would not appear if the |
| 599 // user installed the extension in an existing session. | 602 // user installed the extension in an existing session. |
| 600 if (!device_update_subscription_) { | 603 if (!added_observer_) { |
| 601 device_update_subscription_ = | 604 cast_config_delegate->AddObserver(this); |
| 602 cast_config_delegate->RegisterDeviceUpdateObserver(base::Bind( | 605 added_observer_ = true; |
| 603 &TrayCast::OnReceiversUpdated, weak_ptr_factory_.GetWeakPtr())); | |
| 604 } | 606 } |
| 605 | 607 |
| 606 // The extension updates its view model whenever the popup is opened, so we | 608 // The extension updates its view model whenever the popup is opened, so we |
| 607 // probably should as well. | 609 // probably should as well. |
| 608 cast_config_delegate->RequestDeviceRefresh(); | 610 cast_config_delegate->RequestDeviceRefresh(); |
| 609 } | 611 } |
| 610 | 612 |
| 611 default_ = new tray::CastDuplexView(this, status != user::LOGGED_IN_LOCKED, | 613 default_ = new tray::CastDuplexView(this, status != user::LOGGED_IN_LOCKED, |
| 612 receivers_and_activities_); | 614 receivers_and_activities_); |
| 613 default_->set_id(TRAY_VIEW); | 615 default_->set_id(TRAY_VIEW); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 638 void TrayCast::DestroyDetailedView() { | 640 void TrayCast::DestroyDetailedView() { |
| 639 detailed_ = nullptr; | 641 detailed_ = nullptr; |
| 640 } | 642 } |
| 641 | 643 |
| 642 bool TrayCast::HasCastExtension() { | 644 bool TrayCast::HasCastExtension() { |
| 643 ash::CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate(); | 645 ash::CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate(); |
| 644 return cast_config_delegate != nullptr && | 646 return cast_config_delegate != nullptr && |
| 645 cast_config_delegate->HasCastExtension(); | 647 cast_config_delegate->HasCastExtension(); |
| 646 } | 648 } |
| 647 | 649 |
| 648 void TrayCast::OnReceiversUpdated( | 650 void TrayCast::OnDevicesUpdated( |
| 649 const CastConfigDelegate::ReceiversAndActivities& receivers_activities) { | 651 const CastConfigDelegate::ReceiversAndActivities& receivers_activities) { |
| 650 receivers_and_activities_ = receivers_activities; | 652 receivers_and_activities_ = receivers_activities; |
| 651 | 653 |
| 652 if (default_) { | 654 if (default_) { |
| 653 bool has_receivers = !receivers_and_activities_.empty(); | 655 bool has_receivers = !receivers_and_activities_.empty(); |
| 654 default_->SetVisible(has_receivers); | 656 default_->SetVisible(has_receivers); |
| 655 default_->cast_view()->UpdateLabel(receivers_and_activities_); | 657 default_->cast_view()->UpdateLabel(receivers_and_activities_); |
| 656 } | 658 } |
| 657 if (detailed_) | 659 if (detailed_) |
| 658 detailed_->UpdateReceiverList(receivers_and_activities_); | 660 detailed_->UpdateReceiverList(receivers_and_activities_); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 681 is_casting_ = started; | 683 is_casting_ = started; |
| 682 UpdatePrimaryView(); | 684 UpdatePrimaryView(); |
| 683 } | 685 } |
| 684 | 686 |
| 685 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 687 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 686 if (tray_) | 688 if (tray_) |
| 687 tray_->UpdateAlignment(alignment); | 689 tray_->UpdateAlignment(alignment); |
| 688 } | 690 } |
| 689 | 691 |
| 690 } // namespace ash | 692 } // namespace ash |
| OLD | NEW |