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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 Client* client, | 68 Client* client, |
69 scoped_ptr<TimerHelper> timer_helper, | 69 scoped_ptr<TimerHelper> timer_helper, |
70 int max_parallel_task); | 70 int max_parallel_task); |
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 void ScheduleIfNotRunning(); | |
79 | 78 |
80 int64 pending_changes() const { return pending_changes_; } | 79 int64 pending_changes() const { return pending_changes_; } |
81 | 80 |
82 protected: | 81 protected: |
83 void OnChangesUpdated(int64 pending_changes); | 82 void OnChangesUpdated(int64 pending_changes); |
84 SyncFileSystemService* GetSyncService(); | 83 SyncFileSystemService* GetSyncService(); |
85 | 84 |
86 // Returns the current service state. Default implementation returns | 85 // Returns the current service state. Default implementation returns |
87 // sync_service()->GetSyncServiceState(). | 86 // sync_service()->GetSyncServiceState(). |
88 virtual SyncServiceState GetServiceState(); | 87 virtual SyncServiceState GetServiceState(); |
89 | 88 |
90 private: | 89 private: |
91 void Finished(const base::TimeTicks& start_time, SyncStatusCode status); | 90 void Finished(const base::TimeTicks& start_time, |
| 91 SyncStatusCode status); |
92 void Run(); | 92 void Run(); |
93 void ScheduleInternal(int64 delay); | 93 void ScheduleInternal(int64 delay); |
94 | 94 |
| 95 // Throttles new sync for |base_delay| milliseconds for an error case. |
| 96 // If new sync is already throttled, back off the duration. |
| 97 void ThrottleSync(int64 base_delay); |
| 98 |
| 99 // Clears old throttling setting that is already over. |
| 100 void ResetOldThrottling(); |
| 101 void ResetThrottling(); |
| 102 |
95 std::string name_; | 103 std::string name_; |
96 Client* client_; | 104 Client* client_; |
97 int max_parallel_task_; | 105 int max_parallel_task_; |
98 int running_tasks_; | 106 int running_tasks_; |
99 scoped_ptr<TimerHelper> timer_helper_; | 107 scoped_ptr<TimerHelper> timer_helper_; |
100 base::TimeTicks last_scheduled_; | 108 base::TimeTicks last_scheduled_; |
| 109 |
| 110 base::TimeTicks throttle_from_; |
| 111 base::TimeTicks throttle_until_; |
| 112 |
101 int64 current_delay_; | 113 int64 current_delay_; |
102 int64 last_delay_; | 114 int64 last_delay_; |
103 int64 pending_changes_; | 115 int64 pending_changes_; |
104 base::WeakPtrFactory<SyncProcessRunner> factory_; | 116 base::WeakPtrFactory<SyncProcessRunner> factory_; |
105 | 117 |
106 DISALLOW_COPY_AND_ASSIGN(SyncProcessRunner); | 118 DISALLOW_COPY_AND_ASSIGN(SyncProcessRunner); |
107 }; | 119 }; |
108 | 120 |
109 } // namespace sync_file_system | 121 } // namespace sync_file_system |
110 | 122 |
111 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_ | 123 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_ |
OLD | NEW |