Normalize Profile DoFinalInit sequence

Profiles are created by one of two ProfileManager functions:
CreateProfileHelper and CreateProfileAsyncHelper.

Also two DoFinalInit functions exists one in ProfileImpl
and one in ProfileManager.

In case of sync profile creation ProfileManager::DoFinalInit
is called after ProfileImpl::DoFinalInit. In case of async
profile creation ProfileManager::DoFinalInit is called
inside ProfileImpl::DoFinalInit through Profile::Delegate.

This CL moves delegate calls to end of ProfileImpl::DoFinalInit
and normalise profile initialization sequence.

In Yandex we have trouble with recently added
io_data_.InitializeDataReductionProxy()
because it was inserted after calling Profile::Delegate.

Change-Id: I3ca408e41ca13421d7899f66d5db8b8a06d77eb4
Reviewed-on: https://chromium-review.googlesource.com/c/1417874
Commit-Queue: Aleksei Loshkarev <lixan@yandex-team.ru>
Reviewed-by: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#624471}
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 74f2432..4cb9275 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -699,17 +699,6 @@
   }
 #endif
 
-  if (delegate_) {
-    TRACE_EVENT0("browser", "ProfileImpl::DoFileInit:DelegateOnProfileCreated")
-    delegate_->OnProfileCreated(this, true, IsNewProfile());
-  }
-
-  {
-    SCOPED_UMA_HISTOGRAM_TIMER("Profile.NotifyProfileCreatedTime");
-    content::NotificationService::current()->Notify(
-        chrome::NOTIFICATION_PROFILE_CREATED, content::Source<Profile>(this),
-        content::NotificationService::NoDetails());
-  }
 #if !defined(OS_CHROMEOS)
   // Listen for bookmark model load, to bootstrap the sync service.
   // On CrOS sync service will be initialized after sign in.
@@ -730,6 +719,18 @@
 
   content::URLDataSource::Add(this,
                               std::make_unique<PrefsInternalsSource>(this));
+
+  if (delegate_) {
+    TRACE_EVENT0("browser", "ProfileImpl::DoFileInit:DelegateOnProfileCreated")
+    delegate_->OnProfileCreated(this, true, IsNewProfile());
+  }
+
+  {
+    SCOPED_UMA_HISTOGRAM_TIMER("Profile.NotifyProfileCreatedTime");
+    content::NotificationService::current()->Notify(
+        chrome::NOTIFICATION_PROFILE_CREATED, content::Source<Profile>(this),
+        content::NotificationService::NoDetails());
+  }
 }
 
 base::FilePath ProfileImpl::last_selected_directory() {