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

Side by Side Diff: ui/views/view_model.cc

Issue 298963004: app_list: Fix possible out of bounds index. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DCHECK -> CHECK Created 6 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 | Annotate | Revision Log
« no previous file with comments | « ui/app_list/views/test/apps_grid_view_test_api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/view_model.h" 5 #include "ui/views/view_model.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/views/view.h" 8 #include "ui/views/view.h"
9 9
10 namespace views { 10 namespace views {
(...skipping 15 matching lines...) Expand all
26 26
27 void ViewModel::Remove(int index) { 27 void ViewModel::Remove(int index) {
28 if (index == -1) 28 if (index == -1)
29 return; 29 return;
30 30
31 check_index(index); 31 check_index(index);
32 entries_.erase(entries_.begin() + index); 32 entries_.erase(entries_.begin() + index);
33 } 33 }
34 34
35 void ViewModel::Move(int index, int target_index) { 35 void ViewModel::Move(int index, int target_index) {
36 DCHECK_LT(index, static_cast<int>(entries_.size()));
37 DCHECK_GE(index, 0);
38 DCHECK_LT(target_index, static_cast<int>(entries_.size()));
39 DCHECK_GE(target_index, 0);
40
36 if (index == target_index) 41 if (index == target_index)
37 return; 42 return;
38 Entry entry(entries_[index]); 43 Entry entry(entries_[index]);
39 entries_.erase(entries_.begin() + index); 44 entries_.erase(entries_.begin() + index);
40 entries_.insert(entries_.begin() + target_index, entry); 45 entries_.insert(entries_.begin() + target_index, entry);
41 } 46 }
42 47
43 void ViewModel::MoveViewOnly(int index, int target_index) { 48 void ViewModel::MoveViewOnly(int index, int target_index) {
44 if (index == target_index) 49 if (index == target_index)
45 return; 50 return;
(...skipping 19 matching lines...) Expand all
65 70
66 int ViewModel::GetIndexOfView(const View* view) const { 71 int ViewModel::GetIndexOfView(const View* view) const {
67 for (size_t i = 0; i < entries_.size(); ++i) { 72 for (size_t i = 0; i < entries_.size(); ++i) {
68 if (entries_[i].view == view) 73 if (entries_[i].view == view)
69 return static_cast<int>(i); 74 return static_cast<int>(i);
70 } 75 }
71 return -1; 76 return -1;
72 } 77 }
73 78
74 } // namespace views 79 } // namespace views
OLDNEW
« no previous file with comments | « ui/app_list/views/test/apps_grid_view_test_api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698