File: install_event_log_uploader_base.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (98 lines) | stat: -rw-r--r-- 4,214 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_POLICY_REPORTING_INSTALL_EVENT_LOG_UPLOADER_BASE_H_
#define CHROME_BROWSER_ASH_POLICY_REPORTING_INSTALL_EVENT_LOG_UPLOADER_BASE_H_

#include "base/memory/raw_ptr.h"
#include "components/policy/core/common/cloud/cloud_policy_client.h"

class Profile;

namespace policy {

// Adapter between the system that captures and stores app install event
// logs and the policy system which uploads them to the management server. The
// app refers to extension or ARC++ app. When asked to upload event logs,
// retrieves them from the log store asynchronously and forwards them for
// upload, scheduling retries with exponential backoff in case of upload
// failures.
class InstallEventLogUploaderBase : public CloudPolicyClient::Observer {
 public:
  // |client| must outlive |this|.
  InstallEventLogUploaderBase(CloudPolicyClient* client, Profile* profile);

  // Will construct a non-CloudPolicyClient::Observer version of
  // InstallEventLogUploaderBase.
  // TODO(crbug.com/40689377) This exists to support the move to using
  // reporting::ReportQueue, which owns its own CloudPolicyClient. Once
  // ArcInstallEventLogUploader is ready to move to using
  // reporting::ReportQueue, we can likely do a small refactor removing all
  // references to CloudPolicyClient from InstallEventLogUploaderBase and its
  // children.
  explicit InstallEventLogUploaderBase(Profile* profile);

  ~InstallEventLogUploaderBase() override;

  // Requests log upload. If there is no pending upload yet, asks the delegate
  // to serialize the current logs into a protobuf and sends this to the server.
  // If an upload is pending already, no new upload is scheduled. However, the
  // delegate is notified when the pending upload succeeds and may request
  // another upload at that point.
  //
  // Once requested, the upload is retried with exponential backoff until it
  // succeeds. For each retry, the delegate is asked to serialize logs anew, so
  // that the most recent logs are uploaded.
  //
  // Must only be calling after setting a delegate.
  void RequestUpload();

  // Cancels the pending log upload, if any. Any log currently being serialized
  // by the delegate or uploaded by the client is discarded.
  void CancelUpload();

  virtual void CancelClientUpload() = 0;
  virtual void CheckDelegateSet() = 0;

  // CloudPolicyClient::Observer:
  // Uploads are only possible while the client is registered with the server.
  // If an upload is requested while the client is not registered, the request
  // is stored until the client registers. If the client loses its registration
  // while an upload is pending, the upload is canceled and stored for retry
  // when the client registers again. A stored request is handled as a brand new
  // request when the client registers, by asking the delegate to serialize logs
  // and with the exponential backoff reset to its minimum.
  void OnRegistrationStateChanged(CloudPolicyClient* client) override;

  // Asks the delegate to serialize the current logs into a protobuf and pass it
  // a callback.
  virtual void StartSerialization() = 0;

  // |result| contains the result of the most recent log upload.
  // Forwards success to the delegate and schedules a retry with exponential
  // backoff in case of failure.
  void OnUploadDone(CloudPolicyClient::Result result);

  // Notifies delegate on success of upload.
  virtual void OnUploadSuccess() = 0;

  // Posts a new task to start serialization after |retry_backoff_ms_| ms.
  virtual void PostTaskForStartSerialization() = 0;

  // The client used to upload logs to the server.
  raw_ptr<CloudPolicyClient> client_ = nullptr;

  // Profile used to fetch the context attributes for report request.
  raw_ptr<Profile> profile_ = nullptr;

  // |true| if log upload has been requested and not completed yet.
  bool upload_requested_ = false;

  // The backoff, in milliseconds, for the next upload retry.
  int retry_backoff_ms_;
};

}  // namespace policy

#endif  // CHROME_BROWSER_ASH_POLICY_REPORTING_INSTALL_EVENT_LOG_UPLOADER_BASE_H_