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