Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / sync_file_system / drive_backend / fake_sync_worker.cc
blob4dbcce84a3090ebff652ed1abf2f31a2bff4e1ca
1 // Copyright 2014 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.
5 #include "chrome/browser/sync_file_system/drive_backend/fake_sync_worker.h"
7 #include "base/values.h"
8 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.h"
9 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_context.h"
10 #include "chrome/browser/sync_file_system/sync_status_code.h"
12 namespace sync_file_system {
13 namespace drive_backend {
15 FakeSyncWorker::FakeSyncWorker()
16 : sync_enabled_(true) {
17 sequence_checker_.DetachFromSequence();
20 FakeSyncWorker::~FakeSyncWorker() {
21 observers_.Clear();
24 void FakeSyncWorker::Initialize(
25 scoped_ptr<SyncEngineContext> sync_engine_context) {
26 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
28 sync_engine_context_ = sync_engine_context.Pass();
29 status_map_.clear();
30 // TODO(peria): Set |status_map_| as a fake metadata database.
33 void FakeSyncWorker::RegisterOrigin(const GURL& origin,
34 const SyncStatusCallback& callback) {
35 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
36 // TODO(peria): Check how it should act on installing installed app?
37 status_map_[origin] = REGISTERED;
38 callback.Run(SYNC_STATUS_OK);
41 void FakeSyncWorker::EnableOrigin(const GURL& origin,
42 const SyncStatusCallback& callback) {
43 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
44 // TODO(peria): Check how it should act on enabling non-installed app?
45 status_map_[origin] = ENABLED;
46 callback.Run(SYNC_STATUS_OK);
49 void FakeSyncWorker::DisableOrigin(const GURL& origin,
50 const SyncStatusCallback& callback) {
51 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
52 // TODO(peria): Check how it should act on disabling non-installed app?
53 status_map_[origin] = DISABLED;
54 callback.Run(SYNC_STATUS_OK);
57 void FakeSyncWorker::UninstallOrigin(const GURL& origin,
58 RemoteFileSyncService::UninstallFlag flag,
59 const SyncStatusCallback& callback) {
60 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
61 // TODO(peria): Check how it should act on uninstalling non-installed app?
62 status_map_[origin] = UNINSTALLED;
63 callback.Run(SYNC_STATUS_OK);
66 void FakeSyncWorker::ProcessRemoteChange(
67 const SyncFileCallback& callback) {
68 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
69 callback.Run(SYNC_STATUS_OK, storage::FileSystemURL());
72 void FakeSyncWorker::SetRemoteChangeProcessor(
73 RemoteChangeProcessorOnWorker* remote_change_processor_on_worker) {
74 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
77 RemoteServiceState FakeSyncWorker::GetCurrentState() const {
78 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
79 return REMOTE_SERVICE_OK;
82 void FakeSyncWorker::GetOriginStatusMap(
83 const RemoteFileSyncService::StatusMapCallback& callback) {
84 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
86 scoped_ptr<RemoteFileSyncService::OriginStatusMap>
87 status_map(new RemoteFileSyncService::OriginStatusMap);
88 for (StatusMap::const_iterator itr = status_map_.begin();
89 itr != status_map_.end(); ++itr) {
90 switch (itr->second) {
91 case REGISTERED:
92 (*status_map)[itr->first] = "Registered";
93 break;
94 case ENABLED:
95 (*status_map)[itr->first] = "Enabled";
96 break;
97 case DISABLED:
98 (*status_map)[itr->first] = "Disabled";
99 break;
100 case UNINSTALLED:
101 (*status_map)[itr->first] = "Uninstalled";
102 break;
103 default:
104 (*status_map)[itr->first] = "Unknown";
105 break;
108 callback.Run(status_map.Pass());
111 scoped_ptr<base::ListValue> FakeSyncWorker::DumpFiles(const GURL& origin) {
112 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
113 return nullptr;
116 scoped_ptr<base::ListValue> FakeSyncWorker::DumpDatabase() {
117 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
118 return nullptr;
121 void FakeSyncWorker::SetSyncEnabled(bool enabled) {
122 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
123 sync_enabled_ = enabled;
125 if (enabled)
126 UpdateServiceState(REMOTE_SERVICE_OK, "Set FakeSyncWorker enabled.");
127 else
128 UpdateServiceState(REMOTE_SERVICE_DISABLED, "Disabled FakeSyncWorker.");
131 void FakeSyncWorker::PromoteDemotedChanges(const base::Closure& callback) {
132 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
133 FOR_EACH_OBSERVER(
134 Observer,
135 observers_,
136 OnPendingFileListUpdated(10));
137 callback.Run();
140 void FakeSyncWorker::ApplyLocalChange(const FileChange& local_change,
141 const base::FilePath& local_path,
142 const SyncFileMetadata& local_metadata,
143 const storage::FileSystemURL& url,
144 const SyncStatusCallback& callback) {
145 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
146 callback.Run(SYNC_STATUS_OK);
149 void FakeSyncWorker::ActivateService(RemoteServiceState service_state,
150 const std::string& description) {
151 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
152 UpdateServiceState(service_state, description);
155 void FakeSyncWorker::DeactivateService(const std::string& description) {
156 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
157 UpdateServiceState(REMOTE_SERVICE_TEMPORARY_UNAVAILABLE, description);
160 void FakeSyncWorker::DetachFromSequence() {
161 sequence_checker_.DetachFromSequence();
164 void FakeSyncWorker::AddObserver(Observer* observer) {
165 // This method is called on UI thread.
166 observers_.AddObserver(observer);
169 void FakeSyncWorker::UpdateServiceState(RemoteServiceState state,
170 const std::string& description) {
171 DCHECK(sequence_checker_.CalledOnValidSequencedThread());
173 FOR_EACH_OBSERVER(
174 Observer, observers_,
175 UpdateServiceState(state, description));
178 } // namespace drive_backend
179 } // namespace sync_file_system