Home | History | Annotate | Download | only in webdata
      1 // Copyright 2013 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 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_ENTRY_H__
      6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_ENTRY_H__
      7 
      8 #include <stddef.h>
      9 #include <vector>
     10 
     11 #include "base/gtest_prod_util.h"
     12 #include "base/strings/string16.h"
     13 #include "base/time/time.h"
     14 
     15 namespace autofill {
     16 
     17 class AutofillKey {
     18  public:
     19   AutofillKey();
     20   AutofillKey(const base::string16& name, const base::string16& value);
     21   AutofillKey(const char* name, const char* value);
     22   AutofillKey(const AutofillKey& key);
     23   virtual ~AutofillKey();
     24 
     25   const base::string16& name() const { return name_; }
     26   const base::string16& value() const { return value_; }
     27 
     28   bool operator==(const AutofillKey& key) const;
     29   bool operator<(const AutofillKey& key) const;
     30 
     31  private:
     32   base::string16 name_;
     33   base::string16 value_;
     34 };
     35 
     36 class AutofillEntry {
     37  public:
     38   AutofillEntry(const AutofillKey& key,
     39                 const std::vector<base::Time>& timestamps);
     40   ~AutofillEntry();
     41 
     42   const AutofillKey& key() const { return key_; }
     43   const std::vector<base::Time>& timestamps() const { return timestamps_; }
     44 
     45   bool operator==(const AutofillEntry& entry) const;
     46   bool operator<(const AutofillEntry& entry) const;
     47 
     48   bool timestamps_culled() const { return timestamps_culled_; }
     49 
     50   // Checks if last of the timestamps are older than ExpirationTime().
     51   bool IsExpired() const;
     52 
     53   // The entries last accessed before this time should expire.
     54   static base::Time ExpirationTime();
     55 
     56  private:
     57   FRIEND_TEST_ALL_PREFIXES(AutofillEntryTest, NoCulling);
     58   FRIEND_TEST_ALL_PREFIXES(AutofillEntryTest, Culling);
     59   FRIEND_TEST_ALL_PREFIXES(AutofillEntryTest, CullByTime);
     60 
     61   // Culls the list of timestamps to 2 - the oldest and most recent. This is a
     62   // precursor to getting rid of the timestamps db altogether.
     63   // See http://crbug.com/118696.
     64   // |source| is expected to be sorted from oldest to newest.
     65   static bool CullTimeStamps(const std::vector<base::Time>& source,
     66                              std::vector<base::Time>* result);
     67 
     68   AutofillKey key_;
     69   std::vector<base::Time> timestamps_;
     70   bool timestamps_culled_;
     71 };
     72 
     73 }  // namespace autofill
     74 
     75 #endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_ENTRY_H__
     76