Chromium Code Reviews| Index: google_apis/gcm/gcm_stats_recorder.h |
| diff --git a/google_apis/gcm/gcm_stats_recorder.h b/google_apis/gcm/gcm_stats_recorder.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1e926c0cd66fc2482bdea08a9b6f140fc24ceb94 |
| --- /dev/null |
| +++ b/google_apis/gcm/gcm_stats_recorder.h |
| @@ -0,0 +1,99 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ |
| +#define GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ |
| + |
| +#include <deque> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/compiler_specific.h" |
| +#include "base/memory/ref_counted.h" |
|
jianli
2014/03/21 18:25:27
nit: not needed
juyik
2014/03/26 04:06:03
Done.
|
| +#include "base/memory/weak_ptr.h" |
|
jianli
2014/03/21 18:25:27
ditto
juyik
2014/03/26 04:06:03
Done.
|
| +#include "base/time/time.h" |
| +#include "google_apis/gcm/base/gcm_export.h" |
| + |
| +namespace gcm { |
| + |
| +// Records GCM internal stats and activities for debugging purpose. Recording |
| +// can be turned on/off by calling SetRecording(...) function. It is turned off |
| +// by default. |
| +// This class is not thread safe. It is meant to be owned by a gcm client |
| +// instance. |
| +class GCM_EXPORT GCMStatsRecorder { |
| + public: |
| + // Contains data that are common to all activity kinds below. |
| + struct GCM_EXPORT Activity { |
| + Activity(); |
| + virtual ~Activity(); |
| + |
| + base::Time time; |
| + std::string event; // A short description of the event. |
| + std::string details; // Any additional detail about the event. |
| + }; |
| + |
| + // Contains relevant data of a send-message step. |
| + struct GCM_EXPORT SendingActivity : Activity { |
| + SendingActivity(); |
| + virtual ~SendingActivity() OVERRIDE; |
| + |
| + std::string app_id; |
| + std::string receiver_id; |
| + std::string message_id; |
| + }; |
| + |
| + GCMStatsRecorder(); |
| + virtual ~GCMStatsRecorder(); |
| + |
| + // Indicates whether the recorder is currently recording activities or not. |
| + bool is_recording() const { |
| + return is_recording_; |
| + } |
| + |
| + // Turns recording on/off. |
| + void SetRecording(bool recording); |
| + |
| + // Clear all recorded activities. |
| + void Clear(); |
| + |
| + // Record a sending activity. |
| + void RecordSending(const std::string& app_id, |
| + const std::string& receiver_id, |
| + const std::string& message_id, |
| + const std::string& event, |
| + const std::string& details); |
| + // Record a sending activity together with UMA enumeration metrics. |
| + void RecordSendingWithUMAEnum(const std::string& app_id, |
| + const std::string& receiver_id, |
| + const std::string& message_id, |
| + const std::string& event, |
| + const std::string& details, |
| + const std::string& uma_name, |
| + int uma_value, |
| + int uma_value_bound); |
| + // Record a sending activity together with UMA count metrics. |
| + void RecordSendingWithUMACounts(const std::string& app_id, |
| + const std::string& receiver_id, |
| + const std::string& message_id, |
| + const std::string& event, |
| + const std::string& details, |
| + const std::string& uma_name, |
| + int uma_value); |
| + |
| + const std::deque<SendingActivity>& sending_activities() const { |
| + return sending_activities_; |
| + } |
| + |
| + protected: |
| + bool is_recording_; |
| + |
| + std::deque<SendingActivity> sending_activities_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(GCMStatsRecorder); |
| +}; |
| + |
| +} // namespace gcm |
| + |
| +#endif // GOOGLE_APIS_GCM_GCM_STATS_RECORDER_H_ |