Chromium Code Reviews| Index: chrome/installer/util/experiment_labels.h |
| diff --git a/chrome/installer/util/experiment_labels.h b/chrome/installer/util/experiment_labels.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9a05798cdb92e7584ad9c19e86c8accc26df0421 |
| --- /dev/null |
| +++ b/chrome/installer/util/experiment_labels.h |
| @@ -0,0 +1,59 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_INSTALLER_UTIL_EXPERIMENT_LABELS_H_ |
| +#define CHROME_INSTALLER_UTIL_EXPERIMENT_LABELS_H_ |
| + |
| +#include <utility> |
| + |
| +#include "base/macros.h" |
| +#include "base/strings/string16.h" |
| +#include "base/strings/string_piece.h" |
| +#include "base/time/time.h" |
| + |
| +namespace installer { |
| + |
| +// A wrapper around an Omaha "experiment_labels" value. No validation is |
| +// performed on any values. |
| +class ExperimentLabels { |
| + public: |
| + explicit ExperimentLabels(const base::string16& value); |
| + |
| + // Returns the experiment_labels string containing the individual labels. |
| + const base::string16& value() const { return value_; } |
| + |
| + // Returns the value for a given label, or an empty StringPiece if it is not |
| + // present in the instance's value. |
| + base::StringPiece16 GetValueForLabel(base::StringPiece16 label_name) const; |
|
Patrick Monette
2017/05/08 15:27:48
Maybe note that ExperimentLabels must outlive the
grt (UTC plus 2)
2017/05/08 20:15:26
Done.
|
| + |
| + // Sets the value of a given label, overwriting a previous value if found. |
| + // The label's expiration date is set to the current time plus |lifetime|. |
| + // (A note for the future: if deleting labels is ever needed, this could be |
| + // extended to delete if |lifetime| is zero. |
|
Patrick Monette
2017/05/08 15:27:48
I'm not a fan of this comment. If this is ever nee
grt (UTC plus 2)
2017/05/08 20:15:26
Funny, I had the same thought earlier today -- it'
|
| + void SetValueForLabel(base::StringPiece16 label_name, |
| + base::StringPiece16 label_value, |
| + base::TimeDelta lifetime); |
| + |
| + // Sets the value of a given label, overwriting a previous value if found. |
| + void SetValueForLabel(base::StringPiece16 label_name, |
| + base::StringPiece16 label_value, |
| + base::Time expiration); |
| + |
| + private: |
| + // A label's full contents ("name=value|exp") and value within |value_|. |
|
Patrick Monette
2017/05/08 15:27:48
s/exp/expiration
grt (UTC plus 2)
2017/05/08 20:15:26
Done.
|
| + using LabelAndValue = std::pair<base::StringPiece16, base::StringPiece16>; |
| + |
| + // Returns the label and value nameed |label_name|, or empty string pieces if |
|
Patrick Monette
2017/05/08 15:27:48
s/nameed/named
grt (UTC plus 2)
2017/05/08 20:15:26
Nice catch! Done.
|
| + // not found. |
| + LabelAndValue FindLabel(base::StringPiece16 label_name) const; |
| + |
| + // The raw experiment_labels string. |
| + base::string16 value_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ExperimentLabels); |
| +}; |
| + |
| +} // namespace installer |
| + |
| +#endif // CHROME_INSTALLER_UTIL_EXPERIMENT_LABELS_H_ |