[Query Tiles]: TileServiceScheduler enhancement.

- In the header file, change TileServiceScheduler to a pure interface,
and create TileServiceSchedulerImpl class to inherit from LogSource and
TileServiceScheduler both.

- Implemented LogSource in Scheduler - as TileServiceImpl will actually
owns the Logger.

- Create Delegate in scheduler and GetTileGroup through TileManager,
in order to expose to LogSource.

- Added two more scheduler event APIs OnFetchStarted and OnGroupDataSaved
in order to update the internal status.

- (TODO) convert TileGroup to base::Value with pretty format.

- Follow up CL:
https://chromium-review.googlesource.com/c/chromium/src/+/2264934

Bug: 1066556
Change-Id: Ifa8099499f17e0cddf745dffc7384b3e3595fa2d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2277073
Auto-Submit: Hesen Zhang <[email protected]>
Reviewed-by: Min Qin <[email protected]>
Reviewed-by: Xing Liu <[email protected]>
Commit-Queue: Hesen Zhang <[email protected]>
Cr-Commit-Position: refs/heads/master@{#785892}
diff --git a/components/query_tiles/internal/tile_service_impl.cc b/components/query_tiles/internal/tile_service_impl.cc
index 16317ce..e24b1b9 100644
--- a/components/query_tiles/internal/tile_service_impl.cc
+++ b/components/query_tiles/internal/tile_service_impl.cc
@@ -9,14 +9,11 @@
 
 #include "base/bind.h"
 #include "base/bind_helpers.h"
-#include "base/command_line.h"
 #include "base/guid.h"
 #include "base/rand_util.h"
 #include "base/threading/thread_task_runner_handle.h"
 #include "components/query_tiles/internal/proto_conversion.h"
-#include "components/query_tiles/internal/stats.h"
 #include "components/query_tiles/internal/tile_config.h"
-#include "components/query_tiles/switches.h"
 
 namespace query_tiles {
 
@@ -45,6 +42,7 @@
   bool success = (status == TileGroupStatus::kSuccess ||
                   status == TileGroupStatus::kNoTiles);
   DCHECK(callback);
+  scheduler_->SetDelegate(this);
   scheduler_->OnTileManagerInitialized(status);
   std::move(callback).Run(success);
 }
@@ -65,10 +63,7 @@
   tile_fetcher_->StartFetchForTiles(base::BindOnce(
       &TileServiceImpl::OnFetchFinished, weak_ptr_factory_.GetWeakPtr(),
       is_from_reduced_mode, std::move(task_finished_callback)));
-
-  base::Time::Exploded local_explode;
-  base::Time::Now().LocalExplode(&local_explode);
-  stats::RecordExplodeOnFetchStarted(local_explode.hour);
+  scheduler_->OnFetchStarted();
 }
 
 void TileServiceImpl::CancelTask() {
@@ -114,6 +109,8 @@
     bool is_from_reduced_mode,
     BackgroundTaskFinishedCallback task_finished_callback,
     TileGroupStatus status) {
+  scheduler_->OnGroupDataSaved(status);
+
   if (status != TileGroupStatus::kSuccess) {
     std::move(task_finished_callback).Run(false /*reschedule*/);
     return;
@@ -132,4 +129,8 @@
   std::move(task_finished_callback).Run(false /*reschedule*/);
 }
 
+TileGroup* TileServiceImpl::GetTileGroup() {
+  return tile_manager_->GetTileGroup();
+}
+
 }  // namespace query_tiles