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 #ifndef COMPONENTS_FEATURE_ENGAGEMENT_TRACKER_PUBLIC_FEATURE_ENGAGEMENT_TRACKER_
H_ |
| 6 #define COMPONENTS_FEATURE_ENGAGEMENT_TRACKER_PUBLIC_FEATURE_ENGAGEMENT_TRACKER_
H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/compiler_specific.h" |
| 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/sequenced_task_runner.h" |
| 15 #include "components/keyed_service/core/keyed_service.h" |
| 16 |
| 17 #if defined(OS_ANDROID) |
| 18 #include "base/android/jni_android.h" |
| 19 #endif // defined(OS_ANDROID) |
| 20 |
| 21 namespace feature_engagement_tracker { |
| 22 |
| 23 // The FeatureEngagementTracker provides a backend for displaying feature |
| 24 // enlightenment or in-product help (IPH) with a clean and easy to use API to be |
| 25 // consumed by the UI frontend. The backend behaves as a black box and takes |
| 26 // input about user behavior. Whenever the frontend gives a trigger signal that |
| 27 // IPH could be displayed, the backend will provide an answer to whether it is |
| 28 // appropriate to show it or not. |
| 29 class FeatureEngagementTracker : public KeyedService { |
| 30 public: |
| 31 #if defined(OS_ANDROID) |
| 32 // Returns a Java object of the type FeatureEngagementTracker for the given |
| 33 // FeatureEngagementTracker. |
| 34 static base::android::ScopedJavaLocalRef<jobject> GetJavaObject( |
| 35 FeatureEngagementTracker* feature_engagement_tracker); |
| 36 #endif // defined(OS_ANDROID) |
| 37 |
| 38 // Invoked when the tracker has been initialized. The |success| parameter |
| 39 // indicates that the initialization was a success and it it ready to receive |
| 40 // calls. |
| 41 using OnInitializedCallback = base::Callback<void(bool success)>; |
| 42 |
| 43 // The |storage_dir| is the path to where all local storage will be. |
| 44 // The |bakground_task_runner| will be used for all disk reads and writes. |
| 45 static FeatureEngagementTracker* Create( |
| 46 const base::FilePath& storage_dir, |
| 47 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner); |
| 48 |
| 49 // Must be called whenever an event related to a precondition happens. |
| 50 virtual void Event(const std::string& feature, |
| 51 const std::string& precondition) = 0; |
| 52 |
| 53 // Must be called whenever a feature has been used. |
| 54 virtual void Used(const std::string& feature) = 0; |
| 55 |
| 56 // This function must be called whenever the triggering condition for a |
| 57 // specific feature happens. Returns true iff the display of feature |
| 58 // enlightenment must happen. |
| 59 // If |true| is returned, the caller *must* call Dismissed() when display |
| 60 // of feature enlightenment ends. |
| 61 virtual bool Trigger(const std::string& feature) WARN_UNUSED_RESULT = 0; |
| 62 |
| 63 // Must be called after display of feature enlightenment finishes. |
| 64 virtual void Dismissed() = 0; |
| 65 |
| 66 // For features that trigger on startup, they register a callback to ensure |
| 67 // that they are told when the tracker has been initialized. |
| 68 virtual void AddOnInitializedCallback(OnInitializedCallback callback) = 0; |
| 69 |
| 70 protected: |
| 71 FeatureEngagementTracker() = default; |
| 72 |
| 73 private: |
| 74 DISALLOW_COPY_AND_ASSIGN(FeatureEngagementTracker); |
| 75 }; |
| 76 |
| 77 } // namespace feature_engagement_tracker |
| 78 |
| 79 #endif // COMPONENTS_FEATURE_ENGAGEMENT_TRACKER_PUBLIC_FEATURE_ENGAGEMENT_TRACK
ER_H_ |
OLD | NEW |