Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: ash/system/cast/tray_cast.cc

Issue 2099443002: Migrate simple ash Shell metrics users. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix win compile error. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/shelf/shelf_view.cc ('k') | ash/system/chromeos/audio/tray_audio_chromeos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common/session/session_state_delegate.h" 7 #include "ash/common/session/session_state_delegate.h"
8 #include "ash/common/shelf/shelf_types.h" 8 #include "ash/common/shelf/shelf_types.h"
9 #include "ash/common/shelf/wm_shelf_util.h" 9 #include "ash/common/shelf/wm_shelf_util.h"
10 #include "ash/common/system/tray/fixed_sized_image_view.h" 10 #include "ash/common/system/tray/fixed_sized_image_view.h"
11 #include "ash/common/system/tray/fixed_sized_scroll_view.h" 11 #include "ash/common/system/tray/fixed_sized_scroll_view.h"
12 #include "ash/common/system/tray/hover_highlight_view.h" 12 #include "ash/common/system/tray/hover_highlight_view.h"
13 #include "ash/common/system/tray/system_tray_delegate.h" 13 #include "ash/common/system/tray/system_tray_delegate.h"
14 #include "ash/common/system/tray/throbber_view.h" 14 #include "ash/common/system/tray/throbber_view.h"
15 #include "ash/common/system/tray/tray_constants.h" 15 #include "ash/common/system/tray/tray_constants.h"
16 #include "ash/common/system/tray/tray_details_view.h" 16 #include "ash/common/system/tray/tray_details_view.h"
17 #include "ash/common/system/tray/tray_item_more.h" 17 #include "ash/common/system/tray/tray_item_more.h"
18 #include "ash/common/system/tray/tray_item_view.h" 18 #include "ash/common/system/tray/tray_item_view.h"
19 #include "ash/common/system/tray/tray_popup_label_button.h" 19 #include "ash/common/system/tray/tray_popup_label_button.h"
20 #include "ash/common/system/tray/view_click_listener.h" 20 #include "ash/common/system/tray/view_click_listener.h"
21 #include "ash/common/wm_shell.h" 21 #include "ash/common/wm_shell.h"
22 #include "ash/shelf/shelf_util.h" 22 #include "ash/shelf/shelf_util.h"
23 #include "ash/shell.h"
24 #include "ash/system/chromeos/screen_security/screen_tray_item.h" 23 #include "ash/system/chromeos/screen_security/screen_tray_item.h"
25 #include "ash/system/tray/system_tray.h" 24 #include "ash/system/tray/system_tray.h"
26 #include "ash/system/tray/system_tray_notifier.h" 25 #include "ash/system/tray/system_tray_notifier.h"
27 #include "base/bind.h" 26 #include "base/bind.h"
28 #include "grit/ash_resources.h" 27 #include "grit/ash_resources.h"
29 #include "grit/ash_strings.h" 28 #include "grit/ash_strings.h"
30 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
32 #include "ui/gfx/image/image.h" 31 #include "ui/gfx/image/image.h"
33 #include "ui/gfx/text_elider.h" 32 #include "ui/gfx/text_elider.h"
34 #include "ui/views/controls/button/button.h" 33 #include "ui/views/controls/button/button.h"
35 #include "ui/views/controls/image_view.h" 34 #include "ui/views/controls/image_view.h"
36 #include "ui/views/controls/label.h" 35 #include "ui/views/controls/label.h"
37 #include "ui/views/layout/box_layout.h" 36 #include "ui/views/layout/box_layout.h"
38 #include "ui/views/layout/fill_layout.h" 37 #include "ui/views/layout/fill_layout.h"
39 38
40 namespace ash { 39 namespace ash {
41 40
42 namespace { 41 namespace {
43 42
44 const size_t kMaximumStatusStringLength = 100; 43 const size_t kMaximumStatusStringLength = 100;
45 const int kStopButtonRightPadding = 18; 44 const int kStopButtonRightPadding = 18;
46 45
47 // Returns the active CastConfigDelegate instance. 46 // Returns the active CastConfigDelegate instance.
48 ash::CastConfigDelegate* GetCastConfigDelegate() { 47 CastConfigDelegate* GetCastConfigDelegate() {
49 return WmShell::Get()->system_tray_delegate()->GetCastConfigDelegate(); 48 return WmShell::Get()->system_tray_delegate()->GetCastConfigDelegate();
50 } 49 }
51 50
52 // Helper method to elide the given string to the maximum length. If a string is 51 // Helper method to elide the given string to the maximum length. If a string is
53 // contains user-input and is displayed, we should elide it. 52 // contains user-input and is displayed, we should elide it.
54 // TODO(jdufault): This does not properly trim unicode characters. We should 53 // TODO(jdufault): This does not properly trim unicode characters. We should
55 // implement this properly by using views::Label::SetElideBehavior(...). See 54 // implement this properly by using views::Label::SetElideBehavior(...). See
56 // crbug.com/532496. 55 // crbug.com/532496.
57 base::string16 ElideString(const base::string16& text) { 56 base::string16 ElideString(const base::string16& text) {
58 base::string16 elided; 57 base::string16 elided;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 if (label_->bounds().Intersects(stop_button_->bounds())) { 190 if (label_->bounds().Intersects(stop_button_->bounds())) {
192 gfx::Rect label_bounds = label_->bounds(); 191 gfx::Rect label_bounds = label_->bounds();
193 label_bounds.set_width(stop_button_->x() - kTrayPopupPaddingBetweenItems - 192 label_bounds.set_width(stop_button_->x() - kTrayPopupPaddingBetweenItems -
194 label_->x()); 193 label_->x());
195 label_->SetBoundsRect(label_bounds); 194 label_->SetBoundsRect(label_bounds);
196 } 195 }
197 } 196 }
198 197
199 void CastCastView::StopCasting() { 198 void CastCastView::StopCasting() {
200 GetCastConfigDelegate()->StopCasting(displayed_activity_id_); 199 GetCastConfigDelegate()->StopCasting(displayed_activity_id_);
201 Shell::GetInstance()->metrics()->RecordUserMetricsAction( 200 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_CAST_STOP_CAST);
202 ash::UMA_STATUS_AREA_CAST_STOP_CAST);
203 } 201 }
204 202
205 void CastCastView::UpdateLabel( 203 void CastCastView::UpdateLabel(
206 const CastConfigDelegate::ReceiversAndActivities& receivers_activities) { 204 const CastConfigDelegate::ReceiversAndActivities& receivers_activities) {
207 for (auto& i : receivers_activities) { 205 for (auto& i : receivers_activities) {
208 const CastConfigDelegate::Receiver& receiver = i.receiver; 206 const CastConfigDelegate::Receiver& receiver = i.receiver;
209 const CastConfigDelegate::Activity& activity = i.activity; 207 const CastConfigDelegate::Activity& activity = i.activity;
210 208
211 if (!activity.id.empty()) { 209 if (!activity.id.empty()) {
212 displayed_activity_id_ = activity.id; 210 displayed_activity_id_ = activity.id;
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 .ToImageSkia(); 493 .ToImageSkia();
496 const base::string16& name = receiverActivity.receiver.name; 494 const base::string16& name = receiverActivity.receiver.name;
497 container->AddIndentedIconAndLabel(*image, name, false); 495 container->AddIndentedIconAndLabel(*image, name, false);
498 496
499 scroll_content()->AddChildView(container); 497 scroll_content()->AddChildView(container);
500 return container; 498 return container;
501 } 499 }
502 500
503 void CastDetailedView::AppendSettingsEntries() { 501 void CastDetailedView::AppendSettingsEntries() {
504 // Settings requires a browser window, hide it for non logged in user. 502 // Settings requires a browser window, hide it for non logged in user.
505 const bool userAddingRunning = Shell::GetInstance()
506 ->session_state_delegate()
507 ->IsInSecondaryLoginScreen();
508
509 if (login_ == LoginStatus::NOT_LOGGED_IN || login_ == LoginStatus::LOCKED || 503 if (login_ == LoginStatus::NOT_LOGGED_IN || login_ == LoginStatus::LOCKED ||
510 userAddingRunning) 504 WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) {
511 return; 505 return;
506 }
512 507
513 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 508 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
514 HoverHighlightView* container = new HoverHighlightView(this); 509 HoverHighlightView* container = new HoverHighlightView(this);
515 container->AddLabel(rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_OPTIONS), 510 container->AddLabel(rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_OPTIONS),
516 gfx::ALIGN_LEFT, false /* highlight */); 511 gfx::ALIGN_LEFT, false /* highlight */);
517 512
518 AddChildView(container); 513 AddChildView(container);
519 options_ = container; 514 options_ = container;
520 } 515 }
521 516
522 void CastDetailedView::AppendHeaderEntry() { 517 void CastDetailedView::AppendHeaderEntry() {
523 CreateSpecialRow(IDS_ASH_STATUS_TRAY_CAST, this); 518 CreateSpecialRow(IDS_ASH_STATUS_TRAY_CAST, this);
524 } 519 }
525 520
526 void CastDetailedView::OnViewClicked(views::View* sender) { 521 void CastDetailedView::OnViewClicked(views::View* sender) {
527 ash::CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate(); 522 CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate();
528 523
529 if (sender == footer()->content()) { 524 if (sender == footer()->content()) {
530 TransitionToDefaultView(); 525 TransitionToDefaultView();
531 } else if (sender == options_) { 526 } else if (sender == options_) {
532 cast_config_delegate->LaunchCastOptions(); 527 cast_config_delegate->LaunchCastOptions();
533 } else { 528 } else {
534 // Find the receiver we are going to cast to 529 // Find the receiver we are going to cast to
535 auto it = receiver_activity_map_.find(sender); 530 auto it = receiver_activity_map_.find(sender);
536 if (it != receiver_activity_map_.end()) { 531 if (it != receiver_activity_map_.end()) {
537 cast_config_delegate->CastToReceiver(it->second); 532 cast_config_delegate->CastToReceiver(it->second);
538 Shell::GetInstance()->metrics()->RecordUserMetricsAction( 533 WmShell::Get()->RecordUserMetricsAction(
539 ash::UMA_STATUS_AREA_DETAILED_CAST_VIEW_LAUNCH_CAST); 534 UMA_STATUS_AREA_DETAILED_CAST_VIEW_LAUNCH_CAST);
540 } 535 }
541 } 536 }
542 } 537 }
543 538
544 } // namespace tray 539 } // namespace tray
545 540
546 TrayCast::TrayCast(SystemTray* system_tray) : SystemTrayItem(system_tray) { 541 TrayCast::TrayCast(SystemTray* system_tray) : SystemTrayItem(system_tray) {
547 WmShell::Get()->AddShellObserver(this); 542 WmShell::Get()->AddShellObserver(this);
548 } 543 }
549 544
(...skipping 24 matching lines...) Expand all
574 CHECK(tray_ == nullptr); 569 CHECK(tray_ == nullptr);
575 tray_ = new tray::CastTrayView(this); 570 tray_ = new tray::CastTrayView(this);
576 tray_->SetVisible(is_casting_); 571 tray_->SetVisible(is_casting_);
577 return tray_; 572 return tray_;
578 } 573 }
579 574
580 views::View* TrayCast::CreateDefaultView(LoginStatus status) { 575 views::View* TrayCast::CreateDefaultView(LoginStatus status) {
581 CHECK(default_ == nullptr); 576 CHECK(default_ == nullptr);
582 577
583 if (HasCastExtension()) { 578 if (HasCastExtension()) {
584 ash::CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate(); 579 CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate();
585 580
586 // Add the cast observer here instead of the ctor for two reasons: 581 // Add the cast observer here instead of the ctor for two reasons:
587 // - The ctor gets called too early in the initialization cycle (at least 582 // - The ctor gets called too early in the initialization cycle (at least
588 // for the tests); the correct profile hasn't been setup yet. 583 // for the tests); the correct profile hasn't been setup yet.
589 // - If we're using the cast extension backend (media router is disabled), 584 // - If we're using the cast extension backend (media router is disabled),
590 // then the user can install the extension at any point in time. The 585 // then the user can install the extension at any point in time. The
591 // return value of HasCastExtension() can change, so only checking it in 586 // return value of HasCastExtension() can change, so only checking it in
592 // the ctor isn't enough. 587 // the ctor isn't enough.
593 if (!added_observer_) { 588 if (!added_observer_) {
594 cast_config_delegate->AddObserver(this); 589 cast_config_delegate->AddObserver(this);
595 added_observer_ = true; 590 added_observer_ = true;
596 } 591 }
597 592
598 // The extension updates its view model whenever the popup is opened, so we 593 // The extension updates its view model whenever the popup is opened, so we
599 // probably should as well. 594 // probably should as well.
600 cast_config_delegate->RequestDeviceRefresh(); 595 cast_config_delegate->RequestDeviceRefresh();
601 } 596 }
602 597
603 default_ = new tray::CastDuplexView(this, status != LoginStatus::LOCKED, 598 default_ = new tray::CastDuplexView(this, status != LoginStatus::LOCKED,
604 receivers_and_activities_); 599 receivers_and_activities_);
605 default_->set_id(TRAY_VIEW); 600 default_->set_id(TRAY_VIEW);
606 default_->select_view()->set_id(SELECT_VIEW); 601 default_->select_view()->set_id(SELECT_VIEW);
607 default_->cast_view()->set_id(CAST_VIEW); 602 default_->cast_view()->set_id(CAST_VIEW);
608 603
609 UpdatePrimaryView(); 604 UpdatePrimaryView();
610 return default_; 605 return default_;
611 } 606 }
612 607
613 views::View* TrayCast::CreateDetailedView(LoginStatus status) { 608 views::View* TrayCast::CreateDetailedView(LoginStatus status) {
614 Shell::GetInstance()->metrics()->RecordUserMetricsAction( 609 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_DETAILED_CAST_VIEW);
615 ash::UMA_STATUS_AREA_DETAILED_CAST_VIEW);
616 CHECK(detailed_ == nullptr); 610 CHECK(detailed_ == nullptr);
617 detailed_ = 611 detailed_ =
618 new tray::CastDetailedView(this, status, receivers_and_activities_); 612 new tray::CastDetailedView(this, status, receivers_and_activities_);
619 return detailed_; 613 return detailed_;
620 } 614 }
621 615
622 void TrayCast::DestroyTrayView() { 616 void TrayCast::DestroyTrayView() {
623 tray_ = nullptr; 617 tray_ = nullptr;
624 } 618 }
625 619
626 void TrayCast::DestroyDefaultView() { 620 void TrayCast::DestroyDefaultView() {
627 default_ = nullptr; 621 default_ = nullptr;
628 } 622 }
629 623
630 void TrayCast::DestroyDetailedView() { 624 void TrayCast::DestroyDetailedView() {
631 detailed_ = nullptr; 625 detailed_ = nullptr;
632 } 626 }
633 627
634 bool TrayCast::HasCastExtension() { 628 bool TrayCast::HasCastExtension() {
635 ash::CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate(); 629 CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate();
636 return cast_config_delegate != nullptr && 630 return cast_config_delegate != nullptr &&
637 cast_config_delegate->HasCastExtension(); 631 cast_config_delegate->HasCastExtension();
638 } 632 }
639 633
640 void TrayCast::OnDevicesUpdated( 634 void TrayCast::OnDevicesUpdated(
641 const CastConfigDelegate::ReceiversAndActivities& receivers_activities) { 635 const CastConfigDelegate::ReceiversAndActivities& receivers_activities) {
642 receivers_and_activities_ = receivers_activities; 636 receivers_and_activities_ = receivers_activities;
643 637
644 if (default_) { 638 if (default_) {
645 bool has_receivers = !receivers_and_activities_.empty(); 639 bool has_receivers = !receivers_and_activities_.empty();
(...skipping 27 matching lines...) Expand all
673 is_casting_ = started; 667 is_casting_ = started;
674 UpdatePrimaryView(); 668 UpdatePrimaryView();
675 } 669 }
676 670
677 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { 671 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
678 if (tray_) 672 if (tray_)
679 tray_->UpdateAlignment(alignment); 673 tray_->UpdateAlignment(alignment);
680 } 674 }
681 675
682 } // namespace ash 676 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view.cc ('k') | ash/system/chromeos/audio/tray_audio_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698