File: sync_error.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (128 lines) | stat: -rw-r--r-- 4,763 bytes parent folder | download
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2012 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 COMPONENTS_SYNC_MODEL_SYNC_ERROR_H_
#define COMPONENTS_SYNC_MODEL_SYNC_ERROR_H_

#include <iosfwd>
#include <memory>
#include <string>

#include "components/sync/base/model_type.h"

namespace tracked_objects {
class Location;
}  // namespace tracked_objects

namespace syncer {

// Sync errors are used for debug purposes and handled internally and/or
// exposed through Chrome's "about:sync" internal page.
// This class is copy-friendly and thread-safe.
class SyncError {
 public:
  // Error types are used to distinguish general datatype errors (which result
  // in the datatype being disabled) from actionable sync errors (which might
  // have more complicated results).
  enum ErrorType {
    UNSET,                 // No error.
    UNRECOVERABLE_ERROR,   // An unrecoverable runtime error was encountered,
                           // and sync should be disabled and purged completely.
    DATATYPE_ERROR,        // A datatype error was encountered, and the datatype
                           // should be disabled and purged completely. Note
                           // that datatype errors may be reset, triggering a
                           // re-enable.
    PERSISTENCE_ERROR,     // A persistence error was detected, and the
                           // datataype should be associated after a sync
                           // update.
    CRYPTO_ERROR,          // A cryptographer error was detected, and the
                           // datatype should be associated after it is
                           // resolved.
    UNREADY_ERROR,         // A datatype is not ready to start yet, so should be
                           // neither purged nor enabled until it is ready.
    DATATYPE_POLICY_ERROR  // A datatype should be disabled and purged due to
                           // configuration constraints.
  };

  // Severity is used to indicate how an error should be logged and
  // represented to an end user.
  enum Severity {
    SYNC_ERROR_SEVERITY_ERROR,  // Severe unrecoverable error.
    SYNC_ERROR_SEVERITY_INFO    // Low-severity recoverable error or
                                // configuration policy issue.
  };

  // Default constructor refers to "no error", and IsSet() will return false.
  SyncError();

  // Create a new Sync error of type |error_type| triggered by |model_type|
  // from the specified location. IsSet() will return true afterward. Will
  // create and print an error specific message to LOG(ERROR).
  SyncError(const tracked_objects::Location& location,
            ErrorType error_type,
            const std::string& message,
            ModelType model_type);

  // Copy and assign via deep copy.
  SyncError(const SyncError& other);
  SyncError& operator=(const SyncError& other);

  ~SyncError();

  // Reset the current error to a new datatype error. May be called
  // irrespective of whether IsSet() is true. After this is called, IsSet()
  // will return true.
  // Will print the new error to LOG(ERROR).
  void Reset(const tracked_objects::Location& location,
             const std::string& message,
             ModelType type);

  // Whether this is a valid error or not.
  bool IsSet() const;

  // These must only be called if IsSet() is true.
  const tracked_objects::Location& location() const;
  const std::string& message() const;
  ModelType model_type() const;
  ErrorType error_type() const;

  // Error severity for logging and UI purposes.
  Severity GetSeverity() const;
  // Type specific message prefix for logging and UI purposes.
  std::string GetMessagePrefix() const;

  // Returns empty string is IsSet() is false.
  std::string ToString() const;

 private:
  // Print error information to log.
  void PrintLogError() const;

  // Make a copy of a SyncError. If other.IsSet() == false, this->IsSet() will
  // now return false.
  void Copy(const SyncError& other);

  // Initialize the local error data with the specified error data. After this
  // is called, IsSet() will return true.
  void Init(const tracked_objects::Location& location,
            const std::string& message,
            ModelType model_type,
            ErrorType error_type);

  // Reset the error to it's default (unset) values.
  void Clear();

  // unique_ptr is necessary because Location objects aren't assignable.
  std::unique_ptr<tracked_objects::Location> location_;
  std::string message_;
  ModelType model_type_;
  ErrorType error_type_;
};

// gmock printer helper.
void PrintTo(const SyncError& sync_error, std::ostream* os);

}  // namespace syncer

#endif  // COMPONENTS_SYNC_MODEL_SYNC_ERROR_H_