This is the story of Shabari, Rama and the half-eaten berries, from the epic Ramayana, a little in detail..
Once there lived a couple named Dhara and her husband Drona, of the Vasus.
They were married for quite sometime, but were still childless. They meditated upon Brahma for sometime to please him.
Impressed with their efforts, Brahma asked them for a boon to which they mentioned that they would like Vishnu as their child.
Brahma blessed them for the same. And thus they became Nanda and Yashoda in their next birth and had a chance to raise Krishna as their son.
As per another legend, the couple actually meditated upon Vishnu himself and managed to get his darshan. When asked for a boon, they mentioned that they wanted him as their son.
However, it was pre-decided that he would be born to Aditi and her incarnations in all of his births too. But he still promised them that they would get a chance to become his parents in their next birth.
And that is why, Krishna was born to Devaki (avatar of Aditi), he was raised by his foster-parents Nanda & Yashoda (reincarnations of Drona & Dhara).