Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[segmentation] Separate ownership of execution and signal handlers
Move ownership of signal handlers, and execution / processing classes to separate classes. Make clear the dependencies between these 2 services. BUG=1307083 Change-Id: Ic572e5b7d60b6a16108a91a2d1dff05b1be1b27b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3531200 Reviewed-by: Tommy Nyquist <nyquist@chromium.org> Commit-Queue: Siddhartha S <ssid@chromium.org> Cr-Commit-Position: refs/heads/main@{#990173}
- Loading branch information
1 parent
19c2913
commit 7f85823
Showing
8 changed files
with
305 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
components/segmentation_platform/internal/scheduler/execution_service.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2022 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/segmentation_platform/internal/scheduler/execution_service.h" | ||
|
||
#include "components/segmentation_platform/internal/data_collection/training_data_collector.h" | ||
#include "components/segmentation_platform/internal/database/segment_info_database.h" | ||
#include "components/segmentation_platform/internal/database/signal_database.h" | ||
#include "components/segmentation_platform/internal/execution/feature_aggregator_impl.h" | ||
#include "components/segmentation_platform/internal/execution/feature_list_query_processor.h" | ||
#include "components/segmentation_platform/internal/execution/model_execution_manager_factory.h" | ||
#include "components/segmentation_platform/internal/scheduler/model_execution_scheduler_impl.h" | ||
#include "components/segmentation_platform/internal/signals/signal_handler.h" | ||
|
||
namespace segmentation_platform { | ||
|
||
ExecutionService::ExecutionService() = default; | ||
ExecutionService::~ExecutionService() = default; | ||
|
||
void ExecutionService::Initialize( | ||
SignalDatabase* signal_database, | ||
SegmentInfoDatabase* segment_info_database, | ||
SignalStorageConfig* signal_storage_config, | ||
SignalHandler* signal_handler, | ||
base::Clock* clock, | ||
ModelExecutionManager::SegmentationModelUpdatedCallback callback, | ||
scoped_refptr<base::SequencedTaskRunner> task_runner, | ||
const base::flat_set<OptimizationTarget>& all_segment_ids, | ||
ModelProviderFactory* model_provider_factory, | ||
std::vector<ModelExecutionScheduler::Observer*>&& observers, | ||
const PlatformOptions& platform_options) { | ||
feature_list_query_processor_ = std::make_unique<FeatureListQueryProcessor>( | ||
signal_database, std::make_unique<FeatureAggregatorImpl>()); | ||
|
||
training_data_collector_ = TrainingDataCollector::Create( | ||
segment_info_database, feature_list_query_processor_.get(), | ||
signal_handler->deprecated_histogram_signal_handler(), | ||
signal_storage_config, clock); | ||
training_data_collector_->OnServiceInitialized(); | ||
|
||
model_execution_manager_ = CreateModelExecutionManager( | ||
model_provider_factory, task_runner, all_segment_ids, clock, | ||
segment_info_database, signal_database, | ||
feature_list_query_processor_.get(), callback); | ||
|
||
model_execution_scheduler_ = std::make_unique<ModelExecutionSchedulerImpl>( | ||
std::move(observers), segment_info_database, signal_storage_config, | ||
model_execution_manager_.get(), all_segment_ids, clock, platform_options); | ||
|
||
model_execution_scheduler_->RequestModelExecutionForEligibleSegments( | ||
/*expired_only=*/true); | ||
} | ||
|
||
void ExecutionService::OnNewModelInfoReady( | ||
const proto::SegmentInfo& segment_info) { | ||
model_execution_scheduler_->OnNewModelInfoReady(segment_info); | ||
} | ||
|
||
} // namespace segmentation_platform |
82 changes: 82 additions & 0 deletions
82
components/segmentation_platform/internal/scheduler/execution_service.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2022 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_SEGMENTATION_PLATFORM_INTERNAL_SCHEDULER_EXECUTION_SERVICE_H_ | ||
#define COMPONENTS_SEGMENTATION_PLATFORM_INTERNAL_SCHEDULER_EXECUTION_SERVICE_H_ | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
#include "base/containers/flat_set.h" | ||
#include "base/task/sequenced_task_runner.h" | ||
#include "base/time/clock.h" | ||
#include "components/optimization_guide/proto/models.pb.h" | ||
#include "components/segmentation_platform/internal/execution/model_execution_manager.h" | ||
#include "components/segmentation_platform/internal/scheduler/model_execution_scheduler.h" | ||
|
||
namespace segmentation_platform { | ||
|
||
struct PlatformOptions; | ||
class FeatureListQueryProcessor; | ||
class ModelProviderFactory; | ||
class ModelExecutionSchedulerImpl; | ||
class SegmentInfoDatabase; | ||
class SignalDatabase; | ||
class SignalHandler; | ||
class SignalStorageConfig; | ||
class TrainingDataCollector; | ||
|
||
// Handles feature processing and model execution. | ||
class ExecutionService { | ||
public: | ||
ExecutionService(); | ||
~ExecutionService(); | ||
|
||
ExecutionService(ExecutionService&) = delete; | ||
ExecutionService& operator=(ExecutionService&) = delete; | ||
|
||
void Initialize( | ||
SignalDatabase* signal_database, | ||
SegmentInfoDatabase* segment_info_database, | ||
SignalStorageConfig* signal_storage_config, | ||
SignalHandler* signal_handler, | ||
base::Clock* clock, | ||
ModelExecutionManager::SegmentationModelUpdatedCallback callback, | ||
scoped_refptr<base::SequencedTaskRunner> task_runner, | ||
const base::flat_set<OptimizationTarget>& all_segment_ids, | ||
ModelProviderFactory* model_provider_factory, | ||
std::vector<ModelExecutionScheduler::Observer*>&& observers, | ||
const PlatformOptions& platform_options); | ||
|
||
// Called whenever a new or updated model is available. Must be a valid | ||
// SegmentInfo with valid metadata and features. | ||
void OnNewModelInfoReady(const proto::SegmentInfo& segment_info); | ||
|
||
// TODO(ssid): Remove this method and pass in ExecutionService to proxy | ||
// service. | ||
ModelExecutionSchedulerImpl* deprecated_model_execution_scheduler() { | ||
return model_execution_scheduler_.get(); | ||
} | ||
// TODO(ssid): Remove this method and pass in ExecutionService to selector. | ||
ModelExecutionManager* deprecated_model_execution_manager() { | ||
return model_execution_manager_.get(); | ||
} | ||
|
||
private: | ||
// Training/inference input data generation. | ||
std::unique_ptr<FeatureListQueryProcessor> feature_list_query_processor_; | ||
|
||
// Traing data collection logic. | ||
std::unique_ptr<TrainingDataCollector> training_data_collector_; | ||
|
||
// Model execution scheduling logic. | ||
std::unique_ptr<ModelExecutionSchedulerImpl> model_execution_scheduler_; | ||
|
||
// Model execution. | ||
std::unique_ptr<ModelExecutionManager> model_execution_manager_; | ||
}; | ||
|
||
} // namespace segmentation_platform | ||
|
||
#endif // COMPONENTS_SEGMENTATION_PLATFORM_INTERNAL_SCHEDULER_EXECUTION_SERVICE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
components/segmentation_platform/internal/signals/signal_handler.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2022 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/segmentation_platform/internal/signals/signal_handler.h" | ||
|
||
#include "components/segmentation_platform/internal/signals/histogram_signal_handler.h" | ||
#include "components/segmentation_platform/internal/signals/history_service_observer.h" | ||
#include "components/segmentation_platform/internal/signals/signal_filter_processor.h" | ||
#include "components/segmentation_platform/internal/signals/user_action_signal_handler.h" | ||
#include "components/segmentation_platform/internal/ukm_data_manager.h" | ||
|
||
namespace segmentation_platform { | ||
|
||
SignalHandler::SignalHandler() = default; | ||
SignalHandler::~SignalHandler() = default; | ||
|
||
void SignalHandler::Initialize( | ||
SignalDatabase* signal_database, | ||
SegmentInfoDatabase* segment_info_database, | ||
UkmDataManager* ukm_data_manager, | ||
history::HistoryService* history_service, | ||
DefaultModelManager* default_model_manager, | ||
const std::vector<optimization_guide::proto::OptimizationTarget>& | ||
segment_ids) { | ||
user_action_signal_handler_ = | ||
std::make_unique<UserActionSignalHandler>(signal_database); | ||
histogram_signal_handler_ = | ||
std::make_unique<HistogramSignalHandler>(signal_database); | ||
signal_filter_processor_ = std::make_unique<SignalFilterProcessor>( | ||
segment_info_database, user_action_signal_handler_.get(), | ||
histogram_signal_handler_.get(), ukm_data_manager, default_model_manager, | ||
segment_ids); | ||
|
||
if (ukm_data_manager->IsUkmEngineEnabled() && history_service) { | ||
// If UKM engine is enabled and history service is not available, then we | ||
// would write metrics without URLs to the database, which is OK. | ||
history_service_observer_ = std::make_unique<HistoryServiceObserver>( | ||
history_service, ukm_data_manager->GetOrCreateUrlHandler()); | ||
} | ||
} | ||
|
||
void SignalHandler::TearDown() { | ||
history_service_observer_.reset(); | ||
} | ||
|
||
void SignalHandler::EnableMetrics(bool signal_collection_allowed) { | ||
signal_filter_processor_->EnableMetrics(signal_collection_allowed); | ||
} | ||
|
||
void SignalHandler::OnSignalListUpdated() { | ||
signal_filter_processor_->OnSignalListUpdated(); | ||
} | ||
|
||
} // namespace segmentation_platform |
Oops, something went wrong.