OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_ |
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_ | 6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 virtual ~SyncProcessRunner(); | 71 virtual ~SyncProcessRunner(); |
72 | 72 |
73 // Subclass must implement this. | 73 // Subclass must implement this. |
74 virtual void StartSync(const SyncStatusCallback& callback) = 0; | 74 virtual void StartSync(const SyncStatusCallback& callback) = 0; |
75 | 75 |
76 // Schedules a new sync. | 76 // Schedules a new sync. |
77 void Schedule(); | 77 void Schedule(); |
78 | 78 |
79 int64 pending_changes() const { return pending_changes_; } | 79 int64 pending_changes() const { return pending_changes_; } |
80 | 80 |
| 81 // Returns the current service state. Default implementation returns |
| 82 // sync_service()->GetSyncServiceState(). |
| 83 virtual SyncServiceState GetServiceState(); |
| 84 |
81 protected: | 85 protected: |
82 void OnChangesUpdated(int64 pending_changes); | 86 void OnChangesUpdated(int64 pending_changes); |
83 SyncFileSystemService* GetSyncService(); | 87 SyncFileSystemService* GetSyncService(); |
84 | 88 |
85 // Returns the current service state. Default implementation returns | |
86 // sync_service()->GetSyncServiceState(). | |
87 virtual SyncServiceState GetServiceState(); | |
88 | |
89 private: | 89 private: |
90 void Finished(const base::TimeTicks& start_time, SyncStatusCode status); | 90 void Finished(const base::TimeTicks& start_time, SyncStatusCode status); |
91 void Run(); | 91 void Run(); |
92 void ScheduleInternal(int64 delay); | 92 void ScheduleInternal(int64 delay); |
93 | 93 |
94 // Throttles new sync for |base_delay| milliseconds for an error case. | 94 // Throttles new sync for |base_delay| milliseconds for an error case. |
95 // If new sync is already throttled, back off the duration. | 95 // If new sync is already throttled, back off the duration. |
96 void ThrottleSync(int64 base_delay); | 96 void ThrottleSync(int64 base_delay); |
97 | 97 |
98 // Clears old throttling setting that is already over. | 98 // Clears old throttling setting that is already over. |
99 void ResetOldThrottling(); | 99 void ResetOldThrottling(); |
100 void ResetThrottling(); | 100 void ResetThrottling(); |
101 | 101 |
| 102 void CheckIfIdle(); |
| 103 |
102 std::string name_; | 104 std::string name_; |
103 Client* client_; | 105 Client* client_; |
104 size_t max_parallel_task_; | 106 size_t max_parallel_task_; |
105 size_t running_tasks_; | 107 size_t running_tasks_; |
106 scoped_ptr<TimerHelper> timer_helper_; | 108 scoped_ptr<TimerHelper> timer_helper_; |
107 base::TimeTicks last_run_; | 109 base::TimeTicks last_run_; |
108 base::TimeTicks last_scheduled_; | 110 base::TimeTicks last_scheduled_; |
109 SyncServiceState service_state_; | 111 SyncServiceState service_state_; |
110 | 112 |
111 base::TimeTicks throttle_from_; | 113 base::TimeTicks throttle_from_; |
112 base::TimeTicks throttle_until_; | 114 base::TimeTicks throttle_until_; |
113 | 115 |
114 int64 pending_changes_; | 116 int64 pending_changes_; |
115 base::WeakPtrFactory<SyncProcessRunner> factory_; | 117 base::WeakPtrFactory<SyncProcessRunner> factory_; |
116 | 118 |
117 DISALLOW_COPY_AND_ASSIGN(SyncProcessRunner); | 119 DISALLOW_COPY_AND_ASSIGN(SyncProcessRunner); |
118 }; | 120 }; |
119 | 121 |
120 } // namespace sync_file_system | 122 } // namespace sync_file_system |
121 | 123 |
122 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_ | 124 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_ |
OLD | NEW |