[Downloads] Enforce state transition integrity and state invariants.

DownloadItemImpl is getting pretty complicated and it's hard to keep
track of possible races. This CL tries to make things a little easier by
constraining state transitions and also asserting the state of the
DownloadItem as each state is entered.

This CL introduces two new intermediate states to DownloadItemImpl:

  - TARGET_PENDING_INTERNAL
  - TARGET_RESOLVED_INTERNAL

Of these, only TARGET_RESOLVED_INTERNAL is allowed to transition to an
interrupted state. TARGET_PENDING_INTERNAL is entered when the download
target determination cascade begins and defers any interruptions until
TARGET_RESOLVED_INTERNAL. This state also blocks download completion.
Hence transitions to INTERRUPTED and COMPLETED states must now step over
the target determination state.

Also introduce a set of tests that are designed to exercise the various
permutations of events that can occur during the target determination
phase.

BUG=7648

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

Cr-Commit-Position: refs/heads/master@{#375275}
4 files changed