Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: components/feature_engagement_tracker/internal/feature_engagement_tracker_impl.cc

Issue 2877243002: Support IPH NotifyEvent calls before Initialize (Closed)
Patch Set: Fixed build.gn Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/feature_engagement_tracker/internal/feature_engagement_trac ker_impl.h" 5 #include "components/feature_engagement_tracker/internal/feature_engagement_trac ker_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/feature_list.h" 8 #include "base/feature_list.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "components/feature_engagement_tracker/internal/editable_configuration. h" 11 #include "components/feature_engagement_tracker/internal/editable_configuration. h"
12 #include "components/feature_engagement_tracker/internal/in_memory_store.h" 12 #include "components/feature_engagement_tracker/internal/in_memory_store.h"
13 #include "components/feature_engagement_tracker/internal/init_aware_model.h"
13 #include "components/feature_engagement_tracker/internal/model_impl.h" 14 #include "components/feature_engagement_tracker/internal/model_impl.h"
14 #include "components/feature_engagement_tracker/internal/never_condition_validat or.h" 15 #include "components/feature_engagement_tracker/internal/never_condition_validat or.h"
15 #include "components/feature_engagement_tracker/internal/never_storage_validator .h" 16 #include "components/feature_engagement_tracker/internal/never_storage_validator .h"
16 #include "components/feature_engagement_tracker/internal/once_condition_validato r.h" 17 #include "components/feature_engagement_tracker/internal/once_condition_validato r.h"
17 #include "components/feature_engagement_tracker/internal/persistent_store.h" 18 #include "components/feature_engagement_tracker/internal/persistent_store.h"
18 #include "components/feature_engagement_tracker/internal/single_invalid_configur ation.h" 19 #include "components/feature_engagement_tracker/internal/single_invalid_configur ation.h"
19 #include "components/feature_engagement_tracker/internal/system_time_provider.h" 20 #include "components/feature_engagement_tracker/internal/system_time_provider.h"
20 #include "components/feature_engagement_tracker/public/feature_constants.h" 21 #include "components/feature_engagement_tracker/public/feature_constants.h"
21 #include "components/feature_engagement_tracker/public/feature_list.h" 22 #include "components/feature_engagement_tracker/public/feature_list.h"
22 #include "components/leveldb_proto/proto_database_impl.h" 23 #include "components/leveldb_proto/proto_database_impl.h"
(...skipping 10 matching lines...) Expand all
33 34
34 // Create valid configurations for all features to ensure that the 35 // Create valid configurations for all features to ensure that the
35 // OnceConditionValidator acknowledges that thet meet conditions once. 36 // OnceConditionValidator acknowledges that thet meet conditions once.
36 std::vector<const base::Feature*> features = GetAllFeatures(); 37 std::vector<const base::Feature*> features = GetAllFeatures();
37 for (auto* feature : features) { 38 for (auto* feature : features) {
38 FeatureConfig feature_config; 39 FeatureConfig feature_config;
39 feature_config.valid = true; 40 feature_config.valid = true;
40 configuration->SetConfiguration(feature, feature_config); 41 configuration->SetConfiguration(feature, feature_config);
41 } 42 }
42 43
44 auto raw_model =
45 base::MakeUnique<ModelImpl>(base::MakeUnique<InMemoryStore>(),
46 base::MakeUnique<NeverStorageValidator>());
47
43 return base::MakeUnique<FeatureEngagementTrackerImpl>( 48 return base::MakeUnique<FeatureEngagementTrackerImpl>(
44 base::MakeUnique<InMemoryStore>(), std::move(configuration), 49 base::MakeUnique<InitAwareModel>(std::move(raw_model)),
45 base::MakeUnique<OnceConditionValidator>(), 50 std::move(configuration), base::MakeUnique<OnceConditionValidator>(),
46 base::MakeUnique<NeverStorageValidator>(),
47 base::MakeUnique<SystemTimeProvider>()); 51 base::MakeUnique<SystemTimeProvider>());
48 } 52 }
49 53
50 } // namespace 54 } // namespace
51 55
52 // This method is declared in //components/feature_engagement_tracker/public/ 56 // This method is declared in //components/feature_engagement_tracker/public/
53 // feature_engagement_tracker.h 57 // feature_engagement_tracker.h
54 // and should be linked in to any binary using FeatureEngagementTracker::Create. 58 // and should be linked in to any binary using FeatureEngagementTracker::Create.
55 // static 59 // static
56 FeatureEngagementTracker* FeatureEngagementTracker::Create( 60 FeatureEngagementTracker* FeatureEngagementTracker::Create(
57 const base::FilePath& storage_dir, 61 const base::FilePath& storage_dir,
58 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner) { 62 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner) {
59 if (base::FeatureList::IsEnabled(kIPHDemoMode)) 63 if (base::FeatureList::IsEnabled(kIPHDemoMode))
60 return CreateDemoModeFeatureEngagementTracker().release(); 64 return CreateDemoModeFeatureEngagementTracker().release();
61 65
62 std::unique_ptr<leveldb_proto::ProtoDatabase<Event>> db = 66 std::unique_ptr<leveldb_proto::ProtoDatabase<Event>> db =
63 base::MakeUnique<leveldb_proto::ProtoDatabaseImpl<Event>>( 67 base::MakeUnique<leveldb_proto::ProtoDatabaseImpl<Event>>(
64 background_task_runner); 68 background_task_runner);
65 69
66 std::unique_ptr<Store> store = 70 auto store = base::MakeUnique<PersistentStore>(storage_dir, std::move(db));
67 base::MakeUnique<PersistentStore>(storage_dir, std::move(db)); 71 auto storage_validator = base::MakeUnique<NeverStorageValidator>();
68 std::unique_ptr<Configuration> configuration = 72 auto raw_model = base::MakeUnique<ModelImpl>(std::move(store),
69 base::MakeUnique<SingleInvalidConfiguration>(); 73 std::move(storage_validator));
70 std::unique_ptr<ConditionValidator> condition_validator = 74
71 base::MakeUnique<NeverConditionValidator>(); 75 auto model = base::MakeUnique<InitAwareModel>(std::move(raw_model));
72 std::unique_ptr<StorageValidator> storage_validator = 76 auto configuration = base::MakeUnique<SingleInvalidConfiguration>();
73 base::MakeUnique<NeverStorageValidator>(); 77 auto condition_validator = base::MakeUnique<NeverConditionValidator>();
74 std::unique_ptr<TimeProvider> time_provider = 78 auto time_provider = base::MakeUnique<SystemTimeProvider>();
75 base::MakeUnique<SystemTimeProvider>();
76 79
77 return new FeatureEngagementTrackerImpl( 80 return new FeatureEngagementTrackerImpl(
78 std::move(store), std::move(configuration), 81 std::move(model), std::move(configuration),
79 std::move(condition_validator), std::move(storage_validator), 82 std::move(condition_validator), std::move(time_provider));
80 std::move(time_provider));
81 } 83 }
82 84
83 FeatureEngagementTrackerImpl::FeatureEngagementTrackerImpl( 85 FeatureEngagementTrackerImpl::FeatureEngagementTrackerImpl(
84 std::unique_ptr<Store> store, 86 std::unique_ptr<Model> model,
85 std::unique_ptr<Configuration> configuration, 87 std::unique_ptr<Configuration> configuration,
86 std::unique_ptr<ConditionValidator> condition_validator, 88 std::unique_ptr<ConditionValidator> condition_validator,
87 std::unique_ptr<StorageValidator> storage_validator,
88 std::unique_ptr<TimeProvider> time_provider) 89 std::unique_ptr<TimeProvider> time_provider)
89 : configuration_(std::move(configuration)), 90 : model_(std::move(model)),
91 configuration_(std::move(configuration)),
90 condition_validator_(std::move(condition_validator)), 92 condition_validator_(std::move(condition_validator)),
91 time_provider_(std::move(time_provider)), 93 time_provider_(std::move(time_provider)),
92 initialization_finished_(false), 94 initialization_finished_(false),
93 weak_ptr_factory_(this) { 95 weak_ptr_factory_(this) {
94 model_ = base::MakeUnique<ModelImpl>(std::move(store),
95 std::move(storage_validator));
96 model_->Initialize( 96 model_->Initialize(
97 base::Bind(&FeatureEngagementTrackerImpl::OnModelInitializationFinished, 97 base::Bind(&FeatureEngagementTrackerImpl::OnModelInitializationFinished,
98 weak_ptr_factory_.GetWeakPtr()), 98 weak_ptr_factory_.GetWeakPtr()),
99 time_provider_->GetCurrentDay()); 99 time_provider_->GetCurrentDay());
100 } 100 }
101 101
102 FeatureEngagementTrackerImpl::~FeatureEngagementTrackerImpl() = default; 102 FeatureEngagementTrackerImpl::~FeatureEngagementTrackerImpl() = default;
103 103
104 void FeatureEngagementTrackerImpl::NotifyEvent(const std::string& event) { 104 void FeatureEngagementTrackerImpl::NotifyEvent(const std::string& event) {
105 // TODO(nyquist): Track this event in UMA. 105 // TODO(nyquist): Track this event in UMA.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 146
147 for (auto& callback : on_initialized_callbacks_) { 147 for (auto& callback : on_initialized_callbacks_) {
148 base::ThreadTaskRunnerHandle::Get()->PostTask( 148 base::ThreadTaskRunnerHandle::Get()->PostTask(
149 FROM_HERE, base::Bind(callback, success)); 149 FROM_HERE, base::Bind(callback, success));
150 } 150 }
151 151
152 on_initialized_callbacks_.clear(); 152 on_initialized_callbacks_.clear();
153 } 153 }
154 154
155 } // namespace feature_engagement_tracker 155 } // namespace feature_engagement_tracker
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698