Home | History | Annotate | Download | only in uploader
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef METRICSD_UPLOADER_METRICS_LOG_H_
     18 #define METRICSD_UPLOADER_METRICS_LOG_H_
     19 
     20 #include <string>
     21 
     22 #include <base/files/file_path.h>
     23 #include <base/macros.h>
     24 
     25 #include "uploader/metrics_log_base.h"
     26 
     27 // This file defines a set of user experience metrics data recorded by
     28 // the MetricsService. This is the unit of data that is sent to the server.
     29 class SystemProfileSetter;
     30 
     31 // This class provides base functionality for logging metrics data.
     32 class MetricsLog : public metrics::MetricsLogBase {
     33  public:
     34   // The constructor doesn't set any metadata. The metadata is only set by a
     35   // SystemProfileSetter.
     36   MetricsLog();
     37 
     38   // Increment the crash counters in the protobuf.
     39   // These methods don't have to be thread safe as metrics logs are only
     40   // accessed by the uploader thread.
     41   void IncrementUserCrashCount(unsigned int count);
     42   void IncrementKernelCrashCount(unsigned int count);
     43   void IncrementUncleanShutdownCount(unsigned int count);
     44 
     45   // Populate the system profile with system information using setter.
     46   bool PopulateSystemProfile(SystemProfileSetter* setter);
     47 
     48   // Load the log from |path|.
     49   bool LoadFromFile(const base::FilePath& path);
     50 
     51   // Save this log to |path|.
     52   bool SaveToFile(const base::FilePath& path);
     53 
     54  private:
     55   friend class UploadServiceTest;
     56   FRIEND_TEST(UploadServiceTest, CurrentLogSavedAndResumed);
     57   FRIEND_TEST(UploadServiceTest, LogContainsAggregatedValues);
     58   FRIEND_TEST(UploadServiceTest, LogContainsCrashCounts);
     59   FRIEND_TEST(UploadServiceTest, LogKernelCrash);
     60   FRIEND_TEST(UploadServiceTest, LogUncleanShutdown);
     61   FRIEND_TEST(UploadServiceTest, LogUserCrash);
     62   FRIEND_TEST(UploadServiceTest, UnknownCrashIgnored);
     63 
     64   DISALLOW_COPY_AND_ASSIGN(MetricsLog);
     65 };
     66 
     67 #endif  // METRICSD_UPLOADER_METRICS_LOG_H_
     68