Response theory for time-resolved second-harmonic generation and two-photon photoemission