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

Unified Diff: base/prefs/json_pref_store.h

Issue 1128733002: Update from https://crrev.com/328418 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/posix/unix_domain_socket_linux_unittest.cc ('k') | base/prefs/json_pref_store.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/prefs/json_pref_store.h
diff --git a/base/prefs/json_pref_store.h b/base/prefs/json_pref_store.h
index 16e431b3c92f014cbf57afc766710f629d23995c..1badcf2257ca3c3c8e058c4a55fd80e657a5e12d 100644
--- a/base/prefs/json_pref_store.h
+++ b/base/prefs/json_pref_store.h
@@ -13,9 +13,10 @@
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/files/important_file_writer.h"
+#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h"
-#include "base/message_loop/message_loop_proxy.h"
#include "base/observer_list.h"
#include "base/prefs/base_prefs_export.h"
#include "base/prefs/persistent_pref_store.h"
@@ -24,11 +25,17 @@
class PrefFilter;
namespace base {
+class Clock;
class DictionaryValue;
class FilePath;
+class HistogramBase;
class SequencedTaskRunner;
class SequencedWorkerPool;
class Value;
+FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestBasic);
+FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestSinglePeriod);
+FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestMultiplePeriods);
+FORWARD_DECLARE_TEST(JsonPrefStoreTest, WriteCountHistogramTestPeriodWithGaps);
}
// A writable PrefStore implementation that is used for user preferences.
@@ -98,6 +105,63 @@ class BASE_PREFS_EXPORT JsonPrefStore
const base::Closure& on_next_successful_write);
private:
+ // Represents a histogram for recording the number of writes to the pref file
+ // that occur every kHistogramWriteReportIntervalInMins minutes.
+ class BASE_PREFS_EXPORT WriteCountHistogram {
+ public:
+ static const int32_t kHistogramWriteReportIntervalMins;
+
+ WriteCountHistogram(const base::TimeDelta& commit_interval,
+ const base::FilePath& path);
+ // Constructor for testing. |clock| is a test Clock that is used to retrieve
+ // the time.
+ WriteCountHistogram(const base::TimeDelta& commit_interval,
+ const base::FilePath& path,
+ scoped_ptr<base::Clock> clock);
+ ~WriteCountHistogram();
+
+ // Record that a write has occured.
+ void RecordWriteOccured();
+
+ // Reports writes (that have not yet been reported) in all of the recorded
+ // intervals that have elapsed up until current time.
+ void ReportOutstandingWrites();
+
+ base::HistogramBase* GetHistogram();
+
+ private:
+ // The minimum interval at which writes can occur.
+ const base::TimeDelta commit_interval_;
+
+ // The path to the file.
+ const base::FilePath path_;
+
+ // Clock which is used to retrieve the current time.
+ scoped_ptr<base::Clock> clock_;
+
+ // The interval at which to report write counts.
+ const base::TimeDelta report_interval_;
+
+ // The time at which the last histogram value was reported for the number
+ // of write counts.
+ base::Time last_report_time_;
+
+ // The number of writes that have occured since the last write count was
+ // reported.
+ uint32_t writes_since_last_report_;
+
+ DISALLOW_COPY_AND_ASSIGN(WriteCountHistogram);
+ };
+
+ FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest,
+ WriteCountHistogramTestBasic);
+ FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest,
+ WriteCountHistogramTestSinglePeriod);
+ FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest,
+ WriteCountHistogramTestMultiplePeriods);
+ FRIEND_TEST_ALL_PREFIXES(base::JsonPrefStoreTest,
+ WriteCountHistogramTestPeriodWithGaps);
+
~JsonPrefStore() override;
// This method is called after the JSON file has been read. It then hands
@@ -144,6 +208,8 @@ class BASE_PREFS_EXPORT JsonPrefStore
std::set<std::string> keys_need_empty_value_;
+ WriteCountHistogram write_count_histogram_;
+
DISALLOW_COPY_AND_ASSIGN(JsonPrefStore);
};
« no previous file with comments | « base/posix/unix_domain_socket_linux_unittest.cc ('k') | base/prefs/json_pref_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698