Skip to content

Commit

Permalink
wsd: preset: failed to cache browsersetting json
Browse files Browse the repository at this point in the history
Signed-off-by: Rashesh <[email protected]>
Change-Id: If08d4caeab1917bdf604c39bef224b6471317d9b
  • Loading branch information
Rash419 authored and caolanm committed Jan 27, 2025
1 parent 97d1664 commit 3a71de1
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions wsd/DocumentBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1572,32 +1572,15 @@ class PresetsInstallTask
std::string fileName;
if (groupName == "xcu")
fileName = Poco::Path(destDir.toString(), "config.xcu").toString();
else if (groupName == "browsersetting")
fileName = Poco::Path(destDir.toString(), "browsersetting.json").toString();
else
fileName = Poco::Path(destDir.toString(), Uri::getFilenameWithExtFromURL(uri)).toString();

queries.emplace_back(uri, stamp, fileName);
}
}

void addBrowserSetting(Poco::JSON::Object::Ptr settings, std::vector<CacheQuery>& queries)
{
if (!settings->has("browsersetting"))
return;

auto browsersetting = settings->get("browsersetting").extract<Poco::JSON::Array::Ptr>();
if (browsersetting->empty())
return;

auto firstElem = browsersetting->get(0).extract<Poco::JSON::Object::Ptr>();
if (!firstElem)
return;

const std::string uri = JsonUtil::getJSONValue<std::string>(firstElem, "uri");
const std::string stamp = JsonUtil::getJSONValue<std::string>(firstElem, "stamp");

queries.emplace_back(uri, stamp, "browsersetting.json");
}

public:
PresetsInstallTask(SocketPoll& poll, const std::string& configId,
const std::string& presetsPath,
Expand Down Expand Up @@ -1630,7 +1613,7 @@ class PresetsInstallTask
_overallSuccess = false;
else
{
addBrowserSetting(settings, presets);
addGroup(settings, "browsersetting", presets);
addGroup(settings, "autotext", presets);
addGroup(settings, "wordbook", presets);
addGroup(settings, "xcu", presets);
Expand Down Expand Up @@ -1734,9 +1717,10 @@ void DocumentBroker::sendBrowserSetting(const std::shared_ptr<ClientSession>& se
std::ostringstream jsonStream;
browsersetting->stringify(jsonStream, 2);
const std::string& jsonStr = jsonStream.str();
LOG_TRC("Sending browsersetting json[" << jsonStr << ']');
session->sendTextFrame("browsersetting: " + jsonStr);
session->setSentBrowserSetting(true);
LOG_TRC("Sent browsersetting json[" << jsonStr << "] to client with sessionId["
<< session->getId() << ']');
}

void DocumentBroker::getBrowserSettingSync(const std::shared_ptr<ClientSession>& session,
Expand Down Expand Up @@ -1895,8 +1879,12 @@ void DocumentBroker::asyncInstallPreset(
{
success = true;
LOG_INF("Fetch of preset uri[" << uriAnonym << "] to " << presetFile << " succeeded");

Cache::cacheConfigFile(configId, presetUri, presetStamp, presetFile);

// delete the browsersetting json from jail
// we only saved it to make sure cache util can copy it
if (presetFile.ends_with("browsersetting.json"))
FileUtil::removeFile(presetFile);
}

if (finishedCB)
Expand All @@ -1917,7 +1905,6 @@ void DocumentBroker::asyncInstallPreset(
const std::string& body = presetHttpResponse->getBody();
DocumentBroker::parseBrowserSettings(session, body);
DocumentBroker::sendBrowserSetting(session);
return;
}
presetHttpResponse->saveBodyToFile(presetFile);
}
Expand Down

0 comments on commit 3a71de1

Please sign in to comment.