Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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_CONTEXTUAL_SEARCH_BROWSER_WEEKLY_ACTIVITY_STORAGE_H_ | |
| 6 #define COMPONENTS_CONTEXTUAL_SEARCH_BROWSER_WEEKLY_ACTIVITY_STORAGE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <unordered_map> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 | |
| 13 namespace contextual_search { | |
| 14 | |
| 15 // An abstract class that stores weekly activity in device-specific | |
| 16 // integer storage. Allows callers to read and write user actions to persistent | |
| 17 // storage on the device by overriding the ReadStorage and WriteStorage calls. | |
| 18 // A user view of some UX is an "Impression", and user interaction is considered | |
| 19 // a "Click" even if the triggering gesture was something else. Together they | |
| 20 // produce the Click-Through-Rate, or CTR. | |
| 21 class WeeklyActivityStorage { | |
| 22 public: | |
| 23 // Constructs an instance that will manage at least |weeks_needed| week data. | |
| 24 WeeklyActivityStorage(int weeks_needed); | |
| 25 virtual ~WeeklyActivityStorage(); | |
| 26 | |
| 27 // Returns the number of clicks for the given week. | |
| 28 int ReadClicks(int week_number); | |
| 29 // Writes |value| into the number of clicks for the given |week_number|. | |
| 30 void WriteClicks(int week_number, int value); | |
| 31 | |
| 32 // Returns the number of impressions for the given week. | |
| 33 int ReadImpressions(int week_number); | |
| 34 // Writes |value| into the number of impressions for the given |week_number|. | |
| 35 void WriteImpressions(int week_number, int value); | |
| 36 | |
| 37 // Initializes recording of activity for the given |week_number|. | |
| 38 // This must be called for each week before reading or writing any data | |
| 39 // for that week. | |
| 40 void InitActivity(int week_number); | |
|
marq (ping after 24h)
2016/09/02 13:09:45
Any reason why calling this isn't handled automati
Donn Denman
2016/09/02 22:48:00
Yes. Renamed the method and added this comment to
| |
| 41 // Returns whether the given |week_number| has data, based on whether | |
| 42 // InitActivity has ever been called for that week. | |
| 43 bool HasActivity(int week_number); | |
|
Theresa
2016/09/02 16:25:29
I think this method the "Activity" methods need di
Donn Denman
2016/09/02 22:48:00
Done.
| |
| 44 // Clears the click and impression counters for the given |week_number|. | |
| 45 void ClearActivity(int week_number); | |
| 46 | |
| 47 // Reads and returns the value keyed by |storage_bucket|. | |
| 48 // If there is no stored value associated with the given bucket then 0 is | |
| 49 // returned. | |
| 50 virtual int ReadStorage(std::string storage_bucket) = 0; | |
| 51 // Overwrites the |value| to the storage bucket keyed by |storage_bucket|, | |
| 52 // regardless of whether there is an existing value in the given bucket. | |
| 53 virtual void WriteStorage(std::string storage_bucket, int value) = 0; | |
| 54 | |
| 55 private: | |
| 56 // Returns the string key of the storage bin for the given week |which_week|. | |
| 57 std::string GetWeekKey(int which_week); | |
| 58 // Returns the string key for the "clicks" storage bin for the given week | |
| 59 // |which_week|. | |
| 60 std::string GetWeekClicksKey(int which_week); | |
| 61 // Returns the string key for the "impressions" storage bin for the given week | |
| 62 // |which_week|. | |
| 63 std::string GetWeekImpressionsKey(int which_week); | |
| 64 | |
| 65 // Reads and returns the integer keyed by |storage_key|. | |
| 66 // If there is no value for the given key then 0 is returned. | |
| 67 int ReadInt(std::string storage_key); | |
| 68 // Writes the integer |value| to the storage bucket keyed by |storage_key|. | |
| 69 void WriteInt(std::string storage_key, int value); | |
| 70 | |
| 71 // Ensures that activity data is initialized for the given week |which_week|. | |
| 72 void EnsureHasActivity(int which_week); | |
| 73 | |
| 74 // The number of weeks of data that this instance needs to support. | |
| 75 int weeks_needed_; | |
| 76 | |
| 77 DISALLOW_COPY_AND_ASSIGN(WeeklyActivityStorage); | |
| 78 }; | |
| 79 | |
| 80 } // namespace contextual_search | |
| 81 | |
| 82 #endif // COMPONENTS_CONTEXTUAL_SEARCH_BROWSER_WEEKLY_ACTIVITY_STORAGE_H_ | |
| OLD | NEW |