chromium/components/prefs/scoped_user_pref_update.h

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// A helper class that assists preferences in firing notifications when lists
// or dictionaries are changed.

#ifndef COMPONENTS_PREFS_SCOPED_USER_PREF_UPDATE_H_
#define COMPONENTS_PREFS_SCOPED_USER_PREF_UPDATE_H_

#include <string>
#include <string_view>

#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/sequence_checker.h"
#include "base/values.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/prefs_export.h"

class PrefService;

namespace subtle {

// Base class for ScopedUserPrefUpdateTemplate that contains the parts
// that do not depend on ScopedUserPrefUpdateTemplate's template parameter.
//
// We need this base class mostly for making it a friend of PrefService
// and getting access to PrefService::GetMutableUserPref and
// PrefService::ReportUserPrefChanged.
class COMPONENTS_PREFS_EXPORT ScopedUserPrefUpdateBase {};

}  // namespace subtle

// Class to support modifications to base::Value::Dicts while guaranteeing
// that PrefObservers are notified of changed values.
//
// This class may only be used on the UI thread as it requires access to the
// PrefService.
class COMPONENTS_PREFS_EXPORT ScopedDictPrefUpdate
    : public subtle::ScopedUserPrefUpdateBase {};

// Class to support modifications to base::Value::Lists while guaranteeing
// that PrefObservers are notified of changed values.
//
// This class may only be used on the UI thread as it requires access to the
// PrefService.
class COMPONENTS_PREFS_EXPORT ScopedListPrefUpdate
    : public subtle::ScopedUserPrefUpdateBase {};

#endif  // COMPONENTS_PREFS_SCOPED_USER_PREF_UPDATE_H_