Fix a crash when calling GetNetworkService() on Android

On Android, NetworkChangeNotifier can be created in 2 situations:
1. In BrowserMainLoop::PostMainMessageLoopStart(),
   NetworkChangeNotifierAndroid will be created on UI thread.
2. Triggered by the GetNetworkService() call when network service is running
   in-process, NetworkChangeNotifierPosix will be created on IO thread

Because 1 and 2 happens on 2 different threads, there is a race condition
that both creation calls could take place.

This CL fixes the issue by:
1. Combining NetworkChangeNotifier::HasNetworkChangeNotifier()
   and NetworkChangeNotifier::Create() into a single method
   CreateIfNeeded(), so that race condition won't be introduced
   between Has() and Create().
2. Use a lock to protect CreateIfNeeded(), so that only one global
   instance will be created if multiple threads are competing with
   each other. The original logic of not using a lock is introduce 9
   years ago: http://codereview.chromium.org/2802015, but with network
   service, the situation is more complicated. As a result, the lock
   usage will provide a safer and more simple approach to solve the
   issue.
3. Calling SetNetworkChangeNotifierFactory early for Android code.

BUG=1009981

Change-Id: I88dd50ca23d08f110f7ac7ffe08d50da65a05fac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872414
Reviewed-by: Clark DuVall <[email protected]>
Reviewed-by: Mike Dougherty <[email protected]>
Reviewed-by: John Abd-El-Malek <[email protected]>
Reviewed-by: Paul Jensen <[email protected]>
Reviewed-by: Gary Kacmarcik <[email protected]>
Reviewed-by: Changwan Ryu <[email protected]>
Reviewed-by: Xi Han <[email protected]>
Commit-Queue: Min Qin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#712848}
32 files changed