| 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 <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
| 8 #include <string> | 11 #include <string> |
| 9 | 12 |
| 10 #include "base/basictypes.h" | 13 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 12 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
| 13 #include "chrome/browser/sync_file_system/sync_callbacks.h" | 16 #include "chrome/browser/sync_file_system/sync_callbacks.h" |
| 14 #include "chrome/browser/sync_file_system/sync_service_state.h" | 17 #include "chrome/browser/sync_file_system/sync_service_state.h" |
| 15 | 18 |
| 16 namespace sync_file_system { | 19 namespace sync_file_system { |
| 17 | 20 |
| 18 class SyncFileSystemService; | 21 class SyncFileSystemService; |
| 19 | 22 |
| 20 // A base class to schedule a sync. | 23 // A base class to schedule a sync. |
| 21 // Each subclass must implement StartSync(). | 24 // Each subclass must implement StartSync(). |
| 22 // An instance of this class is supposed to be owned by SyncFileSystemService. | 25 // An instance of this class is supposed to be owned by SyncFileSystemService. |
| 23 // | 26 // |
| 24 // Note that multiple SyncProcessRunner doesn't coordinate its sync schedule | 27 // Note that multiple SyncProcessRunner doesn't coordinate its sync schedule |
| 25 // with each other. | 28 // with each other. |
| 26 class SyncProcessRunner { | 29 class SyncProcessRunner { |
| 27 public: | 30 public: |
| 28 // Default delay when more changes are available. | 31 // Default delay when more changes are available. |
| 29 static const int64 kSyncDelayInMilliseconds; | 32 static const int64_t kSyncDelayInMilliseconds; |
| 30 | 33 |
| 31 // Default delay when the previous change has had an error (but remote service | 34 // Default delay when the previous change has had an error (but remote service |
| 32 // is running). | 35 // is running). |
| 33 static const int64 kSyncDelayWithSyncError; | 36 static const int64_t kSyncDelayWithSyncError; |
| 34 | 37 |
| 35 // Default delay when there're more than 10 pending changes. | 38 // Default delay when there're more than 10 pending changes. |
| 36 static const int64 kSyncDelayFastInMilliseconds; | 39 static const int64_t kSyncDelayFastInMilliseconds; |
| 37 static const int kPendingChangeThresholdForFastSync; | 40 static const int kPendingChangeThresholdForFastSync; |
| 38 | 41 |
| 39 // Default delay when remote service is temporarily unavailable. | 42 // Default delay when remote service is temporarily unavailable. |
| 40 // The delay backs off exponentially from initial value on repeated failure. | 43 // The delay backs off exponentially from initial value on repeated failure. |
| 41 static const int64 kSyncDelaySlowInMilliseconds; | 44 static const int64_t kSyncDelaySlowInMilliseconds; |
| 42 | 45 |
| 43 // Default delay when there're no changes. | 46 // Default delay when there're no changes. |
| 44 static const int64 kSyncDelayMaxInMilliseconds; | 47 static const int64_t kSyncDelayMaxInMilliseconds; |
| 45 | 48 |
| 46 class Client { | 49 class Client { |
| 47 public: | 50 public: |
| 48 virtual ~Client() {} | 51 virtual ~Client() {} |
| 49 virtual void OnSyncIdle() {} | 52 virtual void OnSyncIdle() {} |
| 50 virtual SyncServiceState GetSyncServiceState() = 0; | 53 virtual SyncServiceState GetSyncServiceState() = 0; |
| 51 virtual SyncFileSystemService* GetSyncService() = 0; | 54 virtual SyncFileSystemService* GetSyncService() = 0; |
| 52 }; | 55 }; |
| 53 | 56 |
| 54 class TimerHelper { | 57 class TimerHelper { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 69 scoped_ptr<TimerHelper> timer_helper, | 72 scoped_ptr<TimerHelper> timer_helper, |
| 70 size_t max_parallel_task); | 73 size_t max_parallel_task); |
| 71 virtual ~SyncProcessRunner(); | 74 virtual ~SyncProcessRunner(); |
| 72 | 75 |
| 73 // Subclass must implement this. | 76 // Subclass must implement this. |
| 74 virtual void StartSync(const SyncStatusCallback& callback) = 0; | 77 virtual void StartSync(const SyncStatusCallback& callback) = 0; |
| 75 | 78 |
| 76 // Schedules a new sync. | 79 // Schedules a new sync. |
| 77 void Schedule(); | 80 void Schedule(); |
| 78 | 81 |
| 79 int64 pending_changes() const { return pending_changes_; } | 82 int64_t pending_changes() const { return pending_changes_; } |
| 80 | 83 |
| 81 // Returns the current service state. Default implementation returns | 84 // Returns the current service state. Default implementation returns |
| 82 // sync_service()->GetSyncServiceState(). | 85 // sync_service()->GetSyncServiceState(). |
| 83 virtual SyncServiceState GetServiceState(); | 86 virtual SyncServiceState GetServiceState(); |
| 84 | 87 |
| 85 protected: | 88 protected: |
| 86 void OnChangesUpdated(int64 pending_changes); | 89 void OnChangesUpdated(int64_t pending_changes); |
| 87 SyncFileSystemService* GetSyncService(); | 90 SyncFileSystemService* GetSyncService(); |
| 88 | 91 |
| 89 private: | 92 private: |
| 90 void Finished(const base::TimeTicks& start_time, SyncStatusCode status); | 93 void Finished(const base::TimeTicks& start_time, SyncStatusCode status); |
| 91 void Run(); | 94 void Run(); |
| 92 void ScheduleInternal(int64 delay); | 95 void ScheduleInternal(int64_t delay); |
| 93 | 96 |
| 94 // Throttles new sync for |base_delay| milliseconds for an error case. | 97 // Throttles new sync for |base_delay| milliseconds for an error case. |
| 95 // If new sync is already throttled, back off the duration. | 98 // If new sync is already throttled, back off the duration. |
| 96 void ThrottleSync(int64 base_delay); | 99 void ThrottleSync(int64_t base_delay); |
| 97 | 100 |
| 98 // Clears old throttling setting that is already over. | 101 // Clears old throttling setting that is already over. |
| 99 void ResetOldThrottling(); | 102 void ResetOldThrottling(); |
| 100 void ResetThrottling(); | 103 void ResetThrottling(); |
| 101 | 104 |
| 102 void CheckIfIdle(); | 105 void CheckIfIdle(); |
| 103 | 106 |
| 104 std::string name_; | 107 std::string name_; |
| 105 Client* client_; | 108 Client* client_; |
| 106 size_t max_parallel_task_; | 109 size_t max_parallel_task_; |
| 107 size_t running_tasks_; | 110 size_t running_tasks_; |
| 108 scoped_ptr<TimerHelper> timer_helper_; | 111 scoped_ptr<TimerHelper> timer_helper_; |
| 109 base::TimeTicks last_run_; | 112 base::TimeTicks last_run_; |
| 110 base::TimeTicks last_scheduled_; | 113 base::TimeTicks last_scheduled_; |
| 111 SyncServiceState service_state_; | 114 SyncServiceState service_state_; |
| 112 | 115 |
| 113 base::TimeTicks throttle_from_; | 116 base::TimeTicks throttle_from_; |
| 114 base::TimeTicks throttle_until_; | 117 base::TimeTicks throttle_until_; |
| 115 | 118 |
| 116 int64 pending_changes_; | 119 int64_t pending_changes_; |
| 117 base::WeakPtrFactory<SyncProcessRunner> factory_; | 120 base::WeakPtrFactory<SyncProcessRunner> factory_; |
| 118 | 121 |
| 119 DISALLOW_COPY_AND_ASSIGN(SyncProcessRunner); | 122 DISALLOW_COPY_AND_ASSIGN(SyncProcessRunner); |
| 120 }; | 123 }; |
| 121 | 124 |
| 122 } // namespace sync_file_system | 125 } // namespace sync_file_system |
| 123 | 126 |
| 124 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_ | 127 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_SYNC_PROCESS_RUNNER_H_ |
| OLD | NEW |