A chocolate brownie is a flat , baked square or bar developed in the United States at the end of the 19th century and popularized in both the U.S. and Canada during the first half of the 20th century .