File: fake_sync_worker.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; 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 (138 lines) | stat: -rw-r--r-- 4,971 bytes parent folder | download | duplicates (5)
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
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/sync_file_system/drive_backend/fake_sync_worker.h"

#include <utility>

#include "base/values.h"
#include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.h"
#include "chrome/browser/sync_file_system/drive_backend/sync_engine_context.h"
#include "chrome/browser/sync_file_system/sync_status_code.h"

namespace sync_file_system {
namespace drive_backend {

FakeSyncWorker::FakeSyncWorker()
    : sync_enabled_(true) {
  DETACH_FROM_SEQUENCE(sequence_checker_);
}

FakeSyncWorker::~FakeSyncWorker() {
  observers_.Clear();
}

void FakeSyncWorker::Initialize(
    std::unique_ptr<SyncEngineContext> sync_engine_context) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

  sync_engine_context_ = std::move(sync_engine_context);
  status_map_.clear();
  // TODO(peria): Set |status_map_| as a fake metadata database.
}

void FakeSyncWorker::RegisterOrigin(const GURL& origin,
                                    SyncStatusCallback callback) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  // TODO(peria): Check how it should act on installing installed app?
  status_map_[origin] = REGISTERED;
  std::move(callback).Run(SYNC_STATUS_OK);
}

void FakeSyncWorker::EnableOrigin(const GURL& origin,
                                  SyncStatusCallback callback) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  // TODO(peria): Check how it should act on enabling non-installed app?
  status_map_[origin] = ENABLED;
  std::move(callback).Run(SYNC_STATUS_OK);
}

void FakeSyncWorker::DisableOrigin(const GURL& origin,
                                   SyncStatusCallback callback) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  // TODO(peria): Check how it should act on disabling non-installed app?
  status_map_[origin] = DISABLED;
  std::move(callback).Run(SYNC_STATUS_OK);
}

void FakeSyncWorker::UninstallOrigin(const GURL& origin,
                                     RemoteFileSyncService::UninstallFlag flag,
                                     SyncStatusCallback callback) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  // TODO(peria): Check how it should act on uninstalling non-installed app?
  status_map_[origin] = UNINSTALLED;
  std::move(callback).Run(SYNC_STATUS_OK);
}

void FakeSyncWorker::ProcessRemoteChange(SyncFileCallback callback) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  std::move(callback).Run(SYNC_STATUS_OK, storage::FileSystemURL());
}

void FakeSyncWorker::SetRemoteChangeProcessor(
    RemoteChangeProcessorOnWorker* remote_change_processor_on_worker) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}

RemoteServiceState FakeSyncWorker::GetCurrentState() const {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  return REMOTE_SERVICE_OK;
}

void FakeSyncWorker::SetSyncEnabled(bool enabled) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  sync_enabled_ = enabled;

  if (enabled)
    UpdateServiceState(REMOTE_SERVICE_OK, "Set FakeSyncWorker enabled.");
  else
    UpdateServiceState(REMOTE_SERVICE_DISABLED, "Disabled FakeSyncWorker.");
}

void FakeSyncWorker::PromoteDemotedChanges(base::OnceClosure callback) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  for (auto& observer : observers_)
    observer.OnPendingFileListUpdated(10);
  std::move(callback).Run();
}

void FakeSyncWorker::ApplyLocalChange(const FileChange& local_change,
                                      const base::FilePath& local_path,
                                      const SyncFileMetadata& local_metadata,
                                      const storage::FileSystemURL& url,
                                      SyncStatusCallback callback) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  std::move(callback).Run(SYNC_STATUS_OK);
}

void FakeSyncWorker::ActivateService(RemoteServiceState service_state,
                                     const std::string& description) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  UpdateServiceState(service_state, description);
}

void FakeSyncWorker::DeactivateService(const std::string& description) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  UpdateServiceState(REMOTE_SERVICE_TEMPORARY_UNAVAILABLE, description);
}

void FakeSyncWorker::DetachFromSequence() {
  DETACH_FROM_SEQUENCE(sequence_checker_);
}

void FakeSyncWorker::AddObserver(Observer* observer) {
  // This method is called on UI thread.
  observers_.AddObserver(observer);
}

void FakeSyncWorker::UpdateServiceState(RemoteServiceState state,
                                        const std::string& description) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

  for (auto& observer : observers_)
    observer.UpdateServiceState(state, description);
}

}  // namespace drive_backend
}  // namespace sync_file_system