1 // Copyright 2013 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 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_
10 #include "base/basictypes.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/timer/timer.h"
13 #include "chrome/browser/sync_file_system/sync_callbacks.h"
14 #include "chrome/browser/sync_file_system/sync_service_state.h"
16 namespace sync_file_system
{
18 class SyncFileSystemService
;
20 // A base class to schedule a sync.
21 // Each subclass must implement StartSync().
22 // An instance of this class is supposed to be owned by SyncFileSystemService.
24 // Note that multiple SyncProcessRunner doesn't coordinate its sync schedule
26 class SyncProcessRunner
{
28 typedef base::Callback
<void(const SyncStatusCallback
&)> Task
;
29 SyncProcessRunner(const std::string
& name
,
30 SyncFileSystemService
* sync_service
);
31 virtual ~SyncProcessRunner();
33 // Subclass must implement this.
34 virtual void StartSync(const SyncStatusCallback
& callback
) = 0;
36 // Schedules a new sync.
38 void ScheduleIfNotRunning();
40 int64
pending_changes() const { return pending_changes_
; }
43 void OnChangesUpdated(int64 pending_changes
);
44 SyncFileSystemService
* sync_service() { return sync_service_
; }
46 // Returns the current service state. Default implementation returns
47 // sync_service()->GetSyncServiceState().
48 virtual SyncServiceState
GetServiceState();
51 void Finished(SyncStatusCode status
);
53 void ScheduleInternal(int64 delay
);
56 SyncFileSystemService
* sync_service_
;
57 base::OneShotTimer
<SyncProcessRunner
> timer_
;
58 base::Time last_scheduled_
;
61 int64 pending_changes_
;
63 base::WeakPtrFactory
<SyncProcessRunner
> factory_
;
65 DISALLOW_COPY_AND_ASSIGN(SyncProcessRunner
);
68 } // namespace sync_file_system
70 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_