Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / sync_file_system / sync_process_runner.h
blob9118627920d2b038537844bb6175d908f78e1bee
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 <string>
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
25 // with each other.
26 class SyncProcessRunner {
27 public:
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.
37 void Schedule();
38 void ScheduleIfNotRunning();
40 int64 pending_changes() const { return pending_changes_; }
42 protected:
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();
50 private:
51 void Finished(SyncStatusCode status);
52 void Run();
53 void ScheduleInternal(int64 delay);
55 std::string name_;
56 SyncFileSystemService* sync_service_;
57 base::OneShotTimer<SyncProcessRunner> timer_;
58 base::Time last_scheduled_;
59 int64 current_delay_;
60 int64 last_delay_;
61 int64 pending_changes_;
62 bool running_;
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_