The key part of the deal is the years. The Giants only signed him for 2 years, which is huge. Huff wanted 3 years and there were likely teams that would've given it to him, but the Giants got him for just two, likely because they gave him more money per year.
Most reasonable Giants fans know it would be a miracle for Huff to repeat his 2010 numbers. This year he was a .290/.385/.506/.891 hitter with a 5.7 WAR. But in 2009 he was just a .241/.310/.384/.694 hitter with a -1.4 WAR. It's what makes him such a weird player. He had such a terrible year in 2009 and then when most people thought his career was pretty much over, he comes back with a great 2010. It's hard to know or even guess what he'll give you in 2011. In addition to the possibility that Huff's 2010 was mostly a fluke, he's not getting younger, his 2010 defensively was very likely a fluke, and he did post more mediocre numbers on offense after August 1st (.255/.360/.426/.786). I don't know how he'll do next year, but considering his age and slight regression towards the end of 2010, it's likely that the Giants overpaid for him. But the worst case scenario is that he's a player really not worth his salary at all, who the team hasn't made a long-term commitment to. The more likely scenario is that he provides average production at the position. But if that worst case scenario presents itself, his contract won't be a pain in the ass for a long time.
If we just want to focus on the Giants competing next season, it's quite possible that the Giants had no better option than to bring back Huff. With top prospect Brandon Belt hopefully being ready to start on Opening Day or at least come up midseason, the Giants are basically paying Huff to be their left fielder. According to Keith Law's Top 50 Free Agents list (Insider), Huff would be the 3rd best option for a team looking for an outfielder, behind just Carl Crawford and Jayson Werth. The Giants were not going to get Crawford or Werth; they don't have enough money and would have had to commit to long-term deals with them. I imagine Law ranked Huff as the 15th best free agent assuming he would be a first baseman, and maybe Huff's below average defense makes him less valuable in the outfield, but still, the next best free agent outfield options include guys like Manny Ramirez, Magglio Ordonez, and Johnny Damon. I'd rather have Huff. Maybe the Giants could have replaced Huff through the trade market? Maybe, but I find it unlikely that they'd be able to acquire a player better than Huff, without giving up some pretty good prospects. They also don't have many internal options that could replace Huff's production. Nate Schierholtz? Not enough offense. Darren Ford? Hellll no. Thomas Neal? Maybe later, but he's not quite ready. Of all the realistic possibilities, Aubrey Huff is probably the best option for the Giants in left field.
Today, Aubrey Huff probably got more money than he should have. He was a great player last year and an important leader in the clubhouse, but it's unlikely he'll have such a great year again. However, the deal given to Huff is not terrible. Really, it's not hard to imagine another team offering him 2 years and $20 million. Normally, I might say if that's what Huff was looking for, the Giants should move on and look elsewhere. But it's doubtful that the Giants could find another player in their price range more likely to produce than Huff. At worst, the Giants have a mediocre player or worse who they only have to pay for 2 years. At best, they have a player who is definitely worth the money. Huff's value will likely fall somewhere in between. A 2 year, $22 million contract is not going to drastically limit the team financially; the Rowand and Zito contracts have already done that. I don't love the deal, but I definitely don't hate it either.