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

Side by Side Diff: chrome/browser/metrics/variations/variations_seed_store.h

Issue 1200233005: Support delta-compressed variations server responses. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 4 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
OLDNEW
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"
(...skipping 14 matching lines...) Expand all
25 class VariationsSeedStore { 25 class VariationsSeedStore {
26 public: 26 public:
27 explicit VariationsSeedStore(PrefService* local_state); 27 explicit VariationsSeedStore(PrefService* local_state);
28 virtual ~VariationsSeedStore(); 28 virtual ~VariationsSeedStore();
29 29
30 // 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
31 // 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
32 // successful, |seed| will contain the loaded data and true is returned. 32 // successful, |seed| will contain the loaded data and true is returned.
33 bool LoadSeed(variations::VariationsSeed* seed); 33 bool LoadSeed(variations::VariationsSeed* seed);
34 34
35 // Stores the given seed data (serialized protobuf data) to local state, along 35 // Stores the given seed data (serialized protobuf) to local state, along
rkaplow 2015/08/04 22:37:05 nit, would change to |data| too then
Alexei Svitkine (slow) 2015/08/05 15:46:15 Done.
36 // 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
37 // fetched. The |seed_data| will be base64 encoded for storage. If the string 37 // fetched. If |is_delta_compressed| is true, treats |data| as being delta
38 // is invalid, the existing prefs are left as is and false is returned. On 38 // compressed and attempts to decode it first using the store seed data.
rkaplow 2015/08/04 22:37:05 did you mean stored btw?
Alexei Svitkine (slow) 2015/08/05 15:46:15 No meant, store's - i.e. refererring to this class
rkaplow 2015/08/05 18:01:56 it's fine - wasn't sure which way you meant it.
39 // The actual seed data will be base64 encoded for storage. If the string
40 // is invalid, the existing prefs are untouched and false is returned. On
39 // success and if |parsed_seed| is not NULL, |parsed_seed| will be filled 41 // success and if |parsed_seed| is not NULL, |parsed_seed| will be filled
40 // with the de-serialized protobuf decoded from |seed_data|. 42 // with the de-serialized decoded protobuf.
41 bool StoreSeedData(const std::string& seed_data, 43 bool StoreSeedData(const std::string& data,
42 const std::string& base64_seed_signature, 44 const std::string& base64_seed_signature,
45 const std::string& country_code,
rkaplow 2015/08/04 22:37:05 might be worth to add a line in the comment on how
Alexei Svitkine (slow) 2015/08/05 15:46:15 Done.
43 const base::Time& date_fetched, 46 const base::Time& date_fetched,
47 bool is_delta_compressed,
44 variations::VariationsSeed* parsed_seed); 48 variations::VariationsSeed* parsed_seed);
45 49
46 // Updates |kVariationsSeedDate| and logs when previous date was from a 50 // Updates |kVariationsSeedDate| and logs when previous date was from a
47 // different day. 51 // different day.
48 void UpdateSeedDateAndLogDayChange(const base::Time& server_date_fetched); 52 void UpdateSeedDateAndLogDayChange(const base::Time& server_date_fetched);
49 53
50 // Returns the serial number of the last loaded or stored seed. 54 // Returns the serial number of the last loaded or stored seed.
51 const std::string& variations_serial_number() const { 55 const std::string& variations_serial_number() const {
52 return variations_serial_number_; 56 return variations_serial_number_;
53 } 57 }
54 58
55 // Registers Local State prefs used by this class. 59 // Returns whether the last loaded or stored seed has the country field set.
56 static void RegisterPrefs(PrefRegistrySimple* registry); 60 bool seed_has_country_code() const {
61 return seed_has_country_code_;
62 }
57 63
58 // Returns the invalid signature in base64 format, or an empty string if the 64 // Returns the invalid signature in base64 format, or an empty string if the
59 // signature was valid, missing, or if signature verification is disabled. 65 // signature was valid, missing, or if signature verification is disabled.
60 std::string GetInvalidSignature() const; 66 std::string GetInvalidSignature() const;
61 67
68 // Registers Local State prefs used by this class.
69 static void RegisterPrefs(PrefRegistrySimple* registry);
70
62 protected: 71 protected:
63 // Note: UMA histogram enum - don't re-order or remove entries. 72 // Note: UMA histogram enum - don't re-order or remove entries.
64 enum VerifySignatureResult { 73 enum VerifySignatureResult {
65 VARIATIONS_SEED_SIGNATURE_MISSING, 74 VARIATIONS_SEED_SIGNATURE_MISSING,
66 VARIATIONS_SEED_SIGNATURE_DECODE_FAILED, 75 VARIATIONS_SEED_SIGNATURE_DECODE_FAILED,
67 VARIATIONS_SEED_SIGNATURE_INVALID_SIGNATURE, 76 VARIATIONS_SEED_SIGNATURE_INVALID_SIGNATURE,
68 VARIATIONS_SEED_SIGNATURE_INVALID_SEED, 77 VARIATIONS_SEED_SIGNATURE_INVALID_SEED,
69 VARIATIONS_SEED_SIGNATURE_VALID, 78 VARIATIONS_SEED_SIGNATURE_VALID,
70 VARIATIONS_SEED_SIGNATURE_ENUM_SIZE, 79 VARIATIONS_SEED_SIGNATURE_ENUM_SIZE,
71 }; 80 };
72 81
73 // Verifies a variations seed (the serialized proto bytes) with the specified 82 // Verifies a variations seed (the serialized proto bytes) with the specified
74 // base-64 encoded signature that was received from the server and returns the 83 // base-64 encoded signature that was received from the server and returns the
75 // result. The signature is assumed to be an "ECDSA with SHA-256" signature 84 // result. The signature is assumed to be an "ECDSA with SHA-256" signature
76 // (see kECDSAWithSHA256AlgorithmID in the .cc file). Returns the result of 85 // (see kECDSAWithSHA256AlgorithmID in the .cc file). Returns the result of
77 // signature verification or VARIATIONS_SEED_SIGNATURE_ENUM_SIZE if signature 86 // signature verification or VARIATIONS_SEED_SIGNATURE_ENUM_SIZE if signature
78 // verification is not enabled. 87 // verification is not enabled.
79 virtual VariationsSeedStore::VerifySignatureResult VerifySeedSignature( 88 virtual VariationsSeedStore::VerifySignatureResult VerifySeedSignature(
80 const std::string& seed_bytes, 89 const std::string& seed_bytes,
81 const std::string& base64_seed_signature); 90 const std::string& base64_seed_signature);
82 91
83 private: 92 private:
84 FRIEND_TEST_ALL_PREFIXES(VariationsSeedStoreTest, VerifySeedSignature); 93 FRIEND_TEST_ALL_PREFIXES(VariationsSeedStoreTest, VerifySeedSignature);
94 FRIEND_TEST_ALL_PREFIXES(VariationsSeedStoreTest, ApplyDeltaPatch);
85 95
86 // Clears all prefs related to variations seed storage. 96 // Clears all prefs related to variations seed storage.
87 void ClearPrefs(); 97 void ClearPrefs();
88 98
89 // Reads the variations seed data from prefs; returns true on success. 99 // Reads the variations seed data from prefs; returns true on success.
90 bool ReadSeedData(std::string* seed_data); 100 bool ReadSeedData(std::string* seed_data);
91 101
102 // Internal version of |StoreSeedData()| that assumes |seed_data| is not delta
103 // compressed.
104 bool StoreSeedDataNoDelta(
105 const std::string& seed_data,
106 const std::string& base64_seed_signature,
107 const std::string& country_code,
108 const base::Time& date_fetched,
109 variations::VariationsSeed* parsed_seed);
110
111 // Applies a delta-compressed |patch| to |existing_data|, producing the result
112 // in |output|. Returns whether the operation was successful.
113 static bool ApplyDeltaPatch(const std::string& existing_data,
114 const std::string& patch,
115 std::string* output);
116
92 // The pref service used to persist the variations seed. 117 // The pref service used to persist the variations seed.
93 PrefService* local_state_; 118 PrefService* local_state_;
94 119
95 // Cached serial number from the most recently fetched variations seed. 120 // Cached serial number from the most recently fetched variations seed.
96 std::string variations_serial_number_; 121 std::string variations_serial_number_;
97 122
123 // Whether the most recently fetched variations seed has the country code
124 // field set.
125 bool seed_has_country_code_;
126
98 // Keeps track of an invalid signature. 127 // Keeps track of an invalid signature.
99 std::string invalid_base64_signature_; 128 std::string invalid_base64_signature_;
100 129
101 DISALLOW_COPY_AND_ASSIGN(VariationsSeedStore); 130 DISALLOW_COPY_AND_ASSIGN(VariationsSeedStore);
102 }; 131 };
103 132
104 } // namespace chrome_variations 133 } // namespace chrome_variations
105 134
106 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SEED_STORE_H_ 135 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SEED_STORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698