Chromium Code Reviews| Index: components/contextual_search/browser/weekly_activity_storage.h |
| diff --git a/components/contextual_search/browser/weekly_activity_storage.h b/components/contextual_search/browser/weekly_activity_storage.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f0b098c99b378d75627d3557443ad756600d11c8 |
| --- /dev/null |
| +++ b/components/contextual_search/browser/weekly_activity_storage.h |
| @@ -0,0 +1,82 @@ |
| +// Copyright 2016 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_CONTEXTUAL_SEARCH_BROWSER_WEEKLY_ACTIVITY_STORAGE_H_ |
| +#define COMPONENTS_CONTEXTUAL_SEARCH_BROWSER_WEEKLY_ACTIVITY_STORAGE_H_ |
| + |
| +#include <string> |
| +#include <unordered_map> |
| + |
| +#include "base/macros.h" |
| + |
| +namespace contextual_search { |
| + |
| +// An abstract class that stores weekly activity in device-specific |
| +// integer storage. Allows callers to read and write user actions to persistent |
| +// storage on the device by overriding the ReadStorage and WriteStorage calls. |
| +// A user view of some UX is an "Impression", and user interaction is considered |
| +// a "Click" even if the triggering gesture was something else. Together they |
| +// produce the Click-Through-Rate, or CTR. |
| +class WeeklyActivityStorage { |
| + public: |
| + // Constructs an instance that will manage at least |weeks_needed| week data. |
| + WeeklyActivityStorage(int weeks_needed); |
| + virtual ~WeeklyActivityStorage(); |
| + |
| + // Returns the number of clicks for the given week. |
| + int ReadClicks(int week_number); |
| + // Writes |value| into the number of clicks for the given |week_number|. |
| + void WriteClicks(int week_number, int value); |
| + |
| + // Returns the number of impressions for the given week. |
| + int ReadImpressions(int week_number); |
| + // Writes |value| into the number of impressions for the given |week_number|. |
| + void WriteImpressions(int week_number, int value); |
| + |
| + // Initializes recording of activity for the given |week_number|. |
| + // This must be called for each week before reading or writing any data |
| + // for that week. |
| + 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
|
| + // Returns whether the given |week_number| has data, based on whether |
| + // InitActivity has ever been called for that week. |
| + 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.
|
| + // Clears the click and impression counters for the given |week_number|. |
| + void ClearActivity(int week_number); |
| + |
| + // Reads and returns the value keyed by |storage_bucket|. |
| + // If there is no stored value associated with the given bucket then 0 is |
| + // returned. |
| + virtual int ReadStorage(std::string storage_bucket) = 0; |
| + // Overwrites the |value| to the storage bucket keyed by |storage_bucket|, |
| + // regardless of whether there is an existing value in the given bucket. |
| + virtual void WriteStorage(std::string storage_bucket, int value) = 0; |
| + |
| + private: |
| + // Returns the string key of the storage bin for the given week |which_week|. |
| + std::string GetWeekKey(int which_week); |
| + // Returns the string key for the "clicks" storage bin for the given week |
| + // |which_week|. |
| + std::string GetWeekClicksKey(int which_week); |
| + // Returns the string key for the "impressions" storage bin for the given week |
| + // |which_week|. |
| + std::string GetWeekImpressionsKey(int which_week); |
| + |
| + // Reads and returns the integer keyed by |storage_key|. |
| + // If there is no value for the given key then 0 is returned. |
| + int ReadInt(std::string storage_key); |
| + // Writes the integer |value| to the storage bucket keyed by |storage_key|. |
| + void WriteInt(std::string storage_key, int value); |
| + |
| + // Ensures that activity data is initialized for the given week |which_week|. |
| + void EnsureHasActivity(int which_week); |
| + |
| + // The number of weeks of data that this instance needs to support. |
| + int weeks_needed_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WeeklyActivityStorage); |
| +}; |
| + |
| +} // namespace contextual_search |
| + |
| +#endif // COMPONENTS_CONTEXTUAL_SEARCH_BROWSER_WEEKLY_ACTIVITY_STORAGE_H_ |