We select a sample of galaxies from the Sloan Digital Sky Survey Data Release 7 (SDSS-DR7) where galaxies are classified, through visual inspection, as hosting strong bars, weak bars or as unbarred galaxies, and make use of HI mass and kinematic information from the Arecibo Legacy Fast ALFA (ALFALFA) survey catalog, to study the stellar, atomic gas and dark matter content of barred disk galaxies. We find, in agreement with previous studies, that the bar fraction increases with increasing stellar mass. A similar trend is found with total baryonic mass, although the dependence is not as strong as with stellar mass, this due to the contribution of gas. The bar fraction shows a decrease with increasing gas mass fraction. This anticorrelation between the likelihood of a galaxy hosting a bar with the gas richness of the galaxy results from the inhibiting effect the gas has in the formation of bars. We also find that for massive galaxies with stellar masses larger than 10$^{10} M_{odot}$, at fixed stellar mass, the bar fraction decreases with increasing global halo mass (i.e. halo mass measured up to a radius of the order of the HI disk extent).