The problem with saying "you should only do this when" is that such a phrase is inherently arbitrary. The reality is that people have varying degrees of tolerance for foul language, including myself. For example:
I typically have no issue with the f-word, s-word, b-word, crap, ass, and g-damn; however, I do have a problem with the n-word and the c-word, and more so with the latter than the former. Let me clarify before someone jumps down my throat. I can see when using the n-word might be necessary, particularly if you are trying to tell a certain kind of story about, perhaps, the civil rights movement in the United States or the Apartheid era of South Africa; it makes perfect sense that the n-word would show up in such instances. Outside of that, however, I see no use for it. The c-word, though, is, for me, pretty much intolerable; I can't stand the word for too many reasons to count, and there have been times when its use has forced me to stop reading.
That's my personal opinion. Mine is not the only one, and no one answer is any more correct than another. To illustrate this point, I asked folks on my Twitter account to respond to the question: Do you tolerate cursing in the books you read? Where are your limits, if any? Here are some of their responses (with some minor editing):
Dhympna: Yeah, I like cursing. I sometimes get annoyed by writers who use too many colloquial expressions. I get more annoyed by authors using particular vernacular and slang too much than actual cursing. In all fairness, I do tend to curse like a sailor, which is why it does not bother me.
Kaolin Fire: No limits so long as the story's interesting and it's relevant. Whatever.
GothixHalo: As long as the writing is good and the character development isn't horrible, cursing isn't a flaw. Using it as a replacement for good writing skills is a crime, though. Having to use curse words instead of competent words is pitiful.
mspuma: I only respect cursing if it seems realistic. Overuse of cursing in writing is just an old shock value trick. Cussing in and of itself doesn't offend me. They're just words. But like any emphasized phraze/cliche, it loses its punch with repetition.
Keeping all of these views in mind, it is important to note that there is no true answer to the question of cursing. What matters most is your personal taste. The market is not so black and white to make the claim for any particular level of restraint appropriate or right. In fact, because the market is so varied, it is only logical to assume that using curse words should be based on personal taste rather than anything else. Andy Remic, for example, has no qualms about using curses, and he has a market of readers who enjoy that. Other writers avoid curses entirely; they have a market two (and likely some overlap). Some people can't stand Remic, I'm sure, and others love him; Remic, I imagine, loves himself quite a lot. Remic's personal taste is clear: he likes to use curse words in his fiction. And he got published doing it.
That is not to say that you shouldn't demonstrate some restraint. Writing dialogue is not easy to do and having dialogue that is essentially a whole stream of f-words, s-words, and b-words will seem trite or perhaps unnecessarily vulgar. It all really depends on your audience. I often look at cursing as a combination of style and necessity; if the cursing is there only to be shocking or impedes the flow of the prose, then I'm out.
What about you? Where are your limits on the matter of cursing in fiction, as writers or readers?