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. For reference, see |
| 19 // https://github.com/google/omaha/blob/master/omaha/common/experiment_labels.cc
#L16. |
| 20 class ExperimentLabels { |
| 21 public: |
| 22 explicit ExperimentLabels(const base::string16& value); |
| 23 |
| 24 // Returns the experiment_labels string containing the individual labels. |
| 25 const base::string16& value() const { return value_; } |
| 26 |
| 27 // Returns a StringPiece pointing to the value for a given label, or an empty |
| 28 // StringPiece if it is not present in the instance's value. Note: the |
| 29 // ExperimentLabels instance must outlive the piece returned, and the piece is |
| 30 // invalidated by any call to SetValueForLabel. |
| 31 base::StringPiece16 GetValueForLabel(base::StringPiece16 label_name) const; |
| 32 |
| 33 // Sets the value of a given label, overwriting a previous value if found. |
| 34 // The label's expiration date is set to the current time plus |lifetime|. |
| 35 void SetValueForLabel(base::StringPiece16 label_name, |
| 36 base::StringPiece16 label_value, |
| 37 base::TimeDelta lifetime); |
| 38 |
| 39 // Sets the value of a given label, overwriting a previous value if found. |
| 40 void SetValueForLabel(base::StringPiece16 label_name, |
| 41 base::StringPiece16 label_value, |
| 42 base::Time expiration); |
| 43 |
| 44 private: |
| 45 // A label's full contents ("name=value|expiration") and value within |
| 46 // |value_|. |
| 47 using LabelAndValue = std::pair<base::StringPiece16, base::StringPiece16>; |
| 48 |
| 49 // Returns the label and value named |label_name|, or empty string pieces if |
| 50 // not found. |
| 51 LabelAndValue FindLabel(base::StringPiece16 label_name) const; |
| 52 |
| 53 // The raw experiment_labels string. |
| 54 base::string16 value_; |
| 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(ExperimentLabels); |
| 57 }; |
| 58 |
| 59 } // namespace installer |
| 60 |
| 61 #endif // CHROME_INSTALLER_UTIL_EXPERIMENT_LABELS_H_ |
OLD | NEW |