Skip to content

Commit

Permalink
Add GetPersistentSetting() to h5vcc_settings. (youtube#1969)
Browse files Browse the repository at this point in the history
Add a persistent settings getter to validate set persistent h5vcc
settings. The getter is a string getter that maps to the various types
that allows for empty string returns when the getter fails.

b/305057554
  • Loading branch information
briantting authored and Rongo-JL committed Dec 19, 2023
1 parent a561a85 commit ae2bba7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cobalt/h5vcc/h5vcc_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,22 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const {
return false;
}

void H5vccSettings::SetPersistentSettingAsInt(const std::string& key,
int value) const {
if (persistent_settings_) {
persistent_settings_->SetPersistentSetting(
key, std::make_unique<base::Value>(value));
}
}

int H5vccSettings::GetPersistentSettingAsInt(const std::string& key,
int default_setting) const {
if (persistent_settings_) {
return persistent_settings_->GetPersistentSettingAsInt(key,
default_setting);
}
return default_setting;
}

} // namespace h5vcc
} // namespace cobalt
5 changes: 5 additions & 0 deletions cobalt/h5vcc/h5vcc_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class H5vccSettings : public script::Wrappable {
// invalid or not set to the expected value.
bool Set(const std::string& name, SetValueType value) const;

void SetPersistentSettingAsInt(const std::string& key, int value) const;

int GetPersistentSettingAsInt(const std::string& key,
int default_setting) const;

DEFINE_WRAPPABLE_TYPE(H5vccSettings);

private:
Expand Down
2 changes: 2 additions & 0 deletions cobalt/h5vcc/h5vcc_settings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@

interface H5vccSettings {
boolean set(DOMString name, (long or DOMString) value);
void setPersistentSettingAsInt(DOMString name, long value);
long getPersistentSettingAsInt(DOMString name, long default_setting);
};

0 comments on commit ae2bba7

Please sign in to comment.