| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/feature_engagement_tracker/internal/init_aware_model.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 |
| 9 namespace feature_engagement_tracker { |
| 10 |
| 11 InitAwareModel::InitAwareModel(std::unique_ptr<Model> model) |
| 12 : model_(std::move(model)), weak_ptr_factory_(this) { |
| 13 DCHECK(model_); |
| 14 } |
| 15 |
| 16 InitAwareModel::~InitAwareModel() = default; |
| 17 |
| 18 void InitAwareModel::Initialize(const OnModelInitializationFinished& callback, |
| 19 uint32_t current_day) { |
| 20 model_->Initialize(base::Bind(&InitAwareModel::OnInitializeComplete, |
| 21 weak_ptr_factory_.GetWeakPtr(), callback), |
| 22 current_day); |
| 23 } |
| 24 |
| 25 bool InitAwareModel::IsReady() const { |
| 26 return model_->IsReady(); |
| 27 } |
| 28 |
| 29 const Event* InitAwareModel::GetEvent(const std::string& event_name) const { |
| 30 return model_->GetEvent(event_name); |
| 31 } |
| 32 |
| 33 void InitAwareModel::IncrementEvent(const std::string& event_name, |
| 34 uint32_t current_day) { |
| 35 if (IsReady()) { |
| 36 model_->IncrementEvent(event_name, current_day); |
| 37 return; |
| 38 } |
| 39 |
| 40 queued_events_.push_back(std::tie(event_name, current_day)); |
| 41 } |
| 42 |
| 43 void InitAwareModel::OnInitializeComplete( |
| 44 const OnModelInitializationFinished& callback, |
| 45 bool success) { |
| 46 if (success) { |
| 47 for (auto& event : queued_events_) |
| 48 model_->IncrementEvent(std::get<0>(event), std::get<1>(event)); |
| 49 queued_events_.clear(); |
| 50 } |
| 51 |
| 52 callback.Run(success); |
| 53 } |
| 54 |
| 55 } // namespace feature_engagement_tracker |
| OLD | NEW |