Merge duplicated composited layer tree rebuilding code into a helper function

It's precarious to keep the duplicated code around in case we change
it in one place but forget the other. In fact, it's possible that
already happened (hence the FIXME).

Review URL: https://codereview.chromium.org/135323002

git-svn-id: svn://svn.chromium.org/blink/trunk@164940 bbb929c8-8fbe-4397-9dbb-9b2b20218538