Chromium Code Reviews| Index: components/data_reduction_proxy/browser/data_reduction_proxy_delayed_pref_service.h |
| diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_delayed_pref_service.h b/components/data_reduction_proxy/browser/data_reduction_proxy_delayed_pref_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9acbd6e5e45247e2e3b4d78082fcecdfd76c7dba |
| --- /dev/null |
| +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_delayed_pref_service.h |
| @@ -0,0 +1,87 @@ |
| +// Copyright 2014 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_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_DELAYED_PREF_SERVICE_H_ |
| +#define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_DELAYED_PREF_SERVICE_H_ |
| + |
| +#include <map> |
| + |
| +#include "base/memory/weak_ptr.h" |
|
bengr
2014/08/14 17:39:42
#include "base/time/time.h" here and remove the fo
megjablon
2014/08/26 19:28:41
Done.
|
| + |
| +class PrefService; |
| + |
| +namespace base { |
| + class ListValue; |
|
bengr
2014/08/14 17:39:42
remove indent.
megjablon
2014/08/26 19:28:41
Done.
|
| + class SequencedTaskRunner; |
| + class TimeDelta; |
| +} |
| + |
| +namespace data_reduction_proxy { |
| + |
| +// Data reduction proxy delayed pref service reduces the number calls to pref |
| +// service by storing prefs in memory and writing to the given PrefService after |
| +// |delay| amount of time. If |delay| is zero, the delayed pref service writes |
| +// directly to the PrefService and does not store the prefs in memory. All |
| +// variables are stored and should be read on the UI thread. |
|
bengr
2014/08/14 17:39:42
should be stored and read...
megjablon
2014/08/26 19:28:41
Done.
|
| +class DataReductionProxyDelayedPrefService |
| + : public base::SupportsWeakPtr<DataReductionProxyDelayedPrefService>{ |
| +public: |
| + typedef std::map<const char*, int64> DataReductionProxyPrefMap; |
| + typedef std::map<const char*, base::ListValue*> |
| + DataReductionProxyListPrefMap; |
|
bengr
2014/08/14 17:39:42
indent 4
megjablon
2014/08/26 19:28:41
Done.
|
| + |
| + // Constructs a data reduction proxy delayed pref service object using |
| + // |pref_service|. Writes prefs to |pref_service| after |delay| amount of time |
| + // and stores in |pref_map_| and |list_pref_map| between writes. If |delay| is |
| + // zero, writes directly to the PrefService and does not store in the maps. |
| + DataReductionProxyDelayedPrefService( |
| + PrefService* pref_service, |
| + scoped_refptr<base::SequencedTaskRunner> task_runner, |
| + base::TimeDelta delay); |
| + virtual ~DataReductionProxyDelayedPrefService(); |
| + |
| + // Gets the int64 pref at |pref_path| from the |DataReductionProxyPrefMap|. |
| + // If |pref_path| is not in the map, gets the pref from |pref_service_| and |
| + // stores it in the map. |
| + int64 GetInt64(const char* pref_path); |
| + |
| + // Updates the pref value in the |DataReductionProxyPrefMap| map. If |
| + // |pref_path| is not in the map, gets the pref from |pref_service_| and |
| + // stores it in the map. The pref is later written to |pref service_|. |
| + void SetInt64(const char* pref_path, int64 pref_value); |
| + |
| + // Gets the pref list at |pref_path| from the |DataReductionProxyPrefMap|. |
| + // If |pref_path| is not in the map, gets the pref from |pref_service_| and |
| + // stores it in the map. |
| + base::ListValue* GetList(const char* pref_path); |
| + |
| +private: |
| + // Writes the prefs stored in |DataReductionProxyPrefMap| and |
| + // |DataReductionProxyListPrefMap| to |pref_service|. |
| + void WritePrefs(); |
| + |
| + // Writes the stored prefs to |pref_service| and then posts another a delayed |
| + // task to write prefs again in |kMinutesBetweenWrites|. |
| + void WritePrefsAndPost(); |
| + |
| + // Copies the values at each index of |from_list| to the same index in |
| + // |to_list|. |
| + void TransferList(const base::ListValue& from_list, |
| + base::ListValue* to_list); |
| + |
| + // Gets an int64, stored as a string, in a ListPref at the specified |
| + // index. |
| + int64 GetListPrefInt64Value(const base::ListValue& list_update, size_t index); |
| + |
| + PrefService* pref_service_; |
| + scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| + base::TimeDelta delay_; |
| + bool delayed_task_posted_; |
| + DataReductionProxyPrefMap* pref_map_; |
|
bengr
2014/08/14 17:39:42
Why do these need to be pointers?
megjablon
2014/08/26 19:28:41
Done.
|
| + DataReductionProxyListPrefMap* list_pref_map_; |
| +}; |
| + |
| +} // namespace data_reduction_proxy |
| + |
| +#endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_DELAYED_PREF_SERVICE_H_ |