extensions_activity.h 1.9 KB

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