OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SEED_STORE_H_ | 5 #ifndef CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SEED_STORE_H_ |
6 #define CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SEED_STORE_H_ | 6 #define CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SEED_STORE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 | 13 |
14 class PrefService; | 14 class PrefService; |
15 class PrefRegistrySimple; | 15 class PrefRegistrySimple; |
16 | 16 |
| 17 namespace variations { |
| 18 class VariationsSeed; |
| 19 } |
| 20 |
17 namespace chrome_variations { | 21 namespace chrome_variations { |
18 | 22 |
19 class VariationsSeed; | |
20 | |
21 // VariationsSeedStore is a helper class for reading and writing the variations | 23 // VariationsSeedStore is a helper class for reading and writing the variations |
22 // seed from Local State. | 24 // seed from Local State. |
23 class VariationsSeedStore { | 25 class VariationsSeedStore { |
24 public: | 26 public: |
25 explicit VariationsSeedStore(PrefService* local_state); | 27 explicit VariationsSeedStore(PrefService* local_state); |
26 virtual ~VariationsSeedStore(); | 28 virtual ~VariationsSeedStore(); |
27 | 29 |
28 // Loads the variations seed data from local state into |seed|. If there is a | 30 // Loads the variations seed data from local state into |seed|. If there is a |
29 // problem with loading, the pref value is cleared and false is returned. If | 31 // problem with loading, the pref value is cleared and false is returned. If |
30 // successful, |seed| will contain the loaded data and true is returned. | 32 // successful, |seed| will contain the loaded data and true is returned. |
31 bool LoadSeed(VariationsSeed* seed); | 33 bool LoadSeed(variations::VariationsSeed* seed); |
32 | 34 |
33 // Stores the given seed data (serialized protobuf data) to local state, along | 35 // Stores the given seed data (serialized protobuf data) to local state, along |
34 // with a base64-encoded digital signature for seed and the date when it was | 36 // with a base64-encoded digital signature for seed and the date when it was |
35 // fetched. The |seed_data| will be base64 encoded for storage. If the string | 37 // fetched. The |seed_data| will be base64 encoded for storage. If the string |
36 // is invalid, the existing prefs are left as is and false is returned. On | 38 // is invalid, the existing prefs are left as is and false is returned. On |
37 // success and if |parsed_seed| is not NULL, |parsed_seed| will be filled | 39 // success and if |parsed_seed| is not NULL, |parsed_seed| will be filled |
38 // with the de-serialized protobuf decoded from |seed_data|. | 40 // with the de-serialized protobuf decoded from |seed_data|. |
39 bool StoreSeedData(const std::string& seed_data, | 41 bool StoreSeedData(const std::string& seed_data, |
40 const std::string& base64_seed_signature, | 42 const std::string& base64_seed_signature, |
41 const base::Time& date_fetched, | 43 const base::Time& date_fetched, |
42 VariationsSeed* parsed_seed); | 44 variations::VariationsSeed* parsed_seed); |
43 | 45 |
44 // Updates |kVariationsSeedDate| and logs when previous date was from a | 46 // Updates |kVariationsSeedDate| and logs when previous date was from a |
45 // different day. | 47 // different day. |
46 void UpdateSeedDateAndLogDayChange(const base::Time& server_date_fetched); | 48 void UpdateSeedDateAndLogDayChange(const base::Time& server_date_fetched); |
47 | 49 |
48 // Returns the serial number of the last loaded or stored seed. | 50 // Returns the serial number of the last loaded or stored seed. |
49 const std::string& variations_serial_number() const { | 51 const std::string& variations_serial_number() const { |
50 return variations_serial_number_; | 52 return variations_serial_number_; |
51 } | 53 } |
52 | 54 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 87 |
86 // Cached serial number from the most recently fetched variations seed. | 88 // Cached serial number from the most recently fetched variations seed. |
87 std::string variations_serial_number_; | 89 std::string variations_serial_number_; |
88 | 90 |
89 DISALLOW_COPY_AND_ASSIGN(VariationsSeedStore); | 91 DISALLOW_COPY_AND_ASSIGN(VariationsSeedStore); |
90 }; | 92 }; |
91 | 93 |
92 } // namespace chrome_variations | 94 } // namespace chrome_variations |
93 | 95 |
94 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SEED_STORE_H_ | 96 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SEED_STORE_H_ |
OLD | NEW |