Commit 6f3cd908 authored by guidou's avatar guidou Committed by Commit bot

Revert of Integrate registry_hash_store_contents with the rest of tracked...

Revert of Integrate registry_hash_store_contents with the rest of tracked prefs. (patchset #24 id:460001 of https://codereview.chromium.org/2204943002/ )

Reason for revert:
This CL is suspect of breaking WebRTC Windows bots.
I will reland if it doesn't fix the problem.

See, for example, https://build.chromium.org/p/chromium.webrtc/builders/Win7%20Tester/builds/30007/steps/browser_tests/logs/stdio

[4936:6236:0930/181348:INFO:webrtc_video_quality_browsertest.cc(245)] Running "C:\b\depot_tools\python276_bin\python.exe" -u "C:\b\c\b\Win7_Tester\src\third_party/webrtc/tools/compare_videos.py" --label=720p_VP9 --ref_video "C:\b\c\b\Win7_Tester\src\chrome\test\data\webrtc/resources\reference_video_1280x720_30fps.yuv" --test_video "C:\Users\CHROME~1.LAB\AppData\Local\Temp\scoped_dir4936_9527\captured_video.yuv" --frame_analyzer "C:\b\c\b\Win7_Tester\src\out\Release\frame_analyzer.exe" --yuv_frame_width 1280 --yuv_frame_height 720 --zxing_path "C:\b\c\b\Win7_Tester\src\chrome\test\data\webrtc/resources\tools\win\zxing.exe" --ffmpeg_path "C:\b\c\b\Win7_Tester\src\chrome\test\data\webrtc/resources\tools\win\ffmpeg.exe" --stats_file "C:\Users\CHROME~1.LAB\AppData\Local\Temp\scoped_dir4936_9527\stats.txt"
[4936:6236:0930/181420:INFO:user_input_monitor_win.cc(171)] RegisterRawInputDevices() failed for RIDEV_REMOVE: The parameter is incorrect. (0x57)
[4936:6236:0930/181421:FATAL:json_pref_store.cc(385)] Check failed: !has_pending_write_callbacks_.
Backtrace:
	base::debug::StackTrace::StackTrace [0x02BA3CF7+23]
	logging::LogMessage::~LogMessage [0x02B5B061+49]
	JsonPrefStore::RegisterOnNextWriteSynchronousCallbacks [0x03668FDF+154]
	JsonPrefStore::SerializeData [0x03669601+179]
	base::ImportantFileWriter::DoScheduledWrite [0x02BE4B15+149]
	JsonPrefStore::CommitPendingWrite [0x0366803E+120]
	JsonPrefStore::~JsonPrefStore [0x03667DF8+21]
	scoped_refptr<TestingPrefStore>::Release [0x056591C1+23]
	SegregatedPrefStore::~SegregatedPrefStore [0x04359463+95]
	scoped_refptr<TestingPrefStore>::Release [0x056591C1+23]
	PrefService::~PrefService [0x03663ED9+141]
	syncable_prefs::PrefServiceSyncable::~PrefServiceSyncable [0x04088703+93]
	syncable_prefs::PrefServiceSyncable::`scalar deleting destructor' [0x04088714+11]
	ProfileImpl::~ProfileImpl [0x02C5706B+271]
	ProfileDestroyer::DestroyProfileWhenAppropriate [0x02D1A381+484]
	ProfileManager::ProfileInfo::~ProfileInfo [0x02C04D62+14]
	std::_Tree<std::_Tmap_traits<base::FilePath,linked_ptr<ProfileManager::ProfileInfo>,std::less<base::FilePath>,std::allocator<std::pair<base::FilePath const ,linked_ptr<ProfileManager::ProfileInfo> > >,0> >::_Erase [0x02B54889+41]
	std::_Tree<std::_Tmap_traits<base::FilePath,linked_ptr<ProfileManager::ProfileInfo>,std::less<base::FilePath>,std::allocator<std::pair<base::FilePath const ,linked_ptr<ProfileManager::ProfileInfo> > >,0> >::clear [0x02B548B2+13]
	std::_Tree<std::_Tmap_traits<base::FilePath,linked_ptr<ProfileManager::ProfileInfo>,std::less<base::FilePath>,std::allocator<std::pair<base::FilePath const ,linked_ptr<ProfileManager::ProfileInfo> > >,0> >::~_Tree<std::_Tmap_traits<base::FilePath,linked_p [0x02C04D0E+21]
	ProfileManager::~ProfileManager [0x02C04DAF+54]
	BrowserProcessImpl::StartTearDown [0x02DD70E9+458]
	ChromeBrowserMainParts::PostMainMessageLoopRun [0x02E333B0+304]
	content::BrowserMainLoop::ShutdownThreadsAndCleanUp [0x024E327A+350]
	content::BrowserMainRunnerImpl::Shutdown [0x024E4498+632]
	content::BrowserMain [0x024DFE41+139]
	content::RunNamedProcessTypeMain [0x02B46FAB+206]
	content::ContentMainRunnerImpl::Run [0x02B46EAC+274]
	content::ContentMain [0x02B46275+35]
	content::BrowserTestBase::SetUp [0x02F73565+964]
	InProcessBrowserTest::SetUp [0x02BF45D7+268]
	testing::internal::HandleExceptionsInMethodIfSupported<testing::TestCase,void> [0x033F7AB9+32]
	testing::Test::Run [0x033FEAA3+51]
	testing::TestCase::Run [0x033FEB79+133]
	testing::internal::UnitTestImpl::RunAllTests [0x033FEEF8+433]
	testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl,bool> [0x033F7AFD+32]
	testing::UnitTest::Run [0x033FED22+133]
	base::TestSuite::Run [0x02BFD110+95]
	ChromeTestSuiteRunner::RunTestSuite [0x052456CE+40]
	content::LaunchTests [0x02F6D485+585]
	LaunchChromeTests [0x052456A1+49]
	main [0x052454BA+63]
	__scrt_common_main_seh [0x0520AD1F+249] (f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253)
	BaseThreadInitThunk [0x75A0338A+18]
	RtlInitializeExceptionChain [0x77899902+99]
	RtlInitializeExceptionChain [0x778998D5+54]

Original issue's description:
> Integrate registry_hash_store_contents with the rest of tracked prefs.
>
> This change adds Windows-only logic to the PrefHashFilter such that it
> verifies preferences against MACs stored in the registry. Unlike the
> current tracked preference logic, this extra check does NOT reset
> settings.
>
> To avoid inconsistent state with the MACs in secure_preferences, we
> clear the registry MACs before writing secure_preferences, and write
> the registry MACs after the file is successfully written.
>
> BUG=624858
>
> Committed: https://crrev.com/4683dfcecfa72a73e00498d7c06fcf6716f8366c
> Cr-Commit-Position: refs/heads/master@{#422240}

TBR=gab@chromium.org,proberge@chromium.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=624858

Review-Url: https://codereview.chromium.org/2396443002
Cr-Commit-Position: refs/heads/master@{#422738}
parent e6b67c20
......@@ -11,7 +11,6 @@
#include "base/files/file_util.h"
#include "base/json/json_file_value_serializer.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/sequenced_task_runner.h"
#include "build/build_config.h"
......@@ -24,11 +23,6 @@
#include "components/user_prefs/tracked/segregated_pref_store.h"
#include "components/user_prefs/tracked/tracked_preferences_migration.h"
#if defined(OS_WIN)
#include "chrome/installer/util/browser_distribution.h"
#include "components/user_prefs/tracked/registry_hash_store_contents_win.h"
#endif
namespace {
void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store,
......@@ -39,13 +33,6 @@ void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store,
}
}
#if defined(OS_WIN)
// Forces a different registry key to be used for storing preference validation
// MACs. See |SetPreferenceValidationRegistryPathForTesting|.
const base::string16* g_preference_validation_registry_path_for_testing =
nullptr;
#endif // OS_WIN
} // namespace
// Preference tracking and protection is not required on platforms where other
......@@ -90,15 +77,6 @@ void ProfilePrefStoreManager::ClearResetTime(PrefService* pref_service) {
PrefHashFilter::ClearResetTime(pref_service);
}
#if defined(OS_WIN)
// static
void ProfilePrefStoreManager::SetPreferenceValidationRegistryPathForTesting(
const base::string16* path) {
DCHECK(!path->empty());
g_preference_validation_registry_path_for_testing = path;
}
#endif // OS_WIN
PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore(
const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
const base::Closure& on_reset_on_load,
......@@ -130,14 +108,12 @@ PersistentPrefStore* ProfilePrefStoreManager::CreateProfilePrefStore(
}
std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter(
new PrefHashFilter(GetPrefHashStore(false),
GetExternalVerificationPrefHashStorePair(),
unprotected_configuration, base::Closure(),
validation_delegate, reporting_ids_count_, false));
new PrefHashFilter(GetPrefHashStore(false), unprotected_configuration,
base::Closure(), validation_delegate,
reporting_ids_count_, false));
std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter(
GetPrefHashStore(true), GetExternalVerificationPrefHashStorePair(),
protected_configuration, on_reset_on_load, validation_delegate,
reporting_ids_count_, true));
GetPrefHashStore(true), protected_configuration, on_reset_on_load,
validation_delegate, reporting_ids_count_, true));
PrefHashFilter* raw_unprotected_pref_hash_filter =
unprotected_pref_hash_filter.get();
......@@ -183,10 +159,11 @@ bool ProfilePrefStoreManager::InitializePrefsFromMasterPrefs(
copy.reset(master_prefs.DeepCopy());
to_serialize = copy.get();
PrefHashFilter(GetPrefHashStore(false),
GetExternalVerificationPrefHashStorePair(),
tracking_configuration_, base::Closure(), NULL,
reporting_ids_count_, false)
.Initialize(copy.get());
tracking_configuration_,
base::Closure(),
NULL,
reporting_ids_count_,
false).Initialize(copy.get());
}
// This will write out to a single combined file which will be immediately
......@@ -212,23 +189,3 @@ std::unique_ptr<PrefHashStore> ProfilePrefStoreManager::GetPrefHashStore(
return std::unique_ptr<PrefHashStore>(
new PrefHashStoreImpl(seed_, device_id_, use_super_mac));
}
std::pair<std::unique_ptr<PrefHashStore>, std::unique_ptr<HashStoreContents>>
ProfilePrefStoreManager::GetExternalVerificationPrefHashStorePair() {
DCHECK(kPlatformSupportsPreferenceTracking);
#if defined(OS_WIN)
return std::make_pair(
base::MakeUnique<PrefHashStoreImpl>(
"ChromeRegistryHashStoreValidationSeed", device_id_,
false /* use_super_mac */),
g_preference_validation_registry_path_for_testing
? base::MakeUnique<RegistryHashStoreContentsWin>(
*g_preference_validation_registry_path_for_testing,
profile_path_.BaseName().LossyDisplayName())
: base::MakeUnique<RegistryHashStoreContentsWin>(
BrowserDistribution::GetDistribution()->GetRegistryPath(),
profile_path_.BaseName().LossyDisplayName()));
#else
return std::make_pair(nullptr, nullptr);
#endif
}
......@@ -16,7 +16,6 @@
#include "base/memory/ref_counted.h"
#include "components/user_prefs/tracked/pref_hash_filter.h"
class HashStoreContents;
class PersistentPrefStore;
class PrefHashStore;
class PrefService;
......@@ -71,14 +70,6 @@ class ProfilePrefStoreManager {
// was built by ProfilePrefStoreManager.
static void ClearResetTime(PrefService* pref_service);
#if defined(OS_WIN)
// Call before startup tasks kick in to use a different registry path for
// storing and validating tracked preference MACs. Callers are responsible
// for ensuring that the key is deleted on shutdown. For testing only.
static void SetPreferenceValidationRegistryPathForTesting(
const base::string16* path);
#endif
// Creates a PersistentPrefStore providing access to the user preferences of
// the managed profile. If |on_reset| is provided, it will be invoked if a
// reset occurs as a result of loading the profile's prefs.
......@@ -108,12 +99,6 @@ class ProfilePrefStoreManager {
// TrustedInitialized).
std::unique_ptr<PrefHashStore> GetPrefHashStore(bool use_super_mac);
// Returns a PrefHashStore and HashStoreContents which can be be used for
// extra out-of-band verifications, or nullptrs if not available on this
// platform.
std::pair<std::unique_ptr<PrefHashStore>, std::unique_ptr<HashStoreContents>>
GetExternalVerificationPrefHashStorePair();
const base::FilePath profile_path_;
const std::vector<PrefHashFilter::TrackedPreferenceMetadata>
tracking_configuration_;
......
......@@ -28,16 +28,6 @@ void DictionaryHashStoreContents::RegisterProfilePrefs(
registry->RegisterStringPref(kSuperMACPref, std::string());
}
bool DictionaryHashStoreContents::IsCopyable() const {
return false;
}
std::unique_ptr<HashStoreContents> DictionaryHashStoreContents::MakeCopy()
const {
NOTREACHED() << "DictionaryHashStoreContents does not support MakeCopy";
return nullptr;
}
base::StringPiece DictionaryHashStoreContents::GetUMASuffix() const {
// To stay consistent with existing reported data, do not append a suffix
// when reporting UMA stats for this content.
......@@ -131,4 +121,4 @@ base::DictionaryValue* DictionaryHashStoreContents::GetMutableContents(
storage_->Set(kPreferenceMACs, macs_dict);
}
return macs_dict;
}
}
\ No newline at end of file
......@@ -31,8 +31,6 @@ class DictionaryHashStoreContents : public HashStoreContents {
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
// HashStoreContents implementation
bool IsCopyable() const override;
std::unique_ptr<HashStoreContents> MakeCopy() const override;
base::StringPiece GetUMASuffix() const override;
void Reset() override;
bool GetMac(const std::string& path, std::string* out_value) override;
......
......@@ -26,15 +26,6 @@ class HashStoreContents {
public:
virtual ~HashStoreContents() {}
// Returns true if this implementation of HashStoreContents can be copied via
// MakeCopy().
virtual bool IsCopyable() const = 0;
// Returns a copy of this HashStoreContents. Must only be called on
// lightweight implementations (which return true from IsCopyable()) and only
// in scenarios where a copy cannot be avoided.
virtual std::unique_ptr<HashStoreContents> MakeCopy() const = 0;
// Returns the suffix to be appended to UMA histograms for this store type.
// The returned value must either be an empty string or one of the values in
// histograms.xml's TrackedPreferencesExternalValidators.
......
......@@ -15,10 +15,7 @@
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/containers/scoped_ptr_hash_map.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/optional.h"
#include "components/user_prefs/tracked/hash_store_contents.h"
#include "components/user_prefs/tracked/interceptable_pref_filter.h"
#include "components/user_prefs/tracked/tracked_preference.h"
......@@ -67,9 +64,6 @@ class PrefHashFilter : public InterceptablePrefFilter {
ValueType value_type;
};
using StoreContentsPair = std::pair<std::unique_ptr<PrefHashStore>,
std::unique_ptr<HashStoreContents>>;
// Constructs a PrefHashFilter tracking the specified |tracked_preferences|
// using |pref_hash_store| to check/store hashes. An optional |delegate| is
// notified of the status of each preference as it is checked.
......@@ -79,11 +73,8 @@ class PrefHashFilter : public InterceptablePrefFilter {
// than |tracked_preferences.size()|). If |report_super_mac_validity| is true,
// the state of the super MAC will be reported via UMA during
// FinalizeFilterOnLoad.
// |external_validation_hash_store_pair_| will be used (if non-null) to
// perform extra validations without triggering resets.
PrefHashFilter(
std::unique_ptr<PrefHashStore> pref_hash_store,
StoreContentsPair external_validation_hash_store_pair_,
const std::vector<TrackedPreferenceMetadata>& tracked_preferences,
const base::Closure& on_reset_on_load,
TrackedPreferenceValidationDelegate* delegate,
......@@ -120,25 +111,6 @@ class PrefHashFilter : public InterceptablePrefFilter {
std::unique_ptr<base::DictionaryValue> pref_store_contents,
bool prefs_altered) override;
// Helper function to generate FilterSerializeData()'s pre-write and
// post-write callbacks. The returned callbacks are thread-safe.
OnWriteCallbackPair GetOnWriteSynchronousCallbacks(
base::DictionaryValue* pref_store_contents);
// Clears the MACs contained in |external_validation_hash_store_contents|
// which are present in |paths_to_clear|.
static void ClearFromExternalStore(
HashStoreContents* external_validation_hash_store_contents,
const base::DictionaryValue* changed_paths_and_macs);
// Flushes the MACs contained in |changed_paths_and_mac| to
// external_hash_store_contents if |write_success|, otherwise discards the
// changes.
static void FlushToExternalStore(
std::unique_ptr<HashStoreContents> external_hash_store_contents,
std::unique_ptr<base::DictionaryValue> changed_paths_and_macs,
bool write_success);
// Callback to be invoked only once (and subsequently reset) on the next
// FilterOnLoad event. It will be allowed to modify the |prefs| handed to
// FilterOnLoad before handing them back to this PrefHashFilter.
......@@ -149,18 +121,12 @@ class PrefHashFilter : public InterceptablePrefFilter {
typedef base::ScopedPtrHashMap<std::string,
std::unique_ptr<TrackedPreference>>
TrackedPreferencesMap;
// A map from changed paths to their corresponding TrackedPreferences (which
// aren't owned by this map).
typedef std::map<std::string, const TrackedPreference*> ChangedPathsMap;
std::unique_ptr<PrefHashStore> pref_hash_store_;
// A store and contents on which to perform extra validations without
// triggering resets.
// Will be null if the platform does not support external validation.
const base::Optional<StoreContentsPair> external_validation_hash_store_pair_;
// Invoked if a reset occurs in a call to FilterOnLoad.
const base::Closure on_reset_on_load_;
......
......@@ -12,7 +12,6 @@
#include "components/user_prefs/tracked/pref_hash_store_transaction.h"
class HashStoreContents;
class PrefHashStoreTransaction;
// Holds the configuration and implementation used to calculate and verify
// preference MACs.
......
......@@ -7,7 +7,6 @@
#include <windows.h>
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
......@@ -20,7 +19,7 @@ using base::win::RegistryValueIterator;
namespace {
constexpr size_t kMacSize = 64;
constexpr size_t kMacSize = 32;
base::string16 GetSplitPrefKeyName(const base::string16& reg_key_name,
const std::string& split_key_name) {
......@@ -73,18 +72,6 @@ RegistryHashStoreContentsWin::RegistryHashStoreContentsWin(
const base::string16& store_key)
: preference_key_name_(registry_path + L"\\PreferenceMACs\\" + store_key) {}
RegistryHashStoreContentsWin::RegistryHashStoreContentsWin(
const RegistryHashStoreContentsWin& other) = default;
bool RegistryHashStoreContentsWin::IsCopyable() const {
return true;
}
std::unique_ptr<HashStoreContents> RegistryHashStoreContentsWin::MakeCopy()
const {
return base::WrapUnique(new RegistryHashStoreContentsWin(*this));
}
base::StringPiece RegistryHashStoreContentsWin::GetUMASuffix() const {
return user_prefs::tracked::kTrackedPrefRegistryValidationSuffix;
}
......@@ -154,6 +141,7 @@ void RegistryHashStoreContentsWin::SetSplitMac(const std::string& path,
}
bool RegistryHashStoreContentsWin::RemoveEntry(const std::string& path) {
// ClearSplitMac is first to avoid short-circuit issues.
return ClearAtomicMac(preference_key_name_, path) ||
ClearSplitMac(preference_key_name_, path);
}
......@@ -161,22 +149,22 @@ bool RegistryHashStoreContentsWin::RemoveEntry(const std::string& path) {
void RegistryHashStoreContentsWin::ImportEntry(const std::string& path,
const base::Value* in_value) {
NOTREACHED()
<< "RegistryHashStoreContents does not support the ImportEntry operation";
<< "RegistryHashStore does not support the ImportEntry operation";
}
const base::DictionaryValue* RegistryHashStoreContentsWin::GetContents() const {
NOTREACHED()
<< "RegistryHashStoreContents does not support the GetContents operation";
<< "RegistryHashStore does not support the GetContents operation";
return NULL;
}
std::string RegistryHashStoreContentsWin::GetSuperMac() const {
NOTREACHED()
<< "RegistryHashStoreContents does not support the GetSuperMac operation";
<< "RegistryHashStore does not support the GetSuperMac operation";
return NULL;
}
void RegistryHashStoreContentsWin::SetSuperMac(const std::string& super_mac) {
NOTREACHED()
<< "RegistryHashStoreContents does not support the SetSuperMac operation";
<< "RegistryHashStore does not support the SetSuperMac operation";
}
......@@ -18,8 +18,6 @@ class RegistryHashStoreContentsWin : public HashStoreContents {
const base::string16& store_key);
// HashStoreContents overrides:
bool IsCopyable() const override;
std::unique_ptr<HashStoreContents> MakeCopy() const override;
base::StringPiece GetUMASuffix() const override;
void Reset() override;
bool GetMac(const std::string& path, std::string* out_value) override;
......@@ -39,11 +37,9 @@ class RegistryHashStoreContentsWin : public HashStoreContents {
void SetSuperMac(const std::string& super_mac) override;
private:
// Helper constructor for |MakeCopy|.
explicit RegistryHashStoreContentsWin(
const RegistryHashStoreContentsWin& other);
const base::string16 preference_key_name_;
DISALLOW_COPY_AND_ASSIGN(RegistryHashStoreContentsWin);
};
#endif // COMPONENTS_USER_PREFS_TRACKED_PREF_REGISTRY_HASH_STORE_CONTENTS_H_
......@@ -16,11 +16,9 @@ namespace {
constexpr base::char16 kRegistryPath[] = L"Foo\\TestStore";
constexpr base::char16 kStoreKey[] = L"test_store_key";
// Hex-encoded MACs are 64 characters long.
constexpr char kTestStringA[] =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
constexpr char kTestStringB[] =
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
// MACs are 32 characters long.
constexpr char kTestStringA[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
constexpr char kTestStringB[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
constexpr char kAtomicPrefPath[] = "path1";
constexpr char kSplitPrefPath[] = "extension";
......@@ -116,4 +114,4 @@ TEST_F(RegistryHashStoreContentsWinTest, TestReset) {
split_macs.clear();
EXPECT_FALSE(contents->GetSplitMacs(kSplitPrefPath, &split_macs));
EXPECT_EQ(0U, split_macs.size());
}
}
\ No newline at end of file
......@@ -24,10 +24,6 @@ TrackedAtomicPreference::TrackedAtomicPreference(
delegate_(delegate) {
}
TrackedPreferenceType TrackedAtomicPreference::GetType() const {
return TrackedPreferenceType::ATOMIC;
}
void TrackedAtomicPreference::OnNewValue(
const base::Value* value,
PrefHashStoreTransaction* transaction) const {
......@@ -36,32 +32,20 @@ void TrackedAtomicPreference::OnNewValue(
bool TrackedAtomicPreference::EnforceAndReport(
base::DictionaryValue* pref_store_contents,
PrefHashStoreTransaction* transaction,
PrefHashStoreTransaction* external_validation_transaction) const {
PrefHashStoreTransaction* transaction) const {
const base::Value* value = NULL;
pref_store_contents->Get(pref_path_, &value);
PrefHashStoreTransaction::ValueState value_state =
transaction->CheckValue(pref_path_, value);
helper_.ReportValidationResult(value_state, transaction->GetStoreUMASuffix());
PrefHashStoreTransaction::ValueState external_validation_value_state =
PrefHashStoreTransaction::UNCHANGED;
if (external_validation_transaction) {
external_validation_value_state =
external_validation_transaction->CheckValue(pref_path_, value);
helper_.ReportValidationResult(
external_validation_value_state,
external_validation_transaction->GetStoreUMASuffix());
// TODO(proberge): Call delegate_->OnAtomicPreferenceValidation.
}
helper_.ReportValidationResult(value_state, transaction->GetStoreUMASuffix());
TrackedPreferenceHelper::ResetAction reset_action =
helper_.GetAction(value_state);
if (delegate_) {
delegate_->OnAtomicPreferenceValidation(pref_path_, value, value_state,
helper_.IsPersonal());
}
TrackedPreferenceHelper::ResetAction reset_action =
helper_.GetAction(value_state);
helper_.ReportAction(reset_action);
bool was_reset = false;
......@@ -77,16 +61,5 @@ bool TrackedAtomicPreference::EnforceAndReport(
transaction->StoreHash(pref_path_, new_value);
}
// Update MACs in the external store if there is one and there either was a
// reset or external validation failed.
if (external_validation_transaction &&
(was_reset ||
external_validation_value_state !=
PrefHashStoreTransaction::UNCHANGED)) {
const base::Value* new_value = nullptr;
pref_store_contents->Get(pref_path_, &new_value);
external_validation_transaction->StoreHash(pref_path_, new_value);
}
return was_reset;
}
......@@ -30,13 +30,10 @@ class TrackedAtomicPreference : public TrackedPreference {
TrackedPreferenceValidationDelegate* delegate);
// TrackedPreference implementation.
TrackedPreferenceType GetType() const override;
void OnNewValue(const base::Value* value,
PrefHashStoreTransaction* transaction) const override;
bool EnforceAndReport(
base::DictionaryValue* pref_store_contents,
PrefHashStoreTransaction* transaction,
PrefHashStoreTransaction* external_validation_transaction) const override;
bool EnforceAndReport(base::DictionaryValue* pref_store_contents,
PrefHashStoreTransaction* transaction) const override;
private:
const std::string pref_path_;
......
......@@ -12,16 +12,12 @@ class DictionaryValue;
class Value;
}
enum class TrackedPreferenceType { ATOMIC, SPLIT };
// A TrackedPreference tracks changes to an individual preference, reporting and
// reacting to them according to preference-specific and browser-wide policies.
class TrackedPreference {
public:
virtual ~TrackedPreference() {}
virtual TrackedPreferenceType GetType() const = 0;
// Notifies the underlying TrackedPreference about its new |value| which
// can update hashes in the corresponding hash store via |transaction|.
virtual void OnNewValue(const base::Value* value,
......@@ -31,14 +27,10 @@ class TrackedPreference {
// is valid. Responds to verification failures according to
// preference-specific and browser-wide policy and reports results to via UMA.
// May use |transaction| to check/modify hashes in the corresponding hash
// store. Performs validation and reports results without enforcing for
// |external_validation_transaction|. This call assumes exclusive access to
// |external_validation_transaction| and its associated state and as such
// should only be called before any other subsystem is made aware of it.
// store.
virtual bool EnforceAndReport(
base::DictionaryValue* pref_store_contents,
PrefHashStoreTransaction* transaction,
PrefHashStoreTransaction* external_validation_transaction) const = 0;
PrefHashStoreTransaction* transaction) const = 0;
};
#endif // COMPONENTS_USER_PREFS_TRACKED_TRACKED_PREFERENCE_H_
......@@ -27,10 +27,6 @@ TrackedSplitPreference::TrackedSplitPreference(
delegate_(delegate) {
}
TrackedPreferenceType TrackedSplitPreference::GetType() const {
return TrackedPreferenceType::SPLIT;
}
void TrackedSplitPreference::OnNewValue(
const base::Value* value,
PrefHashStoreTransaction* transaction) const {
......@@ -44,8 +40,7 @@ void TrackedSplitPreference::OnNewValue(
bool TrackedSplitPreference::EnforceAndReport(
base::DictionaryValue* pref_store_contents,
PrefHashStoreTransaction* transaction,
PrefHashStoreTransaction* external_validation_transaction) const {
PrefHashStoreTransaction* transaction) const {
base::DictionaryValue* dict_value = NULL;
if (!pref_store_contents->GetDictionary(pref_path_, &dict_value) &&
pref_store_contents->Get(pref_path_, NULL)) {
......@@ -63,26 +58,12 @@ bool TrackedSplitPreference::EnforceAndReport(
helper_.ReportValidationResult(value_state, transaction->GetStoreUMASuffix());
PrefHashStoreTransaction::ValueState external_validation_value_state =
PrefHashStoreTransaction::UNCHANGED;
if (external_validation_transaction) {
std::vector<std::string> invalid_external_validation_keys;
external_validation_value_state =
external_validation_transaction->CheckSplitValue(
pref_path_, dict_value, &invalid_external_validation_keys);
helper_.ReportValidationResult(
external_validation_value_state,
external_validation_transaction->GetStoreUMASuffix());
// TODO(proberge): Call delegate_->OnSplitPreferenceValidation.
}
TrackedPreferenceHelper::ResetAction reset_action =
helper_.GetAction(value_state);
if (delegate_) {
delegate_->OnSplitPreferenceValidation(pref_path_, dict_value, invalid_keys,
value_state, helper_.IsPersonal());
}
TrackedPreferenceHelper::ResetAction reset_action =
helper_.GetAction(value_state);
helper_.ReportAction(reset_action);
bool was_reset = false;
......@@ -107,16 +88,5 @@ bool TrackedSplitPreference::EnforceAndReport(
transaction->StoreSplitHash(pref_path_, new_dict_value);
}
// Update MACs in the external store if there is one and there either was a
// reset or external validation failed.
if (external_validation_transaction &&
(was_reset ||
external_validation_value_state !=
PrefHashStoreTransaction::UNCHANGED)) {
const base::DictionaryValue* new_dict_value = nullptr;
pref_store_contents->GetDictionary(pref_path_, &new_dict_value);
external_validation_transaction->StoreSplitHash(pref_path_, new_dict_value);
}
return was_reset;
}
......@@ -33,13 +33,10 @@ class TrackedSplitPreference : public TrackedPreference {
TrackedPreferenceValidationDelegate* delegate);
// TrackedPreference implementation.
TrackedPreferenceType GetType() const override;
void OnNewValue(const base::Value* value,
PrefHashStoreTransaction* transaction) const override;
bool EnforceAndReport(
base::DictionaryValue* pref_store_contents,
PrefHashStoreTransaction* transaction,
PrefHashStoreTransaction* external_validation_transaction) const override;
bool EnforceAndReport(base::DictionaryValue* pref_store_contents,
PrefHashStoreTransaction* transaction) const override;
private:
const std::string pref_path_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment