Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 CHROME_INSTALLER_UTIL_EXPERIMENT_LABELS_H_ | |
| 6 #define CHROME_INSTALLER_UTIL_EXPERIMENT_LABELS_H_ | |
| 7 | |
| 8 #include <utility> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/strings/string16.h" | |
| 12 #include "base/strings/string_piece.h" | |
| 13 #include "base/time/time.h" | |
| 14 | |
| 15 namespace installer { | |
| 16 | |
| 17 // A wrapper around an Omaha "experiment_labels" value. No validation is | |
| 18 // performed on any values. | |
| 19 class ExperimentLabels { | |
| 20 public: | |
| 21 explicit ExperimentLabels(const base::string16& value); | |
| 22 | |
| 23 // Returns the experiment_labels string containing the individual labels. | |
| 24 const base::string16& value() const { return value_; } | |
| 25 | |
| 26 // Returns the value for a given label, or an empty StringPiece if it is not | |
| 27 // present in the instance's value. | |
| 28 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.
| |
| 29 | |
| 30 // Sets the value of a given label, overwriting a previous value if found. | |
| 31 // The label's expiration date is set to the current time plus |lifetime|. | |
| 32 // (A note for the future: if deleting labels is ever needed, this could be | |
| 33 // 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'
| |
| 34 void SetValueForLabel(base::StringPiece16 label_name, | |
| 35 base::StringPiece16 label_value, | |
| 36 base::TimeDelta lifetime); | |
| 37 | |
| 38 // Sets the value of a given label, overwriting a previous value if found. | |
| 39 void SetValueForLabel(base::StringPiece16 label_name, | |
| 40 base::StringPiece16 label_value, | |
| 41 base::Time expiration); | |
| 42 | |
| 43 private: | |
| 44 // 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.
| |
| 45 using LabelAndValue = std::pair<base::StringPiece16, base::StringPiece16>; | |
| 46 | |
| 47 // 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.
| |
| 48 // not found. | |
| 49 LabelAndValue FindLabel(base::StringPiece16 label_name) const; | |
| 50 | |
| 51 // The raw experiment_labels string. | |
| 52 base::string16 value_; | |
| 53 | |
| 54 DISALLOW_COPY_AND_ASSIGN(ExperimentLabels); | |
| 55 }; | |
| 56 | |
| 57 } // namespace installer | |
| 58 | |
| 59 #endif // CHROME_INSTALLER_UTIL_EXPERIMENT_LABELS_H_ | |
| OLD | NEW |