Commit 4c117ad5 authored by avi's avatar avi Committed by Commit bot

Remove ScopedVector from chrome/browser/ui.

BUG=554289

Review-Url: https://codereview.chromium.org/2606293002
Cr-Commit-Position: refs/heads/master@{#441435}
parent 96fd40ef
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
...@@ -116,7 +115,7 @@ class FakeWebContentsObserver : public content::WebContentsObserver { ...@@ -116,7 +115,7 @@ class FakeWebContentsObserver : public content::WebContentsObserver {
TEST_F(BrowserInstantControllerTest, DefaultSearchProviderChanged) { TEST_F(BrowserInstantControllerTest, DefaultSearchProviderChanged) {
size_t num_tests = arraysize(kTabReloadTestCasesFinalProviderNotGoogle); size_t num_tests = arraysize(kTabReloadTestCasesFinalProviderNotGoogle);
ScopedVector<FakeWebContentsObserver> observers; std::vector<std::unique_ptr<FakeWebContentsObserver>> observers;
for (size_t i = 0; i < num_tests; ++i) { for (size_t i = 0; i < num_tests; ++i) {
const TabReloadTestCase& test = const TabReloadTestCase& test =
kTabReloadTestCasesFinalProviderNotGoogle[i]; kTabReloadTestCasesFinalProviderNotGoogle[i];
...@@ -131,13 +130,13 @@ TEST_F(BrowserInstantControllerTest, DefaultSearchProviderChanged) { ...@@ -131,13 +130,13 @@ TEST_F(BrowserInstantControllerTest, DefaultSearchProviderChanged) {
<< test.description; << test.description;
// Setup an observer to verify reload or absence thereof. // Setup an observer to verify reload or absence thereof.
observers.push_back(new FakeWebContentsObserver(contents)); observers.push_back(base::MakeUnique<FakeWebContentsObserver>(contents));
} }
SetUserSelectedDefaultSearchProvider("https://bar.com/"); SetUserSelectedDefaultSearchProvider("https://bar.com/");
for (size_t i = 0; i < num_tests; ++i) { for (size_t i = 0; i < num_tests; ++i) {
FakeWebContentsObserver* observer = observers[i]; FakeWebContentsObserver* observer = observers[i].get();
const TabReloadTestCase& test = const TabReloadTestCase& test =
kTabReloadTestCasesFinalProviderNotGoogle[i]; kTabReloadTestCasesFinalProviderNotGoogle[i];
...@@ -164,7 +163,7 @@ TEST_F(BrowserInstantControllerTest, DefaultSearchProviderChanged) { ...@@ -164,7 +163,7 @@ TEST_F(BrowserInstantControllerTest, DefaultSearchProviderChanged) {
TEST_F(BrowserInstantControllerTest, GoogleBaseURLUpdated) { TEST_F(BrowserInstantControllerTest, GoogleBaseURLUpdated) {
const size_t num_tests = arraysize(kTabReloadTestCasesFinalProviderGoogle); const size_t num_tests = arraysize(kTabReloadTestCasesFinalProviderGoogle);
ScopedVector<FakeWebContentsObserver> observers; std::vector<std::unique_ptr<FakeWebContentsObserver>> observers;
for (size_t i = 0; i < num_tests; ++i) { for (size_t i = 0; i < num_tests; ++i) {
const TabReloadTestCase& test = kTabReloadTestCasesFinalProviderGoogle[i]; const TabReloadTestCase& test = kTabReloadTestCasesFinalProviderGoogle[i];
AddTab(browser(), GURL(test.start_url)); AddTab(browser(), GURL(test.start_url));
...@@ -178,14 +177,14 @@ TEST_F(BrowserInstantControllerTest, GoogleBaseURLUpdated) { ...@@ -178,14 +177,14 @@ TEST_F(BrowserInstantControllerTest, GoogleBaseURLUpdated) {
<< test.description; << test.description;
// Setup an observer to verify reload or absence thereof. // Setup an observer to verify reload or absence thereof.
observers.push_back(new FakeWebContentsObserver(contents)); observers.push_back(base::MakeUnique<FakeWebContentsObserver>(contents));
} }
NotifyGoogleBaseURLUpdate("https://www.google.es/"); NotifyGoogleBaseURLUpdate("https://www.google.es/");
for (size_t i = 0; i < num_tests; ++i) { for (size_t i = 0; i < num_tests; ++i) {
const TabReloadTestCase& test = kTabReloadTestCasesFinalProviderGoogle[i]; const TabReloadTestCase& test = kTabReloadTestCasesFinalProviderGoogle[i];
FakeWebContentsObserver* observer = observers[i]; FakeWebContentsObserver* observer = observers[i].get();
// Validate final instant state. // Validate final instant state.
EXPECT_EQ(test.end_in_instant_process, EXPECT_EQ(test.end_in_instant_process,
......
...@@ -8,8 +8,9 @@ ...@@ -8,8 +8,9 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#include <memory> #include <memory>
#include <vector>
#include "base/memory/scoped_vector.h" #include "base/logging.h"
class Column; class Column;
class ColumnSet; class ColumnSet;
...@@ -87,15 +88,15 @@ class SimpleGridLayout { ...@@ -87,15 +88,15 @@ class SimpleGridLayout {
private: private:
// Adds a new row, updating associated counters and positions. // Adds a new row, updating associated counters and positions.
void AddRow(Row* row); void AddRow(std::unique_ptr<Row> row);
// Next column in the current ColumnSet. // Next column in the current ColumnSet.
int next_column_; int next_column_;
int current_auto_id_; // Starting value for autogenerated columnset ids. int current_auto_id_; // Starting value for autogenerated columnset ids.
ScopedVector<ViewState> view_states_; std::vector<std::unique_ptr<ViewState>> view_states_;
ScopedVector<ColumnSet> column_sets_; std::vector<std::unique_ptr<ColumnSet>> column_sets_;
ScopedVector<Row> rows_; std::vector<std::unique_ptr<Row>> rows_;
NSView* host_; NSView* host_;
}; };
...@@ -124,7 +125,7 @@ class ColumnSet { ...@@ -124,7 +125,7 @@ class ColumnSet {
Column* GetColumn(int column_index) { Column* GetColumn(int column_index) {
DCHECK(column_index >=0 && column_index < num_columns()); DCHECK(column_index >=0 && column_index < num_columns());
return columns_[column_index]; return columns_[column_index].get();
} }
// These functions are mostly for testing & deviate from Views Layout class. // These functions are mostly for testing & deviate from Views Layout class.
...@@ -134,7 +135,7 @@ class ColumnSet { ...@@ -134,7 +135,7 @@ class ColumnSet {
float CalculateRemainingWidth(float width); float CalculateRemainingWidth(float width);
void DistributeRemainingWidth(float width); void DistributeRemainingWidth(float width);
ScopedVector<Column> columns_; std::vector<std::unique_ptr<Column>> columns_;
int id_; int id_;
}; };
......
...@@ -8,8 +8,7 @@ ...@@ -8,8 +8,7 @@
#include <algorithm> #include <algorithm>
#include "base/logging.h" #include "base/memory/ptr_util.h"
#include "base/stl_util.h"
namespace { namespace {
const int kAutoColumnIdStart = 1000000; // Starting ID for autogeneration. const int kAutoColumnIdStart = 1000000; // Starting ID for autogeneration.
...@@ -47,22 +46,20 @@ class LayoutElement { ...@@ -47,22 +46,20 @@ class LayoutElement {
virtual ~LayoutElement() {} virtual ~LayoutElement() {}
template <class T> template <class T>
static void ResetSizes(ScopedVector<T>* elements) { static void ResetSizes(std::vector<std::unique_ptr<T>>* elements) {
// Reset the layout width of each column. // Reset the layout width of each column.
for (typename std::vector<T*>::iterator i = elements->begin(); for (const auto& element : *elements)
i != elements->end(); ++i) { element->ResetSize();
(*i)->ResetSize();
}
} }
template <class T> template <class T>
static void CalculateLocationsFromSize(ScopedVector<T>* elements) { static void CalculateLocationsFromSize(
std::vector<std::unique_ptr<T>>* elements) {
// Reset the layout width of each column. // Reset the layout width of each column.
int location = 0; int location = 0;
for (typename std::vector<T*>::iterator i = elements->begin(); for (const auto& element : *elements) {
i != elements->end(); ++i) { element->SetLocation(location);
(*i)->SetLocation(location); location += element->Size();
location += (*i)->Size();
} }
} }
...@@ -164,15 +161,15 @@ ColumnSet::~ColumnSet() { ...@@ -164,15 +161,15 @@ ColumnSet::~ColumnSet() {
} }
void ColumnSet::AddPaddingColumn(int fixed_width) { void ColumnSet::AddPaddingColumn(int fixed_width) {
columns_.push_back(new Column(0.0f, fixed_width, true)); columns_.push_back(base::MakeUnique<Column>(0.0f, fixed_width, true));
} }
void ColumnSet::AddColumn(float resize_percent) { void ColumnSet::AddColumn(float resize_percent) {
columns_.push_back(new Column(resize_percent, 0, false)); columns_.push_back(base::MakeUnique<Column>(resize_percent, 0, false));
} }
void ColumnSet::CalculateSize(float width) { void ColumnSet::CalculateSize(float width) {
// Reset column widths // Reset column widths.
LayoutElement::ResetSizes(&columns_); LayoutElement::ResetSizes(&columns_);
width = CalculateRemainingWidth(width); width = CalculateRemainingWidth(width);
DistributeRemainingWidth(width); DistributeRemainingWidth(width);
...@@ -183,8 +180,8 @@ void ColumnSet::ResetColumnXCoordinates() { ...@@ -183,8 +180,8 @@ void ColumnSet::ResetColumnXCoordinates() {
} }
float ColumnSet::CalculateRemainingWidth(float width) { float ColumnSet::CalculateRemainingWidth(float width) {
for (size_t i = 0; i < columns_.size(); ++i) for (const auto& column : columns_)
width -= columns_[i]->Size(); width -= column->Size();
return width; return width;
} }
...@@ -193,20 +190,21 @@ void ColumnSet::DistributeRemainingWidth(float width) { ...@@ -193,20 +190,21 @@ void ColumnSet::DistributeRemainingWidth(float width) {
float total_resize = 0.0f; float total_resize = 0.0f;
int resizable_columns = 0.0; int resizable_columns = 0.0;
for (size_t i = 0; i < columns_.size(); ++i) { for (const auto& column : columns_) {
if (columns_[i]->IsResizable()) { if (column->IsResizable()) {
total_resize += columns_[i]->ResizePercent(); total_resize += column->ResizePercent();
resizable_columns++; resizable_columns++;
} }
} }
float remaining_width = width; float remaining_width = width;
for (size_t i = 0; i < columns_.size(); ++i) { for (const auto& column : columns_) {
if (columns_[i]->IsResizable()) { if (column->IsResizable()) {
float delta = (resizable_columns == 0) ? remaining_width : float delta = (resizable_columns == 0)
(width * columns_[i]->ResizePercent() / total_resize); ? remaining_width
: (width * column->ResizePercent() / total_resize);
remaining_width -= delta; remaining_width -= delta;
columns_[i]->SetSize(columns_[i]->Size() + delta); column->SetSize(column->Size() + delta);
resizable_columns--; resizable_columns--;
} }
} }
...@@ -235,35 +233,33 @@ SimpleGridLayout::~SimpleGridLayout() { ...@@ -235,35 +233,33 @@ SimpleGridLayout::~SimpleGridLayout() {
} }
ColumnSet* SimpleGridLayout::AddColumnSet(int id) { ColumnSet* SimpleGridLayout::AddColumnSet(int id) {
DCHECK(GetColumnSet(id) == NULL); DCHECK(GetColumnSet(id) == nullptr);
ColumnSet* column_set = new ColumnSet(id); column_sets_.push_back(base::MakeUnique<ColumnSet>(id));
column_sets_.push_back(column_set); return column_sets_.back().get();
return column_set;
} }
ColumnSet* SimpleGridLayout::GetColumnSet(int id) { ColumnSet* SimpleGridLayout::GetColumnSet(int id) {
for (ScopedVector<ColumnSet>::const_iterator i = column_sets_.begin(); for (const auto& column_set : column_sets_) {
i != column_sets_.end(); ++i) { if (column_set->id() == id) {
if ((*i)->id() == id) { return column_set.get();
return *i;
} }
} }
return NULL; return nullptr;
} }
void SimpleGridLayout::AddPaddingRow(int fixed_height) { void SimpleGridLayout::AddPaddingRow(int fixed_height) {
AddRow(new Row(0.0f, fixed_height, NULL)); AddRow(base::MakeUnique<Row>(0.0f, fixed_height, nullptr));
} }
void SimpleGridLayout::StartRow(float vertical_resize, int column_set_id) { void SimpleGridLayout::StartRow(float vertical_resize, int column_set_id) {
ColumnSet* column_set = GetColumnSet(column_set_id); ColumnSet* column_set = GetColumnSet(column_set_id);
DCHECK(column_set); DCHECK(column_set);
AddRow(new Row(vertical_resize, 0, column_set)); AddRow(base::MakeUnique<Row>(vertical_resize, 0, column_set));
} }
ColumnSet* SimpleGridLayout::AddRow() { ColumnSet* SimpleGridLayout::AddRow() {
AddRow(new Row(0, 0, AddColumnSet(current_auto_id_++))); AddRow(base::MakeUnique<Row>(0, 0, AddColumnSet(current_auto_id_++)));
return column_sets_.back(); return column_sets_.back().get();
} }
void SimpleGridLayout::SkipColumns(int col_count) { void SimpleGridLayout::SkipColumns(int col_count) {
...@@ -278,20 +274,15 @@ void SimpleGridLayout::SkipColumns(int col_count) { ...@@ -278,20 +274,15 @@ void SimpleGridLayout::SkipColumns(int col_count) {
void SimpleGridLayout::AddView(NSView* view) { void SimpleGridLayout::AddView(NSView* view) {
[host_ addSubview:view]; [host_ addSubview:view];
DCHECK(next_column_ < GetLastValidColumnSet()->num_columns()); DCHECK(next_column_ < GetLastValidColumnSet()->num_columns());
view_states_.push_back( view_states_.push_back(base::MakeUnique<ViewState>(
new ViewState(view, view, GetLastValidColumnSet(), rows_.size() - 1, next_column_++));
GetLastValidColumnSet(),
rows_.size() - 1,
next_column_++));
SkipPaddingColumns(); SkipPaddingColumns();
} }
// Sizes elements to fit into the superViews bounds, according to constraints. // Sizes elements to fit into the superViews bounds, according to constraints.
void SimpleGridLayout::Layout(NSView* superView) { void SimpleGridLayout::Layout(NSView* superView) {
SizeRowsAndColumns(NSWidth([superView bounds])); SizeRowsAndColumns(NSWidth([superView bounds]));
for (std::vector<ViewState*>::iterator i = view_states_.begin(); for (const auto& view_state : view_states_) {
i != view_states_.end(); ++i) {
ViewState* view_state = *i;
NSView* view = view_state->view(); NSView* view = view_state->view();
NSRect frame = NSMakeRect(view_state->GetColumn()->Location(), NSRect frame = NSMakeRect(view_state->GetColumn()->Location(),
rows_[view_state->row_index()]->Location(), rows_[view_state->row_index()]->Location(),
...@@ -303,20 +294,16 @@ void SimpleGridLayout::Layout(NSView* superView) { ...@@ -303,20 +294,16 @@ void SimpleGridLayout::Layout(NSView* superView) {
void SimpleGridLayout::SizeRowsAndColumns(float width) { void SimpleGridLayout::SizeRowsAndColumns(float width) {
// Size all columns first. // Size all columns first.
for (ScopedVector<ColumnSet>::iterator i = column_sets_.begin(); for (const auto& column_set : column_sets_) {
i != column_sets_.end(); ++i) { column_set->CalculateSize(width);
(*i)->CalculateSize(width); column_set->ResetColumnXCoordinates();
(*i)->ResetColumnXCoordinates();
} }
// Reset the height of each row. // Reset the height of each row.
LayoutElement::ResetSizes(&rows_); LayoutElement::ResetSizes(&rows_);
// For each ViewState, obtain the preferred height // For each ViewState, obtain the preferred height
for (std::vector<ViewState*>::iterator i= view_states_.begin(); for (const auto& view_state : view_states_) {
i != view_states_.end() ; ++i) {
ViewState* view_state = *i;
// The view is resizable. As the pref height may vary with the width, // The view is resizable. As the pref height may vary with the width,
// ask for the pref again. // ask for the pref again.
int actual_width = view_state->GetColumnWidth(); int actual_width = view_state->GetColumnWidth();
...@@ -329,10 +316,8 @@ void SimpleGridLayout::SizeRowsAndColumns(float width) { ...@@ -329,10 +316,8 @@ void SimpleGridLayout::SizeRowsAndColumns(float width) {
// Make sure each row can accommodate all contained ViewStates. // Make sure each row can accommodate all contained ViewStates.
std::vector<ViewState*>::iterator view_states_iterator = view_states_.begin(); for (const auto& view_state : view_states_) {
for (; view_states_iterator != view_states_.end(); ++view_states_iterator) { Row* row = rows_[view_state->row_index()].get();
ViewState* view_state = *view_states_iterator;
Row* row = rows_[view_state->row_index()];
row->AdjustSize(view_state->preferred_height()); row->AdjustSize(view_state->preferred_height());
} }
...@@ -353,7 +338,7 @@ ColumnSet* SimpleGridLayout::GetLastValidColumnSet() { ...@@ -353,7 +338,7 @@ ColumnSet* SimpleGridLayout::GetLastValidColumnSet() {
if (rows_[i]->column_set()) if (rows_[i]->column_set())
return rows_[i]->column_set(); return rows_[i]->column_set();
} }
return NULL; return nullptr;
} }
float SimpleGridLayout::GetRowHeight(int row_index) { float SimpleGridLayout::GetRowHeight(int row_index) {
...@@ -376,8 +361,8 @@ float SimpleGridLayout::GetPreferredHeightForWidth(float width) { ...@@ -376,8 +361,8 @@ float SimpleGridLayout::GetPreferredHeightForWidth(float width) {
return rows_.back()->Location() + rows_.back()->Size(); return rows_.back()->Location() + rows_.back()->Size();
} }
void SimpleGridLayout::AddRow(Row* row) { void SimpleGridLayout::AddRow(std::unique_ptr<Row> row) {
next_column_ = 0; next_column_ = 0;
rows_.push_back(row); rows_.push_back(std::move(row));
} }
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <Cocoa/Cocoa.h> #include <Cocoa/Cocoa.h>
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_vector.h"
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
class AccountAvatarFetcherBridge; class AccountAvatarFetcherBridge;
...@@ -17,7 +16,7 @@ class GURL; ...@@ -17,7 +16,7 @@ class GURL;
// Handles retrieving avatar images for credential items. // Handles retrieving avatar images for credential items.
@interface AccountAvatarFetcherManager : NSObject { @interface AccountAvatarFetcherManager : NSObject {
ScopedVector<AccountAvatarFetcherBridge> bridges_; std::vector<std::unique_ptr<AccountAvatarFetcherBridge>> bridges_;
scoped_refptr<net::URLRequestContextGetter> requestContext_; scoped_refptr<net::URLRequestContextGetter> requestContext_;
} }
......
...@@ -79,9 +79,12 @@ void AccountAvatarFetcherBridge::UpdateAvatar(const gfx::ImageSkia& image) { ...@@ -79,9 +79,12 @@ void AccountAvatarFetcherBridge::UpdateAvatar(const gfx::ImageSkia& image) {
fromBridge:(AccountAvatarFetcherBridge*)bridge fromBridge:(AccountAvatarFetcherBridge*)bridge
forView:(CredentialItemButton*)view { forView:(CredentialItemButton*)view {
[view setImage:image]; [view setImage:image];
auto it = std::find(bridges_.begin(), bridges_.end(), bridge); for (auto it = bridges_.begin(); it != bridges_.end(); it++) {
if (it != bridges_.end()) if (it->get() == bridge) {
bridges_.erase(it); bridges_.erase(it);
return;
}
}
} }
@end @end
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
#include <set>
#include <utility> #include <utility>
#include "base/auto_reset.h" #include "base/auto_reset.h"
...@@ -54,8 +55,8 @@ enum DimensionType { WIDTH, HEIGHT }; ...@@ -54,8 +55,8 @@ enum DimensionType { WIDTH, HEIGHT };
// |FunctionType| should equate to (something similar to) // |FunctionType| should equate to (something similar to)
// bool Equal(const Type1&, const Type2&), but we can't enforce this // bool Equal(const Type1&, const Type2&), but we can't enforce this
// because of MSVC compilation limitations. // because of MSVC compilation limitations.
template<typename Type1, typename Type2, typename FunctionType> template <typename Type1, typename Type2, typename FunctionType>
void SortContainer(std::vector<Type1>* to_sort, void SortContainer(std::vector<std::unique_ptr<Type1>>* to_sort,
const std::vector<Type2>& reference, const std::vector<Type2>& reference,
FunctionType equal) { FunctionType equal) {
CHECK_GE(to_sort->size(), reference.size()) << CHECK_GE(to_sort->size(), reference.size()) <<
...@@ -65,11 +66,11 @@ void SortContainer(std::vector<Type1>* to_sort, ...@@ -65,11 +66,11 @@ void SortContainer(std::vector<Type1>* to_sort,
// Run through the each element and compare it to the reference. If something // Run through the each element and compare it to the reference. If something
// is out of place, find the correct spot for it. // is out of place, find the correct spot for it.
for (size_t i = 0; i < reference.size() - 1; ++i) { for (size_t i = 0; i < reference.size() - 1; ++i) {
if (!equal(to_sort->at(i), reference[i])) { if (!equal(to_sort->at(i).get(), reference[i])) {
// Find the correct index (it's guaranteed to be after our current // Find the correct index (it's guaranteed to be after our current
// index, since everything up to this point is correct), and swap. // index, since everything up to this point is correct), and swap.
size_t j = i + 1; size_t j = i + 1;
while (!equal(to_sort->at(j), reference[i])) { while (!equal(to_sort->at(j).get(), reference[i])) {
++j; ++j;
DCHECK_LT(j, to_sort->size()) << DCHECK_LT(j, to_sort->size()) <<
"Item in |reference| not found in |to_sort|."; "Item in |reference| not found in |to_sort|.";
...@@ -210,10 +211,12 @@ size_t ToolbarActionsBar::GetIconCount() const { ...@@ -210,10 +211,12 @@ size_t ToolbarActionsBar::GetIconCount() const {
// If there is a popped out action, it could affect the number of visible // If there is a popped out action, it could affect the number of visible
// icons - but only if it wouldn't otherwise be visible. // icons - but only if it wouldn't otherwise be visible.
if (popped_out_action_) { if (popped_out_action_) {
size_t popped_out_index = size_t popped_out_index = 0;
std::find(toolbar_actions_.begin(), for (; popped_out_index < toolbar_actions_.size(); ++popped_out_index) {
toolbar_actions_.end(), if (toolbar_actions_[popped_out_index].get() == popped_out_action_)
popped_out_action_) - toolbar_actions_.begin(); break;
}
pop_out_modifier = popped_out_index >= model_->visible_icon_count() ? 1 : 0; pop_out_modifier = popped_out_index >= model_->visible_icon_count() ? 1 : 0;
} }
...@@ -294,7 +297,9 @@ gfx::Rect ToolbarActionsBar::GetFrameForIndex( ...@@ -294,7 +297,9 @@ gfx::Rect ToolbarActionsBar::GetFrameForIndex(
std::vector<ToolbarActionViewController*> std::vector<ToolbarActionViewController*>
ToolbarActionsBar::GetActions() const { ToolbarActionsBar::GetActions() const {
std::vector<ToolbarActionViewController*> actions = toolbar_actions_.get(); std::vector<ToolbarActionViewController*> actions;
for (const auto& action : toolbar_actions_)
actions.push_back(action.get());
// If there is an action that should be popped out, and it's not visible by // If there is an action that should be popped out, and it's not visible by
// default, make it the final action in the list. // default, make it the final action in the list.
...@@ -352,7 +357,7 @@ void ToolbarActionsBar::CreateActions() { ...@@ -352,7 +357,7 @@ void ToolbarActionsBar::CreateActions() {
FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions4")); FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions4"));
for (size_t i = 0; i < toolbar_actions_.size(); ++i) for (size_t i = 0; i < toolbar_actions_.size(); ++i)
delegate_->AddViewForAction(toolbar_actions_[i], i); delegate_->AddViewForAction(toolbar_actions_[i].get(), i);
} }
// Once the actions are created, we should animate the changes. // Once the actions are created, we should animate the changes.
...@@ -385,7 +390,7 @@ void ToolbarActionsBar::Update() { ...@@ -385,7 +390,7 @@ void ToolbarActionsBar::Update() {
{ {
// Don't layout until the end. // Don't layout until the end.
base::AutoReset<bool> layout_resetter(&suppress_layout_, true); base::AutoReset<bool> layout_resetter(&suppress_layout_, true);
for (ToolbarActionViewController* action : toolbar_actions_) for (const auto& action : toolbar_actions_)
action->UpdateState(); action->UpdateState();
} }
...@@ -483,10 +488,15 @@ bool ToolbarActionsBar::IsActionVisibleOnMainBar( ...@@ -483,10 +488,15 @@ bool ToolbarActionsBar::IsActionVisibleOnMainBar(
if (in_overflow_mode()) if (in_overflow_mode())
return main_bar_->IsActionVisibleOnMainBar(action); return main_bar_->IsActionVisibleOnMainBar(action);
size_t index = std::find(toolbar_actions_.begin(), if (action == popped_out_action_)
toolbar_actions_.end(), return true;
action) - toolbar_actions_.begin();
return index < GetIconCount() || action == popped_out_action_; size_t visible_icon_count = std::min(toolbar_actions_.size(), GetIconCount());
for (size_t index = 0; index < visible_icon_count; ++index)
if (toolbar_actions_[index].get() == action)
return true;
return false;
} }
void ToolbarActionsBar::PopOutAction(ToolbarActionViewController* controller, void ToolbarActionsBar::PopOutAction(ToolbarActionViewController* controller,
...@@ -620,7 +630,7 @@ void ToolbarActionsBar::OnToolbarActionAdded( ...@@ -620,7 +630,7 @@ void ToolbarActionsBar::OnToolbarActionAdded(
toolbar_actions_.insert(toolbar_actions_.begin() + index, toolbar_actions_.insert(toolbar_actions_.begin() + index,
model_->CreateActionForItem(browser_, this, item)); model_->CreateActionForItem(browser_, this, item));
delegate_->AddViewForAction(toolbar_actions_[index], index); delegate_->AddViewForAction(toolbar_actions_[index].get(), index);
// We may need to resize (e.g. to show the new icon, or the chevron). We don't // We may need to resize (e.g. to show the new icon, or the chevron). We don't
// need to check if an extension is upgrading here, because ResizeDelegate() // need to check if an extension is upgrading here, because ResizeDelegate()
...@@ -644,8 +654,9 @@ void ToolbarActionsBar::OnToolbarActionRemoved(const std::string& action_id) { ...@@ -644,8 +654,9 @@ void ToolbarActionsBar::OnToolbarActionRemoved(const std::string& action_id) {
// The action should outlive the UI element (which is owned by the delegate), // The action should outlive the UI element (which is owned by the delegate),
// so we can't delete it just yet. But we should remove it from the list of // so we can't delete it just yet. But we should remove it from the list of
// actions so that any width calculations are correct. // actions so that any width calculations are correct.
std::unique_ptr<ToolbarActionViewController> removed_action(*iter); std::unique_ptr<ToolbarActionViewController> removed_action =
toolbar_actions_.weak_erase(iter); std::move(*iter);
toolbar_actions_.erase(iter);
delegate_->RemoveViewForAction(removed_action.get()); delegate_->RemoveViewForAction(removed_action.get());
if (popped_out_action_ == removed_action.get()) if (popped_out_action_ == removed_action.get())
UndoPopOut(); UndoPopOut();
...@@ -726,27 +737,30 @@ void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) { ...@@ -726,27 +737,30 @@ void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) {
{ {
base::AutoReset<bool> layout_resetter(&suppress_layout_, true); base::AutoReset<bool> layout_resetter(&suppress_layout_, true);
base::AutoReset<bool> animation_resetter(&suppress_animation_, true); base::AutoReset<bool> animation_resetter(&suppress_animation_, true);
std::set<std::string> seen; std::set<std::string> model_item_ids;
for (const ToolbarActionsModel::ToolbarItem item : for (const auto& model_item : model_->toolbar_items()) {
model_->toolbar_items()) { model_item_ids.insert(model_item.id);
auto current_pos =
std::find_if(toolbar_actions_.begin(), toolbar_actions_.end(), bool found = false;
[&item](const ToolbarActionViewController* action) { for (size_t i = 0; i < toolbar_actions_.size(); ++i) {
return action->GetId() == item.id; if (toolbar_actions_[i]->GetId() == model_item.id) {
}); found = true;
if (current_pos == toolbar_actions_.end()) { break;
}
}
if (!found) {
toolbar_actions_.push_back( toolbar_actions_.push_back(
model_->CreateActionForItem(browser_, this, item).release()); model_->CreateActionForItem(browser_, this, model_item));
delegate_->AddViewForAction(toolbar_actions_.back(), delegate_->AddViewForAction(toolbar_actions_.back().get(),
toolbar_actions_.size() - 1); toolbar_actions_.size() - 1);
} }
seen.insert(item.id);
} }
for (ToolbarActions::iterator iter = toolbar_actions_.begin(); for (auto iter = toolbar_actions_.begin();
iter != toolbar_actions_.end();) { iter != toolbar_actions_.end();) {
if (seen.count((*iter)->GetId()) == 0) { if (model_item_ids.count((*iter)->GetId()) == 0) {
delegate_->RemoveViewForAction(*iter); delegate_->RemoveViewForAction(iter->get());
iter = toolbar_actions_.erase(iter); iter = toolbar_actions_.erase(iter);
} else { } else {
++iter; ++iter;
...@@ -787,7 +801,7 @@ void ToolbarActionsBar::ReorderActions() { ...@@ -787,7 +801,7 @@ void ToolbarActionsBar::ReorderActions() {
const ToolbarActionsModel::ToolbarItem& item) { const ToolbarActionsModel::ToolbarItem& item) {
return action->GetId() == item.id; return action->GetId() == item.id;
}; };
SortContainer(&toolbar_actions_.get(), model_->toolbar_items(), compare); SortContainer(&toolbar_actions_, model_->toolbar_items(), compare);
// Our visible browser actions may have changed - re-Layout() and check the // Our visible browser actions may have changed - re-Layout() and check the
// size (if we aren't suppressing the layout). // size (if we aren't suppressing the layout).
...@@ -799,9 +813,9 @@ void ToolbarActionsBar::ReorderActions() { ...@@ -799,9 +813,9 @@ void ToolbarActionsBar::ReorderActions() {
ToolbarActionViewController* ToolbarActionsBar::GetActionForId( ToolbarActionViewController* ToolbarActionsBar::GetActionForId(
const std::string& action_id) { const std::string& action_id) {
for (ToolbarActionViewController* action : toolbar_actions_) { for (const auto& action : toolbar_actions_) {
if (action->GetId() == action_id) if (action->GetId() == action_id)
return action; return action.get();
} }
return nullptr; return nullptr;
} }
......
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
#include <stddef.h> #include <stddef.h>
#include <memory> #include <memory>
#include <vector>
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
...@@ -47,6 +47,9 @@ class ToolbarActionViewController; ...@@ -47,6 +47,9 @@ class ToolbarActionViewController;
class ToolbarActionsBar : public ToolbarActionsModel::Observer, class ToolbarActionsBar : public ToolbarActionsModel::Observer,
public TabStripModelObserver { public TabStripModelObserver {
public: public:
using ToolbarActions =
std::vector<std::unique_ptr<ToolbarActionViewController>>;
// A struct to contain the platform settings. // A struct to contain the platform settings.
struct PlatformSettings { struct PlatformSettings {
PlatformSettings(); PlatformSettings();
...@@ -221,9 +224,8 @@ class ToolbarActionsBar : public ToolbarActionsModel::Observer, ...@@ -221,9 +224,8 @@ class ToolbarActionsBar : public ToolbarActionsModel::Observer,
// Returns the underlying toolbar actions, but does not order them. Primarily // Returns the underlying toolbar actions, but does not order them. Primarily
// for use in testing. // for use in testing.
const std::vector<ToolbarActionViewController*>& toolbar_actions_unordered() const ToolbarActions& toolbar_actions_unordered() const {
const { return toolbar_actions_;
return toolbar_actions_.get();
} }
bool enabled() const { return model_ != nullptr; } bool enabled() const { return model_ != nullptr; }
bool suppress_layout() const { return suppress_layout_; } bool suppress_layout() const { return suppress_layout_; }
...@@ -255,8 +257,6 @@ class ToolbarActionsBar : public ToolbarActionsModel::Observer, ...@@ -255,8 +257,6 @@ class ToolbarActionsBar : public ToolbarActionsModel::Observer,
int time_in_seconds); int time_in_seconds);
private: private:
using ToolbarActions = ScopedVector<ToolbarActionViewController>;
// ToolbarActionsModel::Observer: // ToolbarActionsModel::Observer:
void OnToolbarActionAdded(const ToolbarActionsModel::ToolbarItem& item, void OnToolbarActionAdded(const ToolbarActionsModel::ToolbarItem& item,
int index) override; int index) override;
......
...@@ -38,7 +38,7 @@ std::string VerifyToolbarOrderForBar( ...@@ -38,7 +38,7 @@ std::string VerifyToolbarOrderForBar(
const char* expected_names[], const char* expected_names[],
size_t total_size, size_t total_size,
size_t visible_count) { size_t visible_count) {
const std::vector<ToolbarActionViewController*>& toolbar_actions = const ToolbarActionsBar::ToolbarActions& toolbar_actions =
actions_bar->toolbar_actions_unordered(); actions_bar->toolbar_actions_unordered();
// If the total size is wrong, we risk segfaulting by continuing. Abort now. // If the total size is wrong, we risk segfaulting by continuing. Abort now.
if (total_size != toolbar_actions.size()) { if (total_size != toolbar_actions.size()) {
......
...@@ -162,17 +162,16 @@ void ToolbarActionsModel::OnExtensionActionUpdated( ...@@ -162,17 +162,16 @@ void ToolbarActionsModel::OnExtensionActionUpdated(
} }
} }
ScopedVector<ToolbarActionViewController> ToolbarActionsModel::CreateActions( std::vector<std::unique_ptr<ToolbarActionViewController>>
Browser* browser, ToolbarActionsModel::CreateActions(Browser* browser, ToolbarActionsBar* bar) {
ToolbarActionsBar* bar) {
DCHECK(browser); DCHECK(browser);
DCHECK(bar); DCHECK(bar);
ScopedVector<ToolbarActionViewController> action_list; std::vector<std::unique_ptr<ToolbarActionViewController>> action_list;
// toolbar_items() might not equate to toolbar_items_ in the case where a // toolbar_items() might not equate to toolbar_items_ in the case where a
// subset is highlighted. // subset is highlighted.
for (const ToolbarItem& item : toolbar_items()) for (const ToolbarItem& item : toolbar_items())
action_list.push_back(CreateActionForItem(browser, bar, item).release()); action_list.push_back(CreateActionForItem(browser, bar, item));
return action_list; return action_list;
} }
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "chrome/browser/extensions/api/extension_action/extension_action_api.h" #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
...@@ -152,7 +151,7 @@ class ToolbarActionsModel ...@@ -152,7 +151,7 @@ class ToolbarActionsModel
bool actions_initialized() const { return actions_initialized_; } bool actions_initialized() const { return actions_initialized_; }
ScopedVector<ToolbarActionViewController> CreateActions( std::vector<std::unique_ptr<ToolbarActionViewController>> CreateActions(
Browser* browser, Browser* browser,
ToolbarActionsBar* bar); ToolbarActionsBar* bar);
std::unique_ptr<ToolbarActionViewController> CreateActionForItem( std::unique_ptr<ToolbarActionViewController> CreateActionForItem(
......
...@@ -1734,9 +1734,13 @@ void BrowserView::OnWidgetDestroying(views::Widget* widget) { ...@@ -1734,9 +1734,13 @@ void BrowserView::OnWidgetDestroying(views::Widget* widget) {
// Destroy any remaining WebContents early on. Doing so may result in // Destroy any remaining WebContents early on. Doing so may result in
// calling back to one of the Views/LayoutManagers or supporting classes of // calling back to one of the Views/LayoutManagers or supporting classes of
// BrowserView. By destroying here we ensure all said classes are valid. // BrowserView. By destroying here we ensure all said classes are valid.
ScopedVector<content::WebContents> contents; std::vector<content::WebContents*> contents;
while (browser()->tab_strip_model()->count()) while (browser()->tab_strip_model()->count())
contents.push_back(browser()->tab_strip_model()->DetachWebContentsAt(0)); contents.push_back(browser()->tab_strip_model()->DetachWebContentsAt(0));
// Note: The BrowserViewTest tests rely on the contents being destroyed in the
// order that they were present in the tab strip.
for (auto* content : contents)
delete content;
} }
void BrowserView::OnWidgetActivationChanged(views::Widget* widget, void BrowserView::OnWidgetActivationChanged(views::Widget* widget,
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/ui/views/hung_renderer_view.h" #include "chrome/browser/ui/views/hung_renderer_view.h"
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -80,13 +81,14 @@ void HungPagesTableModel::InitForWebContents(WebContents* hung_contents) { ...@@ -80,13 +81,14 @@ void HungPagesTableModel::InitForWebContents(WebContents* hung_contents) {
if (hung_contents) { if (hung_contents) {
// Force hung_contents to be first. // Force hung_contents to be first.
if (hung_contents) { if (hung_contents) {
tab_observers_.push_back(new WebContentsObserverImpl(this, tab_observers_.push_back(
hung_contents)); base::MakeUnique<WebContentsObserverImpl>(this, hung_contents));
} }
for (TabContentsIterator it; !it.done(); it.Next()) { for (TabContentsIterator it; !it.done(); it.Next()) {
if (*it != hung_contents && if (*it != hung_contents &&
it->GetRenderProcessHost() == hung_contents->GetRenderProcessHost()) it->GetRenderProcessHost() == hung_contents->GetRenderProcessHost())
tab_observers_.push_back(new WebContentsObserverImpl(this, *it)); tab_observers_.push_back(
base::MakeUnique<WebContentsObserverImpl>(this, *it));
} }
} }
// The world is different. // The world is different.
...@@ -134,13 +136,15 @@ void HungPagesTableModel::GetGroupRange(int model_index, ...@@ -134,13 +136,15 @@ void HungPagesTableModel::GetGroupRange(int model_index,
void HungPagesTableModel::TabDestroyed(WebContentsObserverImpl* tab) { void HungPagesTableModel::TabDestroyed(WebContentsObserverImpl* tab) {
// Clean up tab_observers_ and notify our observer. // Clean up tab_observers_ and notify our observer.
TabObservers::iterator i = std::find( size_t index = 0;
tab_observers_.begin(), tab_observers_.end(), tab); for (; index < tab_observers_.size(); ++index) {
DCHECK(i != tab_observers_.end()); if (tab_observers_[index].get() == tab)
int index = static_cast<int>(i - tab_observers_.begin()); break;
tab_observers_.erase(i); }
DCHECK(index < tab_observers_.size());
tab_observers_.erase(tab_observers_.begin() + index);
if (observer_) if (observer_)
observer_->OnItemsRemoved(index, 1); observer_->OnItemsRemoved(static_cast<int>(index), 1);
// Notify the delegate. // Notify the delegate.
delegate_->TabDestroyed(); delegate_->TabDestroyed();
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define CHROME_BROWSER_UI_VIEWS_HUNG_RENDERER_VIEW_H_ #define CHROME_BROWSER_UI_VIEWS_HUNG_RENDERER_VIEW_H_
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "components/favicon/content/content_favicon_driver.h" #include "components/favicon/content/content_favicon_driver.h"
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
...@@ -86,8 +85,7 @@ class HungPagesTableModel : public ui::TableModel, public views::TableGrouper { ...@@ -86,8 +85,7 @@ class HungPagesTableModel : public ui::TableModel, public views::TableGrouper {
// notifies the observer and delegate. // notifies the observer and delegate.
void TabDestroyed(WebContentsObserverImpl* tab); void TabDestroyed(WebContentsObserverImpl* tab);
typedef ScopedVector<WebContentsObserverImpl> TabObservers; std::vector<std::unique_ptr<WebContentsObserverImpl>> tab_observers_;
TabObservers tab_observers_;
ui::TableModelObserver* observer_; ui::TableModelObserver* observer_;
Delegate* delegate_; Delegate* delegate_;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/ui/website_settings/permission_bubble_browser_test_util.h" #include "chrome/browser/ui/website_settings/permission_bubble_browser_test_util.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/ptr_util.h"
#include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/permissions/mock_permission_request.h" #include "chrome/browser/permissions/mock_permission_request.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
...@@ -31,10 +32,9 @@ void PermissionBubbleBrowserTest::SetUpOnMainThread() { ...@@ -31,10 +32,9 @@ void PermissionBubbleBrowserTest::SetUpOnMainThread() {
ExtensionBrowserTest::SetUpOnMainThread(); ExtensionBrowserTest::SetUpOnMainThread();
// Add a single permission request. // Add a single permission request.
MockPermissionRequest* request = new MockPermissionRequest( requests_.push_back(base::MakeUnique<MockPermissionRequest>(
"Request 1", l10n_util::GetStringUTF8(IDS_PERMISSION_ALLOW), "Request 1", l10n_util::GetStringUTF8(IDS_PERMISSION_ALLOW),
l10n_util::GetStringUTF8(IDS_PERMISSION_DENY)); l10n_util::GetStringUTF8(IDS_PERMISSION_DENY)));
requests_.push_back(request);
} }
Browser* PermissionBubbleBrowserTest::OpenExtensionAppWindow() { Browser* PermissionBubbleBrowserTest::OpenExtensionAppWindow() {
...@@ -56,6 +56,13 @@ Browser* PermissionBubbleBrowserTest::OpenExtensionAppWindow() { ...@@ -56,6 +56,13 @@ Browser* PermissionBubbleBrowserTest::OpenExtensionAppWindow() {
return app_browser; return app_browser;
} }
std::vector<PermissionRequest*> PermissionBubbleBrowserTest::requests() {
std::vector<PermissionRequest*> result;
for (const auto& request : requests_)
result.push_back(request.get());
return result;
}
PermissionBubbleKioskBrowserTest::PermissionBubbleKioskBrowserTest() { PermissionBubbleKioskBrowserTest::PermissionBubbleKioskBrowserTest() {
} }
......
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
#ifndef CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_BROWSER_TEST_UTIL_H_ #ifndef CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_BROWSER_TEST_UTIL_H_
#define CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_BROWSER_TEST_UTIL_H_ #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_PERMISSION_BUBBLE_BROWSER_TEST_UTIL_H_
#include <memory>
#include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/ui/website_settings/permission_prompt.h" #include "chrome/browser/ui/website_settings/permission_prompt.h"
...@@ -42,13 +45,13 @@ class PermissionBubbleBrowserTest : public ExtensionBrowserTest { ...@@ -42,13 +45,13 @@ class PermissionBubbleBrowserTest : public ExtensionBrowserTest {
// Opens an app window, and returns the associated browser. // Opens an app window, and returns the associated browser.
Browser* OpenExtensionAppWindow(); Browser* OpenExtensionAppWindow();
std::vector<PermissionRequest*> requests() { return requests_.get(); } std::vector<PermissionRequest*> requests();
std::vector<bool> accept_states() { return accept_states_; } std::vector<bool> accept_states() { return accept_states_; }
PermissionPrompt::Delegate* test_delegate() { return &test_delegate_; } PermissionPrompt::Delegate* test_delegate() { return &test_delegate_; }
private: private:
TestPermissionBubbleViewDelegate test_delegate_; TestPermissionBubbleViewDelegate test_delegate_;
ScopedVector<PermissionRequest> requests_; std::vector<std::unique_ptr<PermissionRequest>> requests_;
std::vector<bool> accept_states_; std::vector<bool> accept_states_;
DISALLOW_COPY_AND_ASSIGN(PermissionBubbleBrowserTest); DISALLOW_COPY_AND_ASSIGN(PermissionBubbleBrowserTest);
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/i18n/time_formatting.h" #include "base/i18n/time_formatting.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/extensions/api/identity/identity_api.h" #include "chrome/browser/extensions/api/identity/identity_api.h"
...@@ -95,7 +96,7 @@ class IdentityInternalsUIMessageHandler : public content::WebUIMessageHandler { ...@@ -95,7 +96,7 @@ class IdentityInternalsUIMessageHandler : public content::WebUIMessageHandler {
void RevokeToken(const base::ListValue* args); void RevokeToken(const base::ListValue* args);
// A vector of token revokers that are currently revoking tokens. // A vector of token revokers that are currently revoking tokens.
ScopedVector<IdentityInternalsTokenRevoker> token_revokers_; std::vector<std::unique_ptr<IdentityInternalsTokenRevoker>> token_revokers_;
}; };
// Handles the revoking of an access token and helps performing the clean up // Handles the revoking of an access token and helps performing the clean up
...@@ -159,10 +160,14 @@ void IdentityInternalsUIMessageHandler::OnTokenRevokerDone( ...@@ -159,10 +160,14 @@ void IdentityInternalsUIMessageHandler::OnTokenRevokerDone(
result); result);
// Erase the revoker. // Erase the revoker.
ScopedVector<IdentityInternalsTokenRevoker>::iterator iter = for (auto iter = token_revokers_.begin(); iter != token_revokers_.end();
std::find(token_revokers_.begin(), token_revokers_.end(), token_revoker); ++iter) {
DCHECK(iter != token_revokers_.end()); if (iter->get() == token_revoker) {
token_revokers_.erase(iter); token_revokers_.erase(iter);
return;
}
}
DCHECK(false) << "revoker should have been in the list";
} }
const std::string IdentityInternalsUIMessageHandler::GetExtensionName( const std::string IdentityInternalsUIMessageHandler::GetExtensionName(
...@@ -259,7 +264,7 @@ void IdentityInternalsUIMessageHandler::RevokeToken( ...@@ -259,7 +264,7 @@ void IdentityInternalsUIMessageHandler::RevokeToken(
std::string access_token; std::string access_token;
args->GetString(kRevokeTokenExtensionOffset, &extension_id); args->GetString(kRevokeTokenExtensionOffset, &extension_id);
args->GetString(kRevokeTokenTokenOffset, &access_token); args->GetString(kRevokeTokenTokenOffset, &access_token);
token_revokers_.push_back(new IdentityInternalsTokenRevoker( token_revokers_.push_back(base::MakeUnique<IdentityInternalsTokenRevoker>(
extension_id, access_token, Profile::FromWebUI(web_ui()), this)); extension_id, access_token, Profile::FromWebUI(web_ui()), this));
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <algorithm> #include <algorithm>
#include <map> #include <map>
#include <utility> #include <utility>
#include <vector>
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
...@@ -18,7 +19,7 @@ ...@@ -18,7 +19,7 @@
#include "base/i18n/string_compare.h" #include "base/i18n/string_compare.h"
#include "base/id_map.h" #include "base/id_map.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_vector.h" #include "base/memory/ptr_util.h"
#include "base/posix/safe_strerror.h" #include "base/posix/safe_strerror.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -1192,14 +1193,18 @@ void CertificateManagerHandler::PopulateTree( ...@@ -1192,14 +1193,18 @@ void CertificateManagerHandler::PopulateTree(
void CertificateManagerHandler::ShowError(const std::string& title, void CertificateManagerHandler::ShowError(const std::string& title,
const std::string& error) const { const std::string& error) const {
ScopedVector<const base::Value> args; auto title_value = base::MakeUnique<base::StringValue>(title);
args.push_back(new base::StringValue(title)); auto error_value = base::MakeUnique<base::StringValue>(error);
args.push_back(new base::StringValue(error)); auto ok_title_value =
args.push_back(new base::StringValue(l10n_util::GetStringUTF8(IDS_OK))); base::MakeUnique<base::StringValue>(l10n_util::GetStringUTF8(IDS_OK));
args.push_back(base::Value::CreateNullValue().release()); // cancelTitle auto cancel_title_value = base::Value::CreateNullValue();
args.push_back(base::Value::CreateNullValue().release()); // okCallback auto ok_callback_value = base::Value::CreateNullValue();
args.push_back(base::Value::CreateNullValue().release()); // cancelCallback auto cancel_callback_value = base::Value::CreateNullValue();
web_ui()->CallJavascriptFunctionUnsafe("AlertOverlay.show", args.get()); std::vector<const base::Value*> args = {
title_value.get(), error_value.get(),
ok_title_value.get(), cancel_title_value.get(),
ok_callback_value.get(), cancel_callback_value.get()};
web_ui()->CallJavascriptFunctionUnsafe("AlertOverlay.show", args);
} }
void CertificateManagerHandler::ShowImportErrors( void CertificateManagerHandler::ShowImportErrors(
......
...@@ -151,7 +151,7 @@ void ClearBrowserDataHandler::UpdateInfoBannerVisibility() { ...@@ -151,7 +151,7 @@ void ClearBrowserDataHandler::UpdateInfoBannerVisibility() {
} }
void ClearBrowserDataHandler::OnPageOpened(const base::ListValue* value) { void ClearBrowserDataHandler::OnPageOpened(const base::ListValue* value) {
for (browsing_data::BrowsingDataCounter* counter : counters_) { for (const auto& counter : counters_) {
DCHECK(AreCountersEnabled()); DCHECK(AreCountersEnabled());
counter->Restart(); counter->Restart();
} }
......
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
#define CHROME_BROWSER_UI_WEBUI_OPTIONS_CLEAR_BROWSER_DATA_HANDLER_H_ #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CLEAR_BROWSER_DATA_HANDLER_H_
#include <memory> #include <memory>
#include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "chrome/browser/browsing_data/browsing_data_remover.h" #include "chrome/browser/browsing_data/browsing_data_remover.h"
#include "chrome/browser/ui/webui/options/options_ui.h" #include "chrome/browser/ui/webui/options/options_ui.h"
#include "components/browser_sync/profile_sync_service.h" #include "components/browser_sync/profile_sync_service.h"
...@@ -83,7 +83,7 @@ class ClearBrowserDataHandler : public OptionsPageUIHandler, ...@@ -83,7 +83,7 @@ class ClearBrowserDataHandler : public OptionsPageUIHandler,
BooleanPrefMember allow_deleting_browser_history_; BooleanPrefMember allow_deleting_browser_history_;
// Counters that calculate the data volume for some of the data types. // Counters that calculate the data volume for some of the data types.
ScopedVector<browsing_data::BrowsingDataCounter> counters_; std::vector<std::unique_ptr<browsing_data::BrowsingDataCounter>> counters_;
// Informs us whether the user is syncing their data. // Informs us whether the user is syncing their data.
browser_sync::ProfileSyncService* sync_service_; browser_sync::ProfileSyncService* sync_service_;
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h" #include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "components/policy/core/common/policy_types.h" #include "components/policy/core/common/policy_types.h"
...@@ -56,13 +55,13 @@ class PreferencesBrowserTest : public InProcessBrowserTest { ...@@ -56,13 +55,13 @@ class PreferencesBrowserTest : public InProcessBrowserTest {
// Sets user policies through the mock policy provider. // Sets user policies through the mock policy provider.
void SetUserPolicies(const std::vector<std::string>& names, void SetUserPolicies(const std::vector<std::string>& names,
const std::vector<base::Value*>& values, const std::vector<std::unique_ptr<base::Value>>& values,
policy::PolicyLevel level); policy::PolicyLevel level);
// Clears user policies. // Clears user policies.
void ClearUserPolicies(); void ClearUserPolicies();
// Set user-modified pref values directly in the C++ backend. // Set user-modified pref values directly in the C++ backend.
void SetUserValues(const std::vector<std::string>& names, void SetUserValues(const std::vector<std::string>& names,
const std::vector<base::Value*>& values); const std::vector<std::unique_ptr<base::Value>>& values);
// Verifies that a dictionary contains a (key, value) pair. Takes ownership of // Verifies that a dictionary contains a (key, value) pair. Takes ownership of
// |expected|. // |expected|.
...@@ -73,7 +72,7 @@ class PreferencesBrowserTest : public InProcessBrowserTest { ...@@ -73,7 +72,7 @@ class PreferencesBrowserTest : public InProcessBrowserTest {
// been decorated correctly. // been decorated correctly.
void VerifyPref(const base::DictionaryValue* prefs, void VerifyPref(const base::DictionaryValue* prefs,
const std::string& name, const std::string& name,
const base::Value* value, const std::unique_ptr<base::Value>& value,
const std::string& controlledBy, const std::string& controlledBy,
bool disabled, bool disabled,
bool uncommitted); bool uncommitted);
...@@ -82,19 +81,20 @@ class PreferencesBrowserTest : public InProcessBrowserTest { ...@@ -82,19 +81,20 @@ class PreferencesBrowserTest : public InProcessBrowserTest {
// correctly. // correctly.
void VerifyObservedPref(const std::string& observed_json, void VerifyObservedPref(const std::string& observed_json,
const std::string& name, const std::string& name,
const base::Value* value, const std::unique_ptr<base::Value>& value,
const std::string& controlledBy, const std::string& controlledBy,
bool disabled, bool disabled,
bool uncommitted); bool uncommitted);
// Verifies that notifications received from the JavaScript Preferences class // Verifies that notifications received from the JavaScript Preferences class
// contain the given prefs and that their values have been decorated // contain the given prefs and that their values have been decorated
// correctly. // correctly.
void VerifyObservedPrefs(const std::string& observed_json, void VerifyObservedPrefs(
const std::vector<std::string>& names, const std::string& observed_json,
const std::vector<base::Value*>& values, const std::vector<std::string>& names,
const std::string& controlledBy, const std::vector<std::unique_ptr<base::Value>>& values,
bool disabled, const std::string& controlledBy,
bool uncommitted); bool disabled,
bool uncommitted);
// Sets up the expectation that the JavaScript Preferences class will make no // Sets up the expectation that the JavaScript Preferences class will make no
// change to a user-modified pref value in the C++ backend. // change to a user-modified pref value in the C++ backend.
...@@ -102,7 +102,7 @@ class PreferencesBrowserTest : public InProcessBrowserTest { ...@@ -102,7 +102,7 @@ class PreferencesBrowserTest : public InProcessBrowserTest {
// Sets up the expectation that the JavaScript Preferences class will set a // Sets up the expectation that the JavaScript Preferences class will set a
// user-modified pref value in the C++ backend. // user-modified pref value in the C++ backend.
void ExpectSetCommit(const std::string& name, void ExpectSetCommit(const std::string& name,
const base::Value* value); const std::unique_ptr<base::Value>& value);
// Sets up the expectation that the JavaScript Preferences class will clear a // Sets up the expectation that the JavaScript Preferences class will clear a
// user-modified pref value in the C++ backend. // user-modified pref value in the C++ backend.
void ExpectClearCommit(const std::string& name); void ExpectClearCommit(const std::string& name);
...@@ -119,7 +119,7 @@ class PreferencesBrowserTest : public InProcessBrowserTest { ...@@ -119,7 +119,7 @@ class PreferencesBrowserTest : public InProcessBrowserTest {
// VerifyObserved* methods. // VerifyObserved* methods.
void SetPref(const std::string& name, void SetPref(const std::string& name,
const std::string& type, const std::string& type,
const base::Value* value, const std::unique_ptr<base::Value>& value,
bool commit, bool commit,
std::string* observed_json); std::string* observed_json);
...@@ -128,36 +128,36 @@ class PreferencesBrowserTest : public InProcessBrowserTest { ...@@ -128,36 +128,36 @@ class PreferencesBrowserTest : public InProcessBrowserTest {
// the change to C++ if |commit| is true. // the change to C++ if |commit| is true.
void VerifySetPref(const std::string& name, void VerifySetPref(const std::string& name,
const std::string& type, const std::string& type,
const base::Value* value, const std::unique_ptr<base::Value>& value,
bool commit); bool commit);
// Verifies that clearing a user-modified pref value through the JavaScript // Verifies that clearing a user-modified pref value through the JavaScript
// Preferences class fires the correct notification in JavaScript and does // Preferences class fires the correct notification in JavaScript and does
// respectively does not cause the change to be committed to the C++ backend. // respectively does not cause the change to be committed to the C++ backend.
void VerifyClearPref(const std::string& name, void VerifyClearPref(const std::string& name,
const base::Value* value, const std::unique_ptr<base::Value>& value,
bool commit); bool commit);
// Verifies that committing a previously made change of a user-modified pref // Verifies that committing a previously made change of a user-modified pref
// value through the JavaScript Preferences class fires the correct // value through the JavaScript Preferences class fires the correct
// notification in JavaScript. // notification in JavaScript.
void VerifyCommit(const std::string& name, void VerifyCommit(const std::string& name,
const base::Value* value, const std::unique_ptr<base::Value>& value,
const std::string& controlledBy); const std::string& controlledBy);
// Verifies that committing a previously set user-modified pref value through // Verifies that committing a previously set user-modified pref value through
// the JavaScript Preferences class fires the correct notification in // the JavaScript Preferences class fires the correct notification in
// JavaScript and causes the change to be committed to the C++ backend. // JavaScript and causes the change to be committed to the C++ backend.
void VerifySetCommit(const std::string& name, void VerifySetCommit(const std::string& name,
const base::Value* value); const std::unique_ptr<base::Value>& value);
// Verifies that committing the previously cleared user-modified pref value // Verifies that committing the previously cleared user-modified pref value
// through the JavaScript Preferences class fires the correct notification in // through the JavaScript Preferences class fires the correct notification in
// JavaScript and causes the change to be committed to the C++ backend. // JavaScript and causes the change to be committed to the C++ backend.
void VerifyClearCommit(const std::string& name, void VerifyClearCommit(const std::string& name,
const base::Value* value); const std::unique_ptr<base::Value>& value);
// Verifies that rolling back a previously made change of a user-modified pref // Verifies that rolling back a previously made change of a user-modified pref
// value through the JavaScript Preferences class fires the correct // value through the JavaScript Preferences class fires the correct
// notification in JavaScript and does not cause the change to be committed to // notification in JavaScript and does not cause the change to be committed to
// the C++ backend. // the C++ backend.
void VerifyRollback(const std::string& name, void VerifyRollback(const std::string& name,
const base::Value* value, const std::unique_ptr<base::Value>& value,
const std::string& controlledBy); const std::string& controlledBy);
// Start observing notifications sent by the JavaScript Preferences class for // Start observing notifications sent by the JavaScript Preferences class for
// pref values changes. // pref values changes.
...@@ -186,8 +186,8 @@ class PreferencesBrowserTest : public InProcessBrowserTest { ...@@ -186,8 +186,8 @@ class PreferencesBrowserTest : public InProcessBrowserTest {
std::vector<std::string> types_; std::vector<std::string> types_;
std::vector<std::string> pref_names_; std::vector<std::string> pref_names_;
std::vector<std::string> policy_names_; std::vector<std::string> policy_names_;
ScopedVector<base::Value> default_values_; std::vector<std::unique_ptr<base::Value>> default_values_;
ScopedVector<base::Value> non_default_values_; std::vector<std::unique_ptr<base::Value>> non_default_values_;
private: private:
DISALLOW_COPY_AND_ASSIGN(PreferencesBrowserTest); DISALLOW_COPY_AND_ASSIGN(PreferencesBrowserTest);
......
...@@ -68,8 +68,7 @@ class SyncInternalsMessageHandlerTest : public ::testing::Test { ...@@ -68,8 +68,7 @@ class SyncInternalsMessageHandlerTest : public ::testing::Test {
} }
void ValidateAboutInfoCall() { void ValidateAboutInfoCall() {
const ScopedVector<content::TestWebUI::CallData>& data_vector = const auto& data_vector = web_ui_.call_data();
web_ui_.call_data();
ASSERT_FALSE(data_vector.empty()); ASSERT_FALSE(data_vector.empty());
EXPECT_EQ(1u, data_vector.size()); EXPECT_EQ(1u, data_vector.size());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment