There are indeed dogs that are kept specifically for this behaviour. Their job is to act as an alarm and deterrent. In cultures where dogs are routinely kept chained up or penned in small enclosures, that's what they are kept for: to keep people from entering the property and provide an alarm if there's a risk that they will do so. It's not a happy environment for the dog, but that's not the point.
Here's are a couple of blog posts that may help explain this approach to dog ownership and the issues with it, from the Dogstar Foundation, who are a brilliant small charity that work with street dogs and owned dogs in Sri Lanka:
It sounds like the dogs you are encountering are given more freedom than this and are in a first-world country, but the owners may still have the attitude that they wish to encourage barrier protective behaviour to protect their property.
There are dog owners that consider fence running to be 'fun' exercise for their dog. I don't have supporting evidence for that, other than that I've met dog owners in the UK who have told me this. They believe the dog enjoys barking and that the exercise of fence running is stimulating for an active dog that might otherwise be bored.
Here are a couple of articles that explain the different reasons that a dog might be barking:
The division into :
may be useful, but of course with a dog that you don't know well, it can be hard to tell which sort of barking he is doing. In fact, even the owner may well be unclear on that.
As to 'how much is controllable by the owner'- always a vexed question with dog ownership. Ideally, all of it, because even if you have a naturally 'guardy' and active breed such as a border collie or a German Shepherd, the owner should ideally be able to manage the dogs environment so that the dog doesn't spend all day guarding.
For example, when I have fostered rescue border collies and their crosses, I have found that they do have a tendency to want to guard the door from the postman, or race out into the garden barking if they hear someone go by.
I don't consider this appropriate behavior, and my opinion is that it is stressful for the dogs, so I keep an inner door closed so that the dogs cannot see the postman coming or rush right up to the letterbox, and I don't allow unsupervised access to the garden.
Instead, I distract and reward the dogs for the behaviour of NOT barking at passing pedestrians, particularly during the first few days in my house. And of course I walk them a lot in varied environments and play with them, so they do have other things to think about.
Because the dogs are not allowed to be unsupervised in a place where they can easily see and hear pedestrians, they fairly quickly learn how I want them to react. Eventually, like my own sighthounds (which are innately much less guarding-focussed dogs) , they can be allowed outside enjoying the sun without annoying the world with their barking, as they have learned that the behaviour is not permitted, before they are allowed in a situation where they might start practicing it.
This is of course much harder if the dog doesn't get other exercise and stimulation, gets little attention or training, must for some reason be left unsupervised before he has learned what to do, or if you live somewhere where it's simply not possible to manage the excitement because your house is small and there's nowhere available where the dog can't hear traffic, pedestrians etc, so is constantly reacting. In that sort of situation, problem barking can be very difficult for the owner to manage, and retraining will depend on the persistence of the owner and the individual characteristics of the dog.
Here's an article about stress in dogs, which helps explain why I personally don't feel barking is a good way for my dogs to relieve their boredom.