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

Unified Diff: chrome/browser/metrics/variations/variations_seed_store.h

Issue 1271123003: Componentize VariationsSeedStore and its unittest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@componentize_variations_prefs
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/metrics/variations/variations_seed_store.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/metrics/variations/variations_seed_store.h
diff --git a/chrome/browser/metrics/variations/variations_seed_store.h b/chrome/browser/metrics/variations/variations_seed_store.h
deleted file mode 100644
index 0598e908066a0c25751507021c1799fe7498b01c..0000000000000000000000000000000000000000
--- a/chrome/browser/metrics/variations/variations_seed_store.h
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SEED_STORE_H_
-#define CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SEED_STORE_H_
-
-#include <string>
-
-#include "base/compiler_specific.h"
-#include "base/gtest_prod_util.h"
-#include "base/time/time.h"
-
-class PrefService;
-class PrefRegistrySimple;
-
-namespace variations {
-class VariationsSeed;
-}
-
-namespace chrome_variations {
-
-// VariationsSeedStore is a helper class for reading and writing the variations
-// seed from Local State.
-class VariationsSeedStore {
- public:
- explicit VariationsSeedStore(PrefService* local_state);
- virtual ~VariationsSeedStore();
-
- // Loads the variations seed data from local state into |seed|. If there is a
- // problem with loading, the pref value is cleared and false is returned. If
- // successful, |seed| will contain the loaded data and true is returned.
- bool LoadSeed(variations::VariationsSeed* seed);
-
- // Stores the given seed |data| (serialized protobuf) to local state, along
- // with a base64-encoded digital signature for seed and the date when it was
- // fetched. If |is_delta_compressed| is true, treats |data| as being delta
- // compressed and attempts to decode it first using the store's seed data.
- // The actual seed data will be base64 encoded for storage. If the string
- // is invalid, the existing prefs are untouched and false is returned.
- // Additionally, stores the |country_code| that was received with the seed in
- // a separate pref. On success and if |parsed_seed| is not NULL, |parsed_seed|
- // will be filled with the de-serialized decoded protobuf.
- bool StoreSeedData(const std::string& data,
- const std::string& base64_seed_signature,
- const std::string& country_code,
- const base::Time& date_fetched,
- bool is_delta_compressed,
- variations::VariationsSeed* parsed_seed);
-
- // Updates |kVariationsSeedDate| and logs when previous date was from a
- // different day.
- void UpdateSeedDateAndLogDayChange(const base::Time& server_date_fetched);
-
- // Returns the serial number of the last loaded or stored seed.
- const std::string& variations_serial_number() const {
- return variations_serial_number_;
- }
-
- // Returns whether the last loaded or stored seed has the country field set.
- bool seed_has_country_code() const {
- return seed_has_country_code_;
- }
-
- // Returns the invalid signature in base64 format, or an empty string if the
- // signature was valid, missing, or if signature verification is disabled.
- std::string GetInvalidSignature() const;
-
- // Registers Local State prefs used by this class.
- static void RegisterPrefs(PrefRegistrySimple* registry);
-
- protected:
- // Note: UMA histogram enum - don't re-order or remove entries.
- enum VerifySignatureResult {
- VARIATIONS_SEED_SIGNATURE_MISSING,
- VARIATIONS_SEED_SIGNATURE_DECODE_FAILED,
- VARIATIONS_SEED_SIGNATURE_INVALID_SIGNATURE,
- VARIATIONS_SEED_SIGNATURE_INVALID_SEED,
- VARIATIONS_SEED_SIGNATURE_VALID,
- VARIATIONS_SEED_SIGNATURE_ENUM_SIZE,
- };
-
- // Verifies a variations seed (the serialized proto bytes) with the specified
- // base-64 encoded signature that was received from the server and returns the
- // result. The signature is assumed to be an "ECDSA with SHA-256" signature
- // (see kECDSAWithSHA256AlgorithmID in the .cc file). Returns the result of
- // signature verification or VARIATIONS_SEED_SIGNATURE_ENUM_SIZE if signature
- // verification is not enabled.
- virtual VariationsSeedStore::VerifySignatureResult VerifySeedSignature(
- const std::string& seed_bytes,
- const std::string& base64_seed_signature);
-
- private:
- FRIEND_TEST_ALL_PREFIXES(VariationsSeedStoreTest, VerifySeedSignature);
- FRIEND_TEST_ALL_PREFIXES(VariationsSeedStoreTest, ApplyDeltaPatch);
-
- // Clears all prefs related to variations seed storage.
- void ClearPrefs();
-
- // Reads the variations seed data from prefs; returns true on success.
- bool ReadSeedData(std::string* seed_data);
-
- // Internal version of |StoreSeedData()| that assumes |seed_data| is not delta
- // compressed.
- bool StoreSeedDataNoDelta(
- const std::string& seed_data,
- const std::string& base64_seed_signature,
- const std::string& country_code,
- const base::Time& date_fetched,
- variations::VariationsSeed* parsed_seed);
-
- // Applies a delta-compressed |patch| to |existing_data|, producing the result
- // in |output|. Returns whether the operation was successful.
- static bool ApplyDeltaPatch(const std::string& existing_data,
- const std::string& patch,
- std::string* output);
-
- // The pref service used to persist the variations seed.
- PrefService* local_state_;
-
- // Cached serial number from the most recently fetched variations seed.
- std::string variations_serial_number_;
-
- // Whether the most recently fetched variations seed has the country code
- // field set.
- bool seed_has_country_code_;
-
- // Keeps track of an invalid signature.
- std::string invalid_base64_signature_;
-
- DISALLOW_COPY_AND_ASSIGN(VariationsSeedStore);
-};
-
-} // namespace chrome_variations
-
-#endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SEED_STORE_H_
« no previous file with comments | « no previous file | chrome/browser/metrics/variations/variations_seed_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698