Until the conventions, it is not decided, regardless of the primaries and caucuses. The delegates decide who is going to represent their party. If someone drops out, there is a scramble to pick up those delegates.
From NPR-
Biden must ultimately win the majority of the nearly 4,000 ?pledged? delegates at the DNC ? so, if there?s enough opposition from uncommitted delegates or delegates for other candidates, the president would fall short of winning the nomination in the first round of balloting. That could potentially lead to the political chaos of a brokered convention, which hasn?t happened for either party since 1952.
I have no idea what would happen if he quit after the convention, although there must be rules in place for that as well.
Slate has a good article about the possibilities HERE.