1 // Copyright 2020 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 
5 #ifndef CHROME_CREDENTIAL_PROVIDER_GAIACP_EVENT_LOGS_UPLOAD_MANAGER_H_
6 #define CHROME_CREDENTIAL_PROVIDER_GAIACP_EVENT_LOGS_UPLOAD_MANAGER_H_
7 
8 #include "base/strings/string16.h"
9 #include "base/time/time.h"
10 #include "base/values.h"
11 #include "base/win/windows_types.h"
12 #include "url/gurl.h"
13 
14 namespace credential_provider {
15 
16 // Manager used to handle requests to upload GCPW event viewer logs
17 // to GEM cloud storage.
18 class EventLogsUploadManager {
19  public:
20   // Get the Event log manager instance.
21   static EventLogsUploadManager* Get();
22 
23   // Upload event viewer logs to GEM cloud storage using |access_token| for
24   // authentication and authorization.
25   HRESULT UploadEventViewerLogs(const std::string& access_token);
26 
27   // Get the URL of GCPW service for HTTP request for uploading event
28   // viewer logs.
29   GURL GetGcpwServiceUploadEventViewerLogsUrl();
30 
31   // Structure to hold the information read for each event log entry.
32   struct EventLogEntry {
33     struct TimeStamp {
34       uint64_t seconds;
35       uint32_t nanos;
TimeStampEventLogEntry::TimeStamp36       TimeStamp() : seconds(0), nanos(0) {}
TimeStampEventLogEntry::TimeStamp37       TimeStamp(uint64_t seconds, uint32_t nanos)
38           : seconds(seconds), nanos(nanos) {}
39     };
40 
41     // Event Record ID of the event log entry.
42     uint64_t event_id;
43 
44     // System time-stamp of when log was written into the event log.
45     TimeStamp created_ts;
46 
47     // The data portion of the event log.
48     base::string16 data;
49 
50     // Severity level of the log entry.
51     uint32_t severity_level;
52 
EventLogEntryEventLogEntry53     EventLogEntry() : event_id(0), severity_level(0) {}
EventLogEntryEventLogEntry54     EventLogEntry(uint64_t id,
55                   const TimeStamp& ts,
56                   base::string16 data,
57                   uint32_t level)
58         : event_id(id), created_ts(ts), data(data), severity_level(level) {}
59 
60     // Converts to dictionary in a base::Value.
61     void ToValue(base::Value& dict) const;
62   };
63 
64  protected:
65   // Returns the storage used for the instance pointer.
66   static EventLogsUploadManager** GetInstanceStorage();
67 
68   EventLogsUploadManager();
69   virtual ~EventLogsUploadManager();
70 
71   HRESULT upload_status_;
72   uint64_t num_event_logs_uploaded_;
73 
74  private:
75   // Makes the upload HTTP request using the provided |access_token| for
76   // the upload chunk with id |chunk_id| and the log entries specified
77   // as a list in |log_entries|.
78   HRESULT MakeUploadLogChunkRequest(const std::string& access_token,
79                                     uint64_t chunk_id,
80                                     std::unique_ptr<base::Value> log_entries);
81 };
82 
83 }  // namespace credential_provider
84 
85 #endif  // CHROME_CREDENTIAL_PROVIDER_GAIACP_EVENT_LOGS_UPLOAD_MANAGER_H_
86