Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / sync_file_system / sync_process_runner.h
bloba656db36b4f30137da599a4bde1e285904223978
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
23 // with each other.
24 class SyncProcessRunner {
25 public:
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.
35 void Schedule();
36 void ScheduleIfNotRunning();
38 int64 pending_changes() const { return pending_changes_; }
40 protected:
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();
48 private:
49 void Finished(SyncStatusCode status);
50 void Run();
51 void ScheduleInternal(int64 delay);
53 std::string name_;
54 SyncFileSystemService* sync_service_;
55 base::OneShotTimer<SyncProcessRunner> timer_;
56 base::Time last_scheduled_;
57 int64 current_delay_;
58 int64 last_delay_;
59 int64 pending_changes_;
60 bool running_;
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_