It boils down to company regulations. Post 9-11, many companies changed their rules to not allow non airline employee's to enter the cockpit once the cabin doors were closed for visits until landing and arrival at the gate.
Other's specifically do not allow ANYONE in the cockpit who is not a pilot on duty (i.e. instructor/assessment officer) in the cockpit except cabin crew on duty on the flight (i.e. 1 pilot uses the rest room, a cabin crew must be present in the cockpit till the pilot returns. 1 pilot can not be allowed on his or her own in the cockpit).
And then some airlines, as you guys have mentioned, leave it to the pilot's discreation.