To determine this, the researchers consulted loads of Swedish government-collected data on the 3.4 million citizens over the course of 12 years, including whether or not they registered a dog as a pet (a requirement under Swedish law). They then looked at how many of those people died over that period, their cause of death, and whether or not they were dog owners. Based on that, and after adjusting for things like age and sex, they calculated the risk of death and found that having a canine companion significantly reduced the chance of croaking due to cardiovascular disease or other causes.
Of course, this isn't necessarily definitive proof that anyone who adopts a dog is going to tack on a few extra years, as a report by The Verge makes clear. That's because the study doesn't account for a number of factors that could significantly contribute to the dog owners' longevity, including the amount of exercise they get on average. Also, the study was limited to residents of Sweden -- one of the healthiest countries in the world -- so results may vary considerably in other parts of the globe.