| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_ANDROID_HISTORY_REPORT_USAGE_REPORTS_BUFFER_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_HISTORY_REPORT_USAGE_REPORTS_BUFFER_SERVICE_H_ |
| 6 #define CHROME_BROWSER_ANDROID_HISTORY_REPORT_USAGE_REPORTS_BUFFER_SERVICE_H_ | 6 #define CHROME_BROWSER_ANDROID_HISTORY_REPORT_USAGE_REPORTS_BUFFER_SERVICE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <string> | 10 #include <string> |
| 9 #include <vector> | 11 #include <vector> |
| 10 | 12 |
| 13 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
| 13 | 16 |
| 14 namespace base { | 17 namespace base { |
| 15 class FilePath; | 18 class FilePath; |
| 16 } // namespace base | 19 } // namespace base |
| 17 | 20 |
| 18 namespace history_report { | 21 namespace history_report { |
| 19 | 22 |
| 20 class UsageReport; | 23 class UsageReport; |
| 21 class UsageReportsBufferBackend; | 24 class UsageReportsBufferBackend; |
| 22 | 25 |
| 23 // This class is intended to be created once and not destroyed until process is | 26 // This class is intended to be created once and not destroyed until process is |
| 24 // killed. |backend_| is assumed to be a long lived pointer. | 27 // killed. |backend_| is assumed to be a long lived pointer. |
| 25 class UsageReportsBufferService { | 28 class UsageReportsBufferService { |
| 26 public: | 29 public: |
| 27 explicit UsageReportsBufferService(const base::FilePath& dir); | 30 explicit UsageReportsBufferService(const base::FilePath& dir); |
| 28 ~UsageReportsBufferService(); | 31 ~UsageReportsBufferService(); |
| 29 | 32 |
| 30 // Init buffer. All calls to buffer before it's initialized are ignored. It's | 33 // Init buffer. All calls to buffer before it's initialized are ignored. It's |
| 31 // asynchronous. | 34 // asynchronous. |
| 32 void Init(); | 35 void Init(); |
| 33 | 36 |
| 34 // Add report about page visit to the buffer. It's asynchronous. | 37 // Add report about page visit to the buffer. It's asynchronous. |
| 35 void AddVisit(const std::string& id, int64 timestamp_ms, bool typed_visit); | 38 void AddVisit(const std::string& id, int64_t timestamp_ms, bool typed_visit); |
| 36 | 39 |
| 37 // Get a batch of usage reports of size up to |batch_size|. It's synchronous. | 40 // Get a batch of usage reports of size up to |batch_size|. It's synchronous. |
| 38 scoped_ptr<std::vector<UsageReport> > GetUsageReportsBatch(int32 batch_size); | 41 scoped_ptr<std::vector<UsageReport>> GetUsageReportsBatch(int32_t batch_size); |
| 39 | 42 |
| 40 // Remove given usage reports from buffer. It's synchronous. | 43 // Remove given usage reports from buffer. It's synchronous. |
| 41 void Remove(const std::vector<std::string>& report_ids); | 44 void Remove(const std::vector<std::string>& report_ids); |
| 42 | 45 |
| 43 // Clears buffer by removing all usage reports from it. | 46 // Clears buffer by removing all usage reports from it. |
| 44 void Clear(); | 47 void Clear(); |
| 45 | 48 |
| 46 // Dumps internal state to string. | 49 // Dumps internal state to string. |
| 47 std::string Dump(); | 50 std::string Dump(); |
| 48 | 51 |
| 49 private: | 52 private: |
| 50 // Token used to serialize buffer operations. | 53 // Token used to serialize buffer operations. |
| 51 base::SequencedWorkerPool::SequenceToken worker_pool_token_; | 54 base::SequencedWorkerPool::SequenceToken worker_pool_token_; |
| 52 // Non thread safe backend. | 55 // Non thread safe backend. |
| 53 scoped_ptr<UsageReportsBufferBackend> backend_; | 56 scoped_ptr<UsageReportsBufferBackend> backend_; |
| 54 | 57 |
| 55 DISALLOW_COPY_AND_ASSIGN(UsageReportsBufferService); | 58 DISALLOW_COPY_AND_ASSIGN(UsageReportsBufferService); |
| 56 }; | 59 }; |
| 57 | 60 |
| 58 } // namespace history_report | 61 } // namespace history_report |
| 59 | 62 |
| 60 #endif // CHROME_BROWSER_ANDROID_HISTORY_REPORT_USAGE_REPORTS_BUFFER_SERVICE_H_ | 63 #endif // CHROME_BROWSER_ANDROID_HISTORY_REPORT_USAGE_REPORTS_BUFFER_SERVICE_H_ |
| OLD | NEW |