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

Side by Side Diff: chrome/browser/autofill/autofill_scanner.cc

Issue 7120005: Simplify Autofill Scanner semantics (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/autofill/autofill_scanner.h" 5 #include "chrome/browser/autofill/autofill_scanner.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/autofill/autofill_field.h" 8 #include "chrome/browser/autofill/autofill_field.h"
9 9
10 AutofillScanner::AutofillScanner( 10 AutofillScanner::AutofillScanner(
11 const std::vector<const AutofillField*>& fields) 11 const std::vector<const AutofillField*>& fields)
12 : cursor_(fields.begin()), 12 : cursor_(fields.begin()),
13 saved_cursor_(fields.begin()),
14 begin_(fields.begin()),
13 end_(fields.end()) { 15 end_(fields.end()) {
14 } 16 }
15 17
16 AutofillScanner::~AutofillScanner() { 18 AutofillScanner::~AutofillScanner() {
17 } 19 }
18 20
19 void AutofillScanner::Advance() { 21 void AutofillScanner::Advance() {
20 DCHECK(!IsEnd()); 22 DCHECK(!IsEnd());
21 ++cursor_; 23 ++cursor_;
22 } 24 }
23 25
24 const AutofillField* AutofillScanner::Cursor() const { 26 const AutofillField* AutofillScanner::Cursor() const {
25 if (IsEnd()) { 27 if (IsEnd()) {
26 NOTREACHED(); 28 NOTREACHED();
27 return NULL; 29 return NULL;
28 } 30 }
29 31
30 return *cursor_; 32 return *cursor_;
31 } 33 }
32 34
33 bool AutofillScanner::IsEnd() const { 35 bool AutofillScanner::IsEnd() const {
34 return cursor_ == end_; 36 return cursor_ == end_;
35 } 37 }
36 38
37 void AutofillScanner::Rewind() { 39 void AutofillScanner::Rewind() {
38 DCHECK(!saved_cursors_.empty()); 40 DCHECK(saved_cursor_ != end_);
39 cursor_ = saved_cursors_.back(); 41 cursor_ = saved_cursor_;
40 saved_cursors_.pop_back(); 42 saved_cursor_ = end_;
41 } 43 }
42 44
43 void AutofillScanner::SaveCursor() { 45 void AutofillScanner::RewindTo(size_t index) {
44 saved_cursors_.push_back(cursor_); 46 DCHECK(index < static_cast<size_t>(end_ - begin_));
47 cursor_ = begin_ + index;
48 saved_cursor_ = end_;
45 } 49 }
50
51 size_t AutofillScanner::SaveCursor() {
52 saved_cursor_ = cursor_;
53 return static_cast<size_t>(cursor_ - begin_);
54 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_scanner.h ('k') | chrome/browser/autofill/credit_card_field.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698