| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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 SYNC_UTIL_EXTENSIONS_ACTIVITY_H_ | |
| 6 #define SYNC_UTIL_EXTENSIONS_ACTIVITY_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <string> | |
| 12 | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/synchronization/lock.h" | |
| 15 #include "sync/base/sync_export.h" | |
| 16 | |
| 17 namespace syncer { | |
| 18 | |
| 19 // A storage to record usage of extensions APIs to send to sync | |
| 20 // servers, with the ability to purge data once sync servers have | |
| 21 // acknowledged it (successful commit response). | |
| 22 class SYNC_EXPORT ExtensionsActivity | |
| 23 : public base::RefCountedThreadSafe<ExtensionsActivity> { | |
| 24 public: | |
| 25 // A data record of activity performed by extension |extension_id|. | |
| 26 struct SYNC_EXPORT Record { | |
| 27 Record(); | |
| 28 ~Record(); | |
| 29 | |
| 30 // The human-readable ID identifying the extension responsible | |
| 31 // for the activity reported in this Record. | |
| 32 std::string extension_id; | |
| 33 | |
| 34 // How many times the extension successfully invoked a write | |
| 35 // operation through the bookmarks API since the last CommitMessage. | |
| 36 uint32_t bookmark_write_count; | |
| 37 }; | |
| 38 | |
| 39 typedef std::map<std::string, Record> Records; | |
| 40 | |
| 41 ExtensionsActivity(); | |
| 42 | |
| 43 // Fill |buffer| with all current records and then clear the | |
| 44 // internal records. Called on sync thread to append records to sync commit | |
| 45 // message. | |
| 46 void GetAndClearRecords(Records* buffer); | |
| 47 | |
| 48 // Merge |records| with the current set of records. Called on sync thread to | |
| 49 // put back records if sync commit failed. | |
| 50 void PutRecords(const Records& records); | |
| 51 | |
| 52 // Increment write count of the specified extension. | |
| 53 void UpdateRecord(const std::string& extension_id); | |
| 54 | |
| 55 private: | |
| 56 friend class base::RefCountedThreadSafe<ExtensionsActivity>; | |
| 57 ~ExtensionsActivity(); | |
| 58 | |
| 59 Records records_; | |
| 60 mutable base::Lock records_lock_; | |
| 61 }; | |
| 62 | |
| 63 } // namespace syncer | |
| 64 | |
| 65 #endif // SYNC_UTIL_EXTENSIONS_ACTIVITY_H_ | |
| OLD | NEW |