Slang term, origin unknown from the 1920's in America. Used to underline a failure of an action, or dissapointment in reaching an undesired result, with the additional meaning that the result was not an unexpected one.
A:" Well, I asked Cindy out, and she told me to swallow my head . . "
B:"Hey, that's the way the cookie crumbles!"