Home | History | Annotate | Download | only in webdata
      1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include <set>
      6 #include "chrome/browser/webdata/autofill_entry.h"
      7 #include "base/utf_string_conversions.h"
      8 
      9 AutofillKey::AutofillKey() {}
     10 
     11 AutofillKey::AutofillKey(const string16& name, const string16& value)
     12     : name_(name),
     13       value_(value) {
     14 }
     15 
     16 AutofillKey::AutofillKey(const char* name, const char* value)
     17     : name_(UTF8ToUTF16(name)),
     18       value_(UTF8ToUTF16(value)) {
     19 }
     20 
     21 AutofillKey::AutofillKey(const AutofillKey& key)
     22     : name_(key.name()),
     23       value_(key.value()) {
     24 }
     25 
     26 AutofillKey::~AutofillKey() {}
     27 
     28 bool AutofillKey::operator==(const AutofillKey& key) const {
     29   return name_ == key.name() && value_ == key.value();
     30 }
     31 
     32 bool AutofillKey::operator<(const AutofillKey& key) const {
     33   int diff = name_.compare(key.name());
     34   if (diff < 0) {
     35     return true;
     36   } else if (diff == 0) {
     37     return value_.compare(key.value()) < 0;
     38   } else {
     39     return false;
     40   }
     41 }
     42 
     43 AutofillEntry::AutofillEntry(const AutofillKey& key,
     44                              const std::vector<base::Time>& timestamps)
     45     : key_(key),
     46       timestamps_(timestamps) {
     47 }
     48 
     49 AutofillEntry::~AutofillEntry() {}
     50 
     51 bool AutofillEntry::operator==(const AutofillEntry& entry) const {
     52   if (!(key_ == entry.key()))
     53     return false;
     54 
     55   if (timestamps_.size() != entry.timestamps().size())
     56     return false;
     57 
     58   std::set<base::Time> other_timestamps(entry.timestamps().begin(),
     59                                         entry.timestamps().end());
     60   for (size_t i = 0; i < timestamps_.size(); i++) {
     61     if (other_timestamps.count(timestamps_[i]) == 0)
     62       return false;
     63   }
     64 
     65   return true;
     66 }
     67 
     68 bool AutofillEntry::operator<(const AutofillEntry& entry) const {
     69   return key_ < entry.key();
     70 }
     71