OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 // An interface to platform-specific storage of IncidentReportingService prune |
| 6 // state. |
| 7 |
| 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_PLATFORM_STATE_STORE_H_ |
| 9 #define CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_PLATFORM_STATE_STORE_H_ |
| 10 |
| 11 #include <stdint.h> |
| 12 #include <string> |
| 13 |
| 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "build/build_config.h" |
| 16 |
| 17 // Certain platforms provide their own storage of protobuf-serialized prune |
| 18 // state. On platforms where it is not supported, Load() and Store() are noops. |
| 19 #if defined(OS_WIN) |
| 20 // Store the state in the registry on Windows. |
| 21 #define USE_PLATFORM_STATE_STORE |
| 22 #endif |
| 23 |
| 24 class Profile; |
| 25 |
| 26 namespace base { |
| 27 class DictionaryValue; |
| 28 } |
| 29 |
| 30 namespace safe_browsing { |
| 31 namespace platform_state_store { |
| 32 |
| 33 // Loads the platform-specific storage for |profile|. Returns null if there is |
| 34 // no such storage for the current platform or in case of error; otherwise, a |
| 35 // (possibly empty) dictionary. |
| 36 scoped_ptr<base::DictionaryValue> Load(Profile* profile); |
| 37 |
| 38 // Stores the state for |profile| in |incidents_sent| into platform-specific |
| 39 // storage if there is such for the current platform. |
| 40 void Store(Profile* profile, const base::DictionaryValue* incidents_sent); |
| 41 |
| 42 #if defined(USE_PLATFORM_STATE_STORE) |
| 43 |
| 44 // All declarations and definitions from this point forward are for use by |
| 45 // implementations in platform-specific source files, or are exposed for the |
| 46 // sake of testing. |
| 47 |
| 48 // The result of loading platform-specific state. This is a histogram type; do |
| 49 // not reorder. |
| 50 enum class PlatformStateStoreLoadResult : int32_t { |
| 51 SUCCESS = 0, |
| 52 CLEARED_DATA = 1, |
| 53 CLEARED_NO_DATA = 2, |
| 54 DATA_CLEAR_FAILED = 3, |
| 55 OPEN_FAILED = 4, |
| 56 READ_FAILED = 5, |
| 57 PARSE_ERROR = 6, |
| 58 NUM_RESULTS |
| 59 }; |
| 60 |
| 61 // A platform-specific function to read store data for |profile| into |data|. |
| 62 // Returns SUCCESS if |data| was populated, or a load result value indicating |
| 63 // why no data was read. |
| 64 PlatformStateStoreLoadResult ReadStoreData(Profile* profile, std::string* data); |
| 65 |
| 66 // A platform-specific function to write store data for |profile| from |data|. |
| 67 void WriteStoreData(Profile* profile, const std::string& data); |
| 68 |
| 69 // Serializes the |incidents_sent| preference into |data|, replacing its |
| 70 // contents. Exposed for testing. |
| 71 void SerializeIncidentsSent(const base::DictionaryValue* incidents_sent, |
| 72 std::string* data); |
| 73 |
| 74 // Deserializes |data| into |value_dict|. Returns SUCCESS if |data| is empty or |
| 75 // fully processed. Exposed for testing. |
| 76 PlatformStateStoreLoadResult DeserializeIncidentsSent( |
| 77 const std::string& data, |
| 78 base::DictionaryValue* value_dict); |
| 79 |
| 80 #endif // USE_PLATFORM_STATE_STORE |
| 81 |
| 82 } // namespace platform_state_store |
| 83 } // namespace safe_browsing |
| 84 |
| 85 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_PLATFORM_STATE_STORE_
H_ |
OLD | NEW |