Skip to content

Commit

Permalink
Remove ScopedVector from ash/.
Browse files Browse the repository at this point in the history
BUG=554289

Review-Url: https://codereview.chromium.org/2624363002
Cr-Commit-Position: refs/heads/master@{#444196}
  • Loading branch information
avi authored and Commit bot committed Jan 18, 2017
1 parent a26cf1f commit cca18e9
Show file tree
Hide file tree
Showing 24 changed files with 283 additions and 276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "ash/common/test/ash_test.h"
#include "ash/common/wm_shell.h"
#include "base/callback.h"
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
Expand Down Expand Up @@ -75,7 +76,7 @@ class ScreenCaptureTest : public ScreenTrayItemTest {
// This tray item is owned by its parent system tray view and will
// be deleted automatically when its parent is destroyed in AshTestBase.
ScreenTrayItem* item = new ScreenCaptureTrayItem(GetPrimarySystemTray());
GetPrimarySystemTray()->AddTrayItem(item);
GetPrimarySystemTray()->AddTrayItem(base::WrapUnique(item));
set_tray_item(item);
}

Expand All @@ -93,7 +94,7 @@ class ScreenShareTest : public ScreenTrayItemTest {
// This tray item is owned by its parent system tray view and will
// be deleted automatically when its parent is destroyed in AshTestBase.
ScreenTrayItem* item = new ScreenShareTrayItem(GetPrimarySystemTray());
GetPrimarySystemTray()->AddTrayItem(item);
GetPrimarySystemTray()->AddTrayItem(base::WrapUnique(item));
set_tray_item(item);
}

Expand Down Expand Up @@ -189,7 +190,7 @@ void TestSystemTrayInteraction(ScreenTrayItemTest* test) {
ScreenTrayItem* tray_item = test->tray_item();
EXPECT_FALSE(tray_item->tray_view()->visible());

const std::vector<SystemTrayItem*>& tray_items =
std::vector<SystemTrayItem*> tray_items =
AshTest::GetPrimarySystemTray()->GetTrayItems();
EXPECT_NE(std::find(tray_items.begin(), tray_items.end(), tray_item),
tray_items.end());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ash/common/system/tray/system_tray.h"
#include "ash/common/test/test_system_tray_delegate.h"
#include "ash/test/ash_test_base.h"
#include "base/memory/ptr_util.h"
#include "base/time/time.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/notification.h"
Expand All @@ -24,7 +25,7 @@ class TraySessionLengthLimitTest : public AshTestBase {
AshTestBase::SetUp();
SystemTray* system_tray = GetPrimarySystemTray();
tray_session_length_limit_ = new TraySessionLengthLimit(system_tray);
system_tray->AddTrayItem(tray_session_length_limit_);
system_tray->AddTrayItem(base::WrapUnique(tray_session_length_limit_));
}

void TearDown() override {
Expand Down
93 changes: 49 additions & 44 deletions ash/common/system/tray/system_tray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram.h"
#include "base/timer/timer.h"
#include "grit/ash_strings.h"
Expand Down Expand Up @@ -236,10 +237,8 @@ SystemTray::~SystemTray() {
key_event_watcher_.reset();
system_bubble_.reset();
notification_bubble_.reset();
for (std::vector<SystemTrayItem*>::iterator it = items_.begin();
it != items_.end(); ++it) {
(*it)->DestroyTrayView();
}
for (const auto& item : items_)
item->DestroyTrayView();
}

void SystemTray::InitializeTrayItems(
Expand All @@ -264,94 +263,100 @@ void SystemTray::CreateItems(SystemTrayDelegate* delegate) {
->GetSessionStateDelegate()
->GetMaximumNumberOfLoggedInUsers();
for (int i = 0; i < maximum_user_profiles; i++)
AddTrayItem(new TrayUser(this, i));
AddTrayItem(base::MakeUnique<TrayUser>(this, i));

// Crucially, this trailing padding has to be inside the user item(s).
// Otherwise it could be a main axis margin on the tray's box layout.
if (use_md)
AddTrayItem(new PaddingTrayItem());
AddTrayItem(base::MakeUnique<PaddingTrayItem>());

if (!use_md && maximum_user_profiles > 1) {
// Add a special double line separator between users and the rest of the
// menu if more than one user is logged in.
AddTrayItem(new TrayUserSeparator(this));
AddTrayItem(base::MakeUnique<TrayUserSeparator>(this));
}

tray_accessibility_ = new TrayAccessibility(this);
if (!use_md)
tray_date_ = new TrayDate(this);
tray_update_ = new TrayUpdate(this);

AddTrayItem(new TraySessionLengthLimit(this));
AddTrayItem(new TrayEnterprise(this));
AddTrayItem(new TraySupervisedUser(this));
AddTrayItem(new TrayIME(this));
AddTrayItem(tray_accessibility_);
AddTrayItem(new TrayTracing(this));
AddTrayItem(new TrayPower(this, message_center::MessageCenter::Get()));
AddTrayItem(base::MakeUnique<TraySessionLengthLimit>(this));
AddTrayItem(base::MakeUnique<TrayEnterprise>(this));
AddTrayItem(base::MakeUnique<TraySupervisedUser>(this));
AddTrayItem(base::MakeUnique<TrayIME>(this));
AddTrayItem(base::WrapUnique(tray_accessibility_));
AddTrayItem(base::MakeUnique<TrayTracing>(this));
AddTrayItem(
base::MakeUnique<TrayPower>(this, message_center::MessageCenter::Get()));
tray_network_ = new TrayNetwork(this);
AddTrayItem(tray_network_);
AddTrayItem(new TrayVPN(this));
AddTrayItem(new TraySms(this));
AddTrayItem(new TrayBluetooth(this));
AddTrayItem(base::WrapUnique(tray_network_));
AddTrayItem(base::MakeUnique<TrayVPN>(this));
AddTrayItem(base::MakeUnique<TraySms>(this));
AddTrayItem(base::MakeUnique<TrayBluetooth>(this));
tray_cast_ = new TrayCast(this);
AddTrayItem(tray_cast_);
AddTrayItem(base::WrapUnique(tray_cast_));
screen_capture_tray_item_ = new ScreenCaptureTrayItem(this);
AddTrayItem(screen_capture_tray_item_);
AddTrayItem(base::WrapUnique(screen_capture_tray_item_));
screen_share_tray_item_ = new ScreenShareTrayItem(this);
AddTrayItem(screen_share_tray_item_);
AddTrayItem(new MultiProfileMediaTrayItem(this));
AddTrayItem(base::WrapUnique(screen_share_tray_item_));
AddTrayItem(base::MakeUnique<MultiProfileMediaTrayItem>(this));
tray_audio_ = new TrayAudio(this);
AddTrayItem(tray_audio_);
AddTrayItem(new TrayBrightness(this));
AddTrayItem(new TrayCapsLock(this));
AddTrayItem(base::WrapUnique(tray_audio_));
AddTrayItem(base::MakeUnique<TrayBrightness>(this));
AddTrayItem(base::MakeUnique<TrayCapsLock>(this));
// TODO(jamescook): Remove this when mus has support for display management
// and we have a DisplayManager equivalent. See http://crbug.com/548429
std::unique_ptr<SystemTrayItem> tray_rotation_lock =
delegate->CreateRotationLockTrayItem(this);
if (tray_rotation_lock)
AddTrayItem(tray_rotation_lock.release());
AddTrayItem(std::move(tray_rotation_lock));
if (!use_md)
AddTrayItem(new TraySettings(this));
AddTrayItem(tray_update_);
AddTrayItem(base::MakeUnique<TraySettings>(this));
AddTrayItem(base::WrapUnique(tray_update_));
if (use_md) {
tray_tiles_ = new TrayTiles(this);
AddTrayItem(tray_tiles_);
AddTrayItem(base::WrapUnique(tray_tiles_));
tray_system_info_ = new TraySystemInfo(this);
AddTrayItem(tray_system_info_);
AddTrayItem(base::WrapUnique(tray_system_info_));
// Leading padding.
AddTrayItem(new PaddingTrayItem());
AddTrayItem(base::MakeUnique<PaddingTrayItem>());
} else {
AddTrayItem(tray_date_);
AddTrayItem(base::WrapUnique(tray_date_));
}
}

void SystemTray::AddTrayItem(SystemTrayItem* item) {
items_.push_back(item);
void SystemTray::AddTrayItem(std::unique_ptr<SystemTrayItem> item) {
SystemTrayItem* item_ptr = item.get();
items_.push_back(std::move(item));

SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
views::View* tray_item = item->CreateTrayView(delegate->GetUserLoginStatus());
item->UpdateAfterShelfAlignmentChange(shelf_alignment());
views::View* tray_item =
item_ptr->CreateTrayView(delegate->GetUserLoginStatus());
item_ptr->UpdateAfterShelfAlignmentChange(shelf_alignment());

if (tray_item) {
tray_container()->AddChildViewAt(tray_item, 0);
PreferredSizeChanged();
tray_item_map_[item] = tray_item;
tray_item_map_[item_ptr] = tray_item;
}
}

const std::vector<SystemTrayItem*>& SystemTray::GetTrayItems() const {
return items_.get();
std::vector<SystemTrayItem*> SystemTray::GetTrayItems() const {
std::vector<SystemTrayItem*> result;
for (const auto& item : items_)
result.push_back(item.get());
return result;
}

void SystemTray::ShowDefaultView(BubbleCreationType creation_type) {
if (creation_type != BUBBLE_USE_EXISTING)
WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_MENU_OPENED);
ShowItems(items_.get(), false, true, creation_type, false);
ShowItems(GetTrayItems(), false, true, creation_type, false);
}

void SystemTray::ShowPersistentDefaultView() {
ShowItems(items_.get(), false, false, BUBBLE_CREATE_NEW, true);
ShowItems(GetTrayItems(), false, false, BUBBLE_CREATE_NEW, true);
}

void SystemTray::ShowDetailedView(SystemTrayItem* item,
Expand Down Expand Up @@ -403,7 +408,7 @@ void SystemTray::ShowNotificationView(SystemTrayItem* item) {
}

void SystemTray::HideNotificationView(SystemTrayItem* item) {
std::vector<SystemTrayItem*>::iterator found_iter =
auto found_iter =
std::find(notification_items_.begin(), notification_items_.end(), item);
if (found_iter == notification_items_.end())
return;
Expand All @@ -417,7 +422,7 @@ void SystemTray::UpdateAfterLoginStatusChange(LoginStatus login_status) {
DestroySystemBubble();
UpdateNotificationBubble();

for (SystemTrayItem* item : items_)
for (const auto& item : items_)
item->UpdateAfterLoginStatusChange(login_status);

// Items default to SHELF_ALIGNMENT_BOTTOM. Update them if the initial
Expand All @@ -430,7 +435,7 @@ void SystemTray::UpdateAfterLoginStatusChange(LoginStatus login_status) {
}

void SystemTray::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
for (SystemTrayItem* item : items_)
for (const auto& item : items_)
item->UpdateAfterShelfAlignmentChange(alignment);
}

Expand Down
13 changes: 5 additions & 8 deletions ash/common/system/tray/system_tray.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "ash/common/system/tray/system_tray_bubble.h"
#include "ash/common/system/tray/tray_background_view.h"
#include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "ui/views/bubble/tray_bubble_view.h"
#include "ui/views/view.h"

Expand Down Expand Up @@ -57,11 +56,11 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView,
// Resets internal pointers. This has to be called before deletion.
void Shutdown();

// Adds a new item in the tray. Takes ownership.
void AddTrayItem(SystemTrayItem* item);
// Adds a new item in the tray.
void AddTrayItem(std::unique_ptr<SystemTrayItem> item);

// Returns all tray items that has been added to system tray.
const std::vector<SystemTrayItem*>& GetTrayItems() const;
std::vector<SystemTrayItem*> GetTrayItems() const;

// Shows the default view of all items.
void ShowDefaultView(BubbleCreationType creation_type);
Expand Down Expand Up @@ -228,16 +227,14 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView,
// and the percentage of the work area height covered by the system menu.
void RecordSystemMenuMetrics();

const ScopedVector<SystemTrayItem>& items() const { return items_; }

// Overridden from ActionableView.
bool PerformAction(const ui::Event& event) override;

// The web notification tray view that appears adjacent to this view.
WebNotificationTray* web_notification_tray_;

// Owned items.
ScopedVector<SystemTrayItem> items_;
// Items.
std::vector<std::unique_ptr<SystemTrayItem>> items_;

// Pointers to members of |items_|.
SystemTrayItem* detailed_item_;
Expand Down
Loading

0 comments on commit cca18e9

Please sign in to comment.