Commit 3ec9e2cc authored by Hesen Zhang's avatar Hesen Zhang Committed by Commit Bot

[Query Tiles]: Move TileServiceSchedulerImpl to single header.

Bug: 1066556
Change-Id: Iaee901e0071dc39144e369dca07409bbfd6f8421
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2283325
Commit-Queue: Hesen Zhang <hesen@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786181}
parent 5e23e598
......@@ -39,8 +39,9 @@ source_set("internal") {
"tile_manager.h",
"tile_service_impl.cc",
"tile_service_impl.h",
"tile_service_scheduler.cc",
"tile_service_scheduler.h",
"tile_service_scheduler_impl.cc",
"tile_service_scheduler_impl.h",
"tile_store.cc",
"tile_store.h",
"tile_types.h",
......
......@@ -8,19 +8,13 @@
#include <memory>
#include <string>
#include "base/time/clock.h"
#include "base/time/tick_clock.h"
#include "components/background_task_scheduler/background_task_scheduler.h"
#include "components/query_tiles/internal/log_source.h"
#include "components/query_tiles/internal/tile_config.h"
#include "components/query_tiles/internal/tile_types.h"
#include "components/query_tiles/tile_service_prefs.h"
#include "net/base/backoff_entry_serializer.h"
class PrefService;
namespace query_tiles {
struct TileGroup;
// Coordinates with native background task scheduler to schedule or cancel a
// TileBackgroundTask.
class TileServiceScheduler {
......@@ -74,91 +68,6 @@ class TileServiceScheduler {
TileServiceScheduler() = default;
};
// An implementation of TileServiceScheduler interface and LogSource interface.
class TileServiceSchedulerImpl : public TileServiceScheduler, public LogSource {
public:
TileServiceSchedulerImpl(
background_task::BackgroundTaskScheduler* scheduler,
PrefService* prefs,
base::Clock* clock,
const base::TickClock* tick_clock,
std::unique_ptr<net::BackoffEntry::Policy> backoff_policy,
LogSink* log_sink);
~TileServiceSchedulerImpl() override;
private:
// TileServiceScheduler implementation.
void CancelTask() override;
void OnFetchStarted() override;
void OnFetchCompleted(TileInfoRequestStatus status) override;
void OnTileManagerInitialized(TileGroupStatus status) override;
void OnDbPurged(TileGroupStatus status) override;
void OnGroupDataSaved(TileGroupStatus status) override;
void SetDelegate(Delegate* delegate) override;
// LogSource implementation.
TileInfoRequestStatus GetFetcherStatus() override;
TileGroupStatus GetGroupStatus() override;
TileGroup* GetTileGroup() override;
void ScheduleTask(bool is_init_schedule);
std::unique_ptr<net::BackoffEntry> GetBackoff();
void AddBackoff();
void ResetBackoff();
void MaximizeBackoff();
int64_t GetDelaysFromBackoff();
void GetInstantTaskWindow(int64_t* start_time_ms,
int64_t* end_time_ms,
bool is_init_schedule);
void GetTaskWindow(int64_t* start_time_ms,
int64_t* end_time_ms,
bool is_init_schedule);
void UpdateBackoff(net::BackoffEntry* backoff);
void MarkFirstRunScheduled();
void MarkFirstRunFinished();
// Returns true if the initial task has been scheduled because no tiles in
// db(kickoff condition), but still waiting to be completed at the designated
// window. Returns false either the first task is not scheduled yet or it is
// already finished.
bool IsDuringFirstFlow();
// Ping the log sink to update.
void PingLogSink();
// Native Background Scheduler instance.
background_task::BackgroundTaskScheduler* scheduler_;
// PrefService.
PrefService* prefs_;
// Clock object to get current time.
base::Clock* clock_;
// TickClock used for building backoff entry.
const base::TickClock* tick_clock_;
// Backoff policy used for reschdule.
std::unique_ptr<net::BackoffEntry::Policy> backoff_policy_;
// Flag to indicate if currently have a suspend status to avoid overwriting if
// already scheduled a suspend task during this lifecycle.
bool is_suspend_;
// Delegate object.
Delegate* delegate_;
// Internal fetcher status.
TileInfoRequestStatus fetcher_status_;
// Internal group status.
TileGroupStatus group_status_;
// Log Sink object.
LogSink* log_sink_;
};
} // namespace query_tiles
#endif // COMPONENTS_QUERY_TILES_INTERNAL_TILE_SERVICE_SCHEDULER_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/query_tiles/internal/tile_service_scheduler.h"
#include "components/query_tiles/internal/tile_service_scheduler_impl.h"
#include <memory>
#include <utility>
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_QUERY_TILES_INTERNAL_TILE_SERVICE_SCHEDULER_IMPL_H_
#define COMPONENTS_QUERY_TILES_INTERNAL_TILE_SERVICE_SCHEDULER_IMPL_H_
#include "base/time/clock.h"
#include "base/time/tick_clock.h"
#include "components/query_tiles/internal/log_source.h"
#include "components/query_tiles/internal/tile_config.h"
#include "components/query_tiles/internal/tile_service_scheduler.h"
#include "components/query_tiles/tile_service_prefs.h"
#include "net/base/backoff_entry_serializer.h"
class PrefService;
namespace query_tiles {
// An implementation of TileServiceScheduler interface and LogSource interface.
class TileServiceSchedulerImpl : public TileServiceScheduler, public LogSource {
public:
TileServiceSchedulerImpl(
background_task::BackgroundTaskScheduler* scheduler,
PrefService* prefs,
base::Clock* clock,
const base::TickClock* tick_clock,
std::unique_ptr<net::BackoffEntry::Policy> backoff_policy,
LogSink* log_sink);
~TileServiceSchedulerImpl() override;
private:
// TileServiceScheduler implementation.
void CancelTask() override;
void OnFetchStarted() override;
void OnFetchCompleted(TileInfoRequestStatus status) override;
void OnTileManagerInitialized(TileGroupStatus status) override;
void OnDbPurged(TileGroupStatus status) override;
void OnGroupDataSaved(TileGroupStatus status) override;
void SetDelegate(Delegate* delegate) override;
// LogSource implementation.
TileInfoRequestStatus GetFetcherStatus() override;
TileGroupStatus GetGroupStatus() override;
TileGroup* GetTileGroup() override;
void ScheduleTask(bool is_init_schedule);
std::unique_ptr<net::BackoffEntry> GetBackoff();
void AddBackoff();
void ResetBackoff();
void MaximizeBackoff();
int64_t GetDelaysFromBackoff();
void GetInstantTaskWindow(int64_t* start_time_ms,
int64_t* end_time_ms,
bool is_init_schedule);
void GetTaskWindow(int64_t* start_time_ms,
int64_t* end_time_ms,
bool is_init_schedule);
void UpdateBackoff(net::BackoffEntry* backoff);
void MarkFirstRunScheduled();
void MarkFirstRunFinished();
// Returns true if the initial task has been scheduled because no tiles in
// db(kickoff condition), but still waiting to be completed at the designated
// window. Returns false either the first task is not scheduled yet or it is
// already finished.
bool IsDuringFirstFlow();
// Ping the log sink to update.
void PingLogSink();
// Native Background Scheduler instance.
background_task::BackgroundTaskScheduler* scheduler_;
PrefService* prefs_;
// Clock object to get current time.
base::Clock* clock_;
// TickClock used for building backoff entry.
const base::TickClock* tick_clock_;
// Backoff policy used for reschdule.
std::unique_ptr<net::BackoffEntry::Policy> backoff_policy_;
// Flag to indicate if currently have a suspend status to avoid overwriting if
// already scheduled a suspend task during this lifecycle.
bool is_suspend_;
// Delegate instance.
Delegate* delegate_;
// Internal fetcher status.
TileInfoRequestStatus fetcher_status_;
// Internal group status.
TileGroupStatus group_status_;
// LogSink instance.
LogSink* log_sink_;
};
} // namespace query_tiles
#endif // COMPONENTS_QUERY_TILES_INTERNAL_TILE_SERVICE_SCHEDULER_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/query_tiles/internal/tile_service_scheduler.h"
#include "components/query_tiles/internal/tile_service_scheduler_impl.h"
#include <utility>
#include <vector>
......@@ -13,12 +14,15 @@
#include "base/test/simple_test_tick_clock.h"
#include "base/test/task_environment.h"
#include "base/test/test_mock_time_task_runner.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/testing_pref_service.h"
#include "components/query_tiles/internal/black_hole_log_sink.h"
#include "components/query_tiles/internal/tile_config.h"
#include "components/query_tiles/internal/tile_store.h"
#include "components/query_tiles/switches.h"
#include "components/query_tiles/test/test_utils.h"
#include "components/query_tiles/tile_service_prefs.h"
#include "net/base/backoff_entry_serializer.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......
......@@ -27,7 +27,7 @@
#include "components/query_tiles/internal/tile_fetcher.h"
#include "components/query_tiles/internal/tile_manager.h"
#include "components/query_tiles/internal/tile_service_impl.h"
#include "components/query_tiles/internal/tile_service_scheduler.h"
#include "components/query_tiles/internal/tile_service_scheduler_impl.h"
#include "components/query_tiles/switches.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment