Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: chrome/installer/util/experiment_labels.h

Issue 2872583002: Adding ExperimentLabels helper class. (Closed)
Patch Set: pmonette comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/installer/util/BUILD.gn ('k') | chrome/installer/util/experiment_labels.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_
OLDNEW
« no previous file with comments | « chrome/installer/util/BUILD.gn ('k') | chrome/installer/util/experiment_labels.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698