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 COMPONENTS_VARIATIONS_VARIATIONS_SEED_STORE_H_ | 5 #ifndef COMPONENTS_VARIATIONS_VARIATIONS_SEED_STORE_H_ |
6 #define COMPONENTS_VARIATIONS_VARIATIONS_SEED_STORE_H_ | 6 #define COMPONENTS_VARIATIONS_VARIATIONS_SEED_STORE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/callback.h" |
10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
11 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 | 14 |
14 class PrefService; | 15 class PrefService; |
15 class PrefRegistrySimple; | 16 class PrefRegistrySimple; |
16 | 17 |
17 namespace variations { | 18 namespace variations { |
18 class VariationsSeed; | 19 class VariationsSeed; |
19 } | 20 } |
20 | 21 |
21 namespace variations { | 22 namespace variations { |
22 | 23 |
| 24 typedef base::Callback<void(std::string*, std::string*, std::string*)> |
| 25 VariationsFirstRunSeedCallback; |
| 26 |
23 // VariationsSeedStore is a helper class for reading and writing the variations | 27 // VariationsSeedStore is a helper class for reading and writing the variations |
24 // seed from Local State. | 28 // seed from Local State. |
25 class VariationsSeedStore { | 29 class VariationsSeedStore { |
26 public: | 30 public: |
27 explicit VariationsSeedStore(PrefService* local_state); | 31 explicit VariationsSeedStore(PrefService* local_state); |
28 virtual ~VariationsSeedStore(); | 32 virtual ~VariationsSeedStore(); |
29 | 33 |
30 // Loads the variations seed data from local state into |seed|. If there is a | 34 // Loads the variations seed data from local state into |seed|. If there is a |
31 // problem with loading, the pref value is cleared and false is returned. If | 35 // problem with loading, the pref value is cleared and false is returned. If |
32 // successful, |seed| will contain the loaded data and true is returned. | 36 // successful, |seed| will contain the loaded data and true is returned. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 return seed_has_country_code_; | 72 return seed_has_country_code_; |
69 } | 73 } |
70 | 74 |
71 // Returns the invalid signature in base64 format, or an empty string if the | 75 // Returns the invalid signature in base64 format, or an empty string if the |
72 // signature was valid, missing, or if signature verification is disabled. | 76 // signature was valid, missing, or if signature verification is disabled. |
73 std::string GetInvalidSignature() const; | 77 std::string GetInvalidSignature() const; |
74 | 78 |
75 // Registers Local State prefs used by this class. | 79 // Registers Local State prefs used by this class. |
76 static void RegisterPrefs(PrefRegistrySimple* registry); | 80 static void RegisterPrefs(PrefRegistrySimple* registry); |
77 | 81 |
| 82 // Registers callback for pulling variations first run seed from Java side |
| 83 // in Chrome for Android. |
| 84 void SetVariationsFirstRunSeedCallback( |
| 85 const VariationsFirstRunSeedCallback& callback) { |
| 86 get_variations_first_run_seed_ = callback; |
| 87 } |
| 88 |
78 protected: | 89 protected: |
79 // Note: UMA histogram enum - don't re-order or remove entries. | 90 // Note: UMA histogram enum - don't re-order or remove entries. |
80 enum VerifySignatureResult { | 91 enum VerifySignatureResult { |
81 VARIATIONS_SEED_SIGNATURE_MISSING, | 92 VARIATIONS_SEED_SIGNATURE_MISSING, |
82 VARIATIONS_SEED_SIGNATURE_DECODE_FAILED, | 93 VARIATIONS_SEED_SIGNATURE_DECODE_FAILED, |
83 VARIATIONS_SEED_SIGNATURE_INVALID_SIGNATURE, | 94 VARIATIONS_SEED_SIGNATURE_INVALID_SIGNATURE, |
84 VARIATIONS_SEED_SIGNATURE_INVALID_SEED, | 95 VARIATIONS_SEED_SIGNATURE_INVALID_SEED, |
85 VARIATIONS_SEED_SIGNATURE_VALID, | 96 VARIATIONS_SEED_SIGNATURE_VALID, |
86 VARIATIONS_SEED_SIGNATURE_ENUM_SIZE, | 97 VARIATIONS_SEED_SIGNATURE_ENUM_SIZE, |
87 }; | 98 }; |
88 | 99 |
89 // Verifies a variations seed (the serialized proto bytes) with the specified | 100 // Verifies a variations seed (the serialized proto bytes) with the specified |
90 // base-64 encoded signature that was received from the server and returns the | 101 // base-64 encoded signature that was received from the server and returns the |
91 // result. The signature is assumed to be an "ECDSA with SHA-256" signature | 102 // result. The signature is assumed to be an "ECDSA with SHA-256" signature |
92 // (see kECDSAWithSHA256AlgorithmID in the .cc file). Returns the result of | 103 // (see kECDSAWithSHA256AlgorithmID in the .cc file). Returns the result of |
93 // signature verification or VARIATIONS_SEED_SIGNATURE_ENUM_SIZE if signature | 104 // signature verification or VARIATIONS_SEED_SIGNATURE_ENUM_SIZE if signature |
94 // verification is not enabled. | 105 // verification is not enabled. |
95 virtual VariationsSeedStore::VerifySignatureResult VerifySeedSignature( | 106 virtual VariationsSeedStore::VerifySignatureResult VerifySeedSignature( |
96 const std::string& seed_bytes, | 107 const std::string& seed_bytes, |
97 const std::string& base64_seed_signature); | 108 const std::string& base64_seed_signature); |
98 | 109 |
99 private: | 110 private: |
100 FRIEND_TEST_ALL_PREFIXES(VariationsSeedStoreTest, VerifySeedSignature); | 111 FRIEND_TEST_ALL_PREFIXES(VariationsSeedStoreTest, VerifySeedSignature); |
101 FRIEND_TEST_ALL_PREFIXES(VariationsSeedStoreTest, ApplyDeltaPatch); | 112 FRIEND_TEST_ALL_PREFIXES(VariationsSeedStoreTest, ApplyDeltaPatch); |
102 | 113 |
103 // Clears all prefs related to variations seed storage. | 114 // Clears all prefs related to variations seed storage. |
104 void ClearPrefs(); | 115 void ClearPrefs(); |
105 | 116 |
| 117 #if defined(OS_ANDROID) |
| 118 // Imports the variations seed data from Java side during the first |
| 119 // Chrome for Android run. |
| 120 void ImportFirstRunJavaSeed(); |
| 121 #endif // OS_ANDROID |
| 122 |
106 // Reads the variations seed data from prefs; returns true on success. | 123 // Reads the variations seed data from prefs; returns true on success. |
107 bool ReadSeedData(std::string* seed_data); | 124 bool ReadSeedData(std::string* seed_data); |
108 | 125 |
109 // Internal version of |StoreSeedData()| that assumes |seed_data| is not delta | 126 // Internal version of |StoreSeedData()| that assumes |seed_data| is not delta |
110 // compressed. | 127 // compressed. |
111 bool StoreSeedDataNoDelta( | 128 bool StoreSeedDataNoDelta( |
112 const std::string& seed_data, | 129 const std::string& seed_data, |
113 const std::string& base64_seed_signature, | 130 const std::string& base64_seed_signature, |
114 const std::string& country_code, | 131 const std::string& country_code, |
115 const base::Time& date_fetched, | 132 const base::Time& date_fetched, |
(...skipping 11 matching lines...) Expand all Loading... |
127 // Cached serial number from the most recently fetched variations seed. | 144 // Cached serial number from the most recently fetched variations seed. |
128 std::string variations_serial_number_; | 145 std::string variations_serial_number_; |
129 | 146 |
130 // Whether the most recently fetched variations seed has the country code | 147 // Whether the most recently fetched variations seed has the country code |
131 // field set. | 148 // field set. |
132 bool seed_has_country_code_; | 149 bool seed_has_country_code_; |
133 | 150 |
134 // Keeps track of an invalid signature. | 151 // Keeps track of an invalid signature. |
135 std::string invalid_base64_signature_; | 152 std::string invalid_base64_signature_; |
136 | 153 |
| 154 VariationsFirstRunSeedCallback get_variations_first_run_seed_; |
| 155 |
137 DISALLOW_COPY_AND_ASSIGN(VariationsSeedStore); | 156 DISALLOW_COPY_AND_ASSIGN(VariationsSeedStore); |
138 }; | 157 }; |
139 | 158 |
140 } // namespace variations | 159 } // namespace variations |
141 | 160 |
142 #endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_STORE_H_ | 161 #endif // COMPONENTS_VARIATIONS_VARIATIONS_SEED_STORE_H_ |
OLD | NEW |