File: remote_file_sync_service.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (187 lines) | stat: -rw-r--r-- 7,057 bytes parent folder | download | duplicates (4)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Copyright 2012 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_SYNC_FILE_SYSTEM_REMOTE_FILE_SYNC_SERVICE_H_
#define CHROME_BROWSER_SYNC_FILE_SYSTEM_REMOTE_FILE_SYNC_SERVICE_H_

#include <stdint.h>

#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>

#include "base/values.h"
#include "chrome/browser/sync_file_system/conflict_resolution_policy.h"
#include "chrome/browser/sync_file_system/sync_callbacks.h"
#include "chrome/browser/sync_file_system/sync_file_metadata.h"
#include "storage/browser/file_system/file_system_url.h"

class BrowserContextKeyedServiceFactory;
class GURL;

namespace content {
class BrowserContext;
}

namespace sync_file_system {

class FileStatusObserver;
class LocalChangeProcessor;
class RemoteChangeProcessor;
class TaskLogger;

enum RemoteServiceState {
  // Remote service is up and running, or has not seen any errors yet.
  // The consumer of this service can make new requests while the
  // service is in this state.
  REMOTE_SERVICE_OK = 0,

  // Remote service is temporarily unavailable due to network,
  // authentication or some other temporary failure.
  // This state may be automatically resolved when the underlying
  // network condition or service condition changes.
  // The consumer of this service can still make new requests but
  // they may fail (with recoverable error code).
  REMOTE_SERVICE_TEMPORARY_UNAVAILABLE,

  // Remote service is temporarily unavailable due to authentication failure.
  // This state may be automatically resolved when the authentication token
  // has been refreshed internally (e.g. when the user signed in etc).
  // The consumer of this service can still make new requests but
  // they may fail (with recoverable error code).
  REMOTE_SERVICE_AUTHENTICATION_REQUIRED,

  // Remote service is temporarily unavailable due to lack of API permissions.
  // This state may be automatically resolved when the API gets right
  // permissions to access with.
  // The consumer of this service can still make new requests but
  // they may fail (with recoverable error code).
  REMOTE_SERVICE_ACCESS_FORBIDDEN,

  // Remote service is disabled by configuration change or due to some
  // unrecoverable errors, e.g. local database corruption.
  // Any new requests will immediately fail when the service is in
  // this state.
  REMOTE_SERVICE_DISABLED,

  REMOTE_SERVICE_STATE_MAX,
};

// This class represents a backing service of the sync filesystem.
// This also maintains conflict information, i.e. a list of conflicting files
// (at least in the current design).
// Owned by SyncFileSystemService.
class RemoteFileSyncService {
 public:
  class Observer {
   public:
    Observer() = default;

    Observer(const Observer&) = delete;
    Observer& operator=(const Observer&) = delete;

    virtual ~Observer() = default;

    // This is called when RemoteFileSyncService updates its internal queue
    // of pending remote changes.
    // |pending_changes_hint| indicates the pending queue length to help sync
    // scheduling but the value may not be accurately reflect the real-time
    // value.
    virtual void OnRemoteChangeQueueUpdated(int64_t pending_changes_hint) = 0;

    // This is called when RemoteFileSyncService updates its state.
    virtual void OnRemoteServiceStateUpdated(
        RemoteServiceState state,
        const std::string& description) {}
  };

  struct Version {
    std::string id;
    SyncFileMetadata metadata;
  };

  enum UninstallFlag {
    UNINSTALL_AND_PURGE_REMOTE,
    UNINSTALL_AND_KEEP_REMOTE,
  };

  // Creates an initialized RemoteFileSyncService for backend |version|
  // for |context|.
  static std::unique_ptr<RemoteFileSyncService> CreateForBrowserContext(
      content::BrowserContext* context,
      TaskLogger* task_logger);

  // Returns BrowserContextKeyedServiceFactory's an instance of
  // RemoteFileSyncService for backend |version| depends on.
  static void AppendDependsOnFactories(
      std::set<BrowserContextKeyedServiceFactory*>* factories);

  RemoteFileSyncService() = default;

  RemoteFileSyncService(const RemoteFileSyncService&) = delete;
  RemoteFileSyncService& operator=(const RemoteFileSyncService&) = delete;

  virtual ~RemoteFileSyncService() = default;

  // Adds and removes observers.
  virtual void AddServiceObserver(Observer* observer) = 0;
  virtual void AddFileStatusObserver(FileStatusObserver* observer) = 0;

  // Registers |origin| to track remote side changes for the |origin|.
  // Upon completion, invokes |callback|.
  // The caller may call this method again when the remote service state
  // migrates to REMOTE_SERVICE_OK state if the error code returned via
  // |callback| was retriable ones.
  virtual void RegisterOrigin(const GURL& origin,
                              SyncStatusCallback callback) = 0;

  // Re-enables |origin| that was previously disabled. If |origin| is not a
  // SyncFS app, then the origin is effectively ignored.
  virtual void EnableOrigin(const GURL& origin,
                            SyncStatusCallback callback) = 0;

  virtual void DisableOrigin(const GURL& origin,
                             SyncStatusCallback callback) = 0;

  // Uninstalls the |origin| by deleting its remote data copy and then removing
  // the origin from the metadata store.
  virtual void UninstallOrigin(const GURL& origin,
                               UninstallFlag flag,
                               SyncStatusCallback callback) = 0;

  // Called by the sync engine to process one remote change.
  // After a change is processed |callback| will be called (to return
  // the control to the sync engine).
  // It is invalid to call this before calling SetRemoteChangeProcessor().
  virtual void ProcessRemoteChange(SyncFileCallback callback) = 0;

  // Sets a remote change processor.  This must be called before any
  // ProcessRemoteChange().
  virtual void SetRemoteChangeProcessor(
      RemoteChangeProcessor* processor) = 0;

  // Returns a LocalChangeProcessor that applies a local change to the remote
  // storage backed by this service.
  virtual LocalChangeProcessor* GetLocalChangeProcessor() = 0;

  // Returns the current remote service state (should equal to the value
  // returned by the last OnRemoteServiceStateUpdated notification.
  virtual RemoteServiceState GetCurrentState() const = 0;

  // Enables or disables the background sync.
  // Setting this to false should disable the synchronization (and make
  // the service state to REMOTE_SERVICE_DISABLED), while setting this to
  // true does not necessarily mean the service is actually turned on
  // (for example if Chrome is offline the service state will become
  // REMOTE_SERVICE_TEMPORARY_UNAVAILABLE).
  virtual void SetSyncEnabled(bool enabled) = 0;

  virtual void PromoteDemotedChanges(base::OnceClosure callback) = 0;
};

}  // namespace sync_file_system

#endif  // CHROME_BROWSER_SYNC_FILE_SYSTEM_REMOTE_FILE_SYNC_SERVICE_H_