blob: 9118627920d2b038537844bb6175d908f78e1bee (
plain)
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
|
// Copyright 2013 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 CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_
#define CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_
#include <string>
#include "base/basictypes.h"
#include "base/memory/weak_ptr.h"
#include "base/timer/timer.h"
#include "chrome/browser/sync_file_system/sync_callbacks.h"
#include "chrome/browser/sync_file_system/sync_service_state.h"
namespace sync_file_system {
class SyncFileSystemService;
// A base class to schedule a sync.
// Each subclass must implement StartSync().
// An instance of this class is supposed to be owned by SyncFileSystemService.
//
// Note that multiple SyncProcessRunner doesn't coordinate its sync schedule
// with each other.
class SyncProcessRunner {
public:
typedef base::Callback<void(const SyncStatusCallback&)> Task;
SyncProcessRunner(const std::string& name,
SyncFileSystemService* sync_service);
virtual ~SyncProcessRunner();
// Subclass must implement this.
virtual void StartSync(const SyncStatusCallback& callback) = 0;
// Schedules a new sync.
void Schedule();
void ScheduleIfNotRunning();
int64 pending_changes() const { return pending_changes_; }
protected:
void OnChangesUpdated(int64 pending_changes);
SyncFileSystemService* sync_service() { return sync_service_; }
// Returns the current service state. Default implementation returns
// sync_service()->GetSyncServiceState().
virtual SyncServiceState GetServiceState();
private:
void Finished(SyncStatusCode status);
void Run();
void ScheduleInternal(int64 delay);
std::string name_;
SyncFileSystemService* sync_service_;
base::OneShotTimer<SyncProcessRunner> timer_;
base::Time last_scheduled_;
int64 current_delay_;
int64 last_delay_;
int64 pending_changes_;
bool running_;
base::WeakPtrFactory<SyncProcessRunner> factory_;
DISALLOW_COPY_AND_ASSIGN(SyncProcessRunner);
};
} // namespace sync_file_system
#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_
|