Move PostTaskToMainLoop to base class.

PostTaskToMainLoop has common functionality which can be used
by both child classes, thus move it to base class. Also, make
this virtual incase it needs to be customized in future.