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