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