| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // A class to run the syncer on a thread. | 5 // A class to run the syncer on a thread. |
| 6 #ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD2_H_ | 6 #ifndef CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD2_H_ |
| 7 #define CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD2_H_ | 7 #define CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD2_H_ |
| 8 #pragma once | 8 #pragma once |
| 9 | 9 |
| 10 #include "base/linked_ptr.h" | 10 #include "base/linked_ptr.h" |
| 11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/task.h" | 13 #include "base/task.h" |
| 14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "base/timer.h" | 16 #include "base/timer.h" |
| 17 #include "chrome/browser/sync/engine/nudge_source.h" | 17 #include "chrome/browser/sync/engine/nudge_source.h" |
| 18 #include "chrome/browser/sync/engine/polling_constants.h" | 18 #include "chrome/browser/sync/engine/polling_constants.h" |
| 19 #include "chrome/browser/sync/engine/syncer.h" |
| 19 #include "chrome/browser/sync/sessions/sync_session.h" | 20 #include "chrome/browser/sync/sessions/sync_session.h" |
| 20 #include "chrome/browser/sync/sessions/sync_session_context.h" | 21 #include "chrome/browser/sync/sessions/sync_session_context.h" |
| 21 | 22 |
| 22 namespace browser_sync { | 23 namespace browser_sync { |
| 23 | 24 |
| 24 struct ServerConnectionEvent; | 25 struct ServerConnectionEvent; |
| 25 class Syncer; | |
| 26 | 26 |
| 27 namespace s3 { | 27 namespace s3 { |
| 28 | 28 |
| 29 class SyncerThread : public sessions::SyncSession::Delegate { | 29 class SyncerThread : public sessions::SyncSession::Delegate { |
| 30 public: | 30 public: |
| 31 enum Mode { | 31 enum Mode { |
| 32 // In this mode, the thread only performs configuration tasks. This is | 32 // In this mode, the thread only performs configuration tasks. This is |
| 33 // designed to make the case where we want to download updates for a | 33 // designed to make the case where we want to download updates for a |
| 34 // specific type only, and not continue syncing until we are moved into | 34 // specific type only, and not continue syncing until we are moved into |
| 35 // normal mode. | 35 // normal mode. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 58 void Stop(); | 58 void Stop(); |
| 59 | 59 |
| 60 // The meat and potatoes. | 60 // The meat and potatoes. |
| 61 void ScheduleNudge(const base::TimeDelta& delay, NudgeSource source, | 61 void ScheduleNudge(const base::TimeDelta& delay, NudgeSource source, |
| 62 const syncable::ModelTypeBitSet& types); | 62 const syncable::ModelTypeBitSet& types); |
| 63 void ScheduleNudgeWithPayloads( | 63 void ScheduleNudgeWithPayloads( |
| 64 const base::TimeDelta& delay, NudgeSource source, | 64 const base::TimeDelta& delay, NudgeSource source, |
| 65 const sessions::TypePayloadMap& types_with_payloads); | 65 const sessions::TypePayloadMap& types_with_payloads); |
| 66 void ScheduleConfig(const base::TimeDelta& delay, | 66 void ScheduleConfig(const base::TimeDelta& delay, |
| 67 const syncable::ModelTypeBitSet& types); | 67 const syncable::ModelTypeBitSet& types); |
| 68 void ScheduleClearUserData(); |
| 68 | 69 |
| 69 // Change status of notifications in the SyncSessionContext. | 70 // Change status of notifications in the SyncSessionContext. |
| 70 void set_notifications_enabled(bool notifications_enabled); | 71 void set_notifications_enabled(bool notifications_enabled); |
| 71 | 72 |
| 72 // DDOS avoidance function. Calculates how long we should wait before trying | 73 // DDOS avoidance function. Calculates how long we should wait before trying |
| 73 // again after a failed sync attempt, where the last delay was |base_delay|. | 74 // again after a failed sync attempt, where the last delay was |base_delay|. |
| 74 // TODO(tim): Look at URLRequestThrottlerEntryInterface. | 75 // TODO(tim): Look at URLRequestThrottlerEntryInterface. |
| 75 static base::TimeDelta GetRecommendedDelay(const base::TimeDelta& base_delay); | 76 static base::TimeDelta GetRecommendedDelay(const base::TimeDelta& base_delay); |
| 76 | 77 |
| 77 // SyncSession::Delegate implementation. | 78 // SyncSession::Delegate implementation. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 90 struct WaitInterval; | 91 struct WaitInterval; |
| 91 | 92 |
| 92 // An enum used to describe jobs for scheduling purposes. | 93 // An enum used to describe jobs for scheduling purposes. |
| 93 enum SyncSessionJobPurpose { | 94 enum SyncSessionJobPurpose { |
| 94 // Our poll timer schedules POLL jobs periodically based on a server | 95 // Our poll timer schedules POLL jobs periodically based on a server |
| 95 // assigned poll interval. | 96 // assigned poll interval. |
| 96 POLL, | 97 POLL, |
| 97 // A nudge task can come from a variety of components needing to force | 98 // A nudge task can come from a variety of components needing to force |
| 98 // a sync. The source is inferable from |session.source()|. | 99 // a sync. The source is inferable from |session.source()|. |
| 99 NUDGE, | 100 NUDGE, |
| 101 // The user invoked a function in the UI to clear their entire account |
| 102 // and stop syncing (globally). |
| 103 CLEAR_USER_DATA, |
| 100 // Typically used for fetching updates for a subset of the enabled types | 104 // Typically used for fetching updates for a subset of the enabled types |
| 101 // during initial sync or reconfiguration. We don't run all steps of | 105 // during initial sync or reconfiguration. We don't run all steps of |
| 102 // the sync cycle for these (e.g. CleanupDisabledTypes is skipped). | 106 // the sync cycle for these (e.g. CleanupDisabledTypes is skipped). |
| 103 CONFIGURATION, | 107 CONFIGURATION, |
| 104 }; | 108 }; |
| 105 | 109 |
| 106 // Internal state for every sync task that is scheduled. | 110 // Internal state for every sync task that is scheduled. |
| 107 struct SyncSessionJob; | 111 struct SyncSessionJob; |
| 108 | 112 |
| 109 // A component used to get time delays associated with exponential backoff. | 113 // A component used to get time delays associated with exponential backoff. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 150 |
| 147 // 'Impl' here refers to real implementation of public functions, running on | 151 // 'Impl' here refers to real implementation of public functions, running on |
| 148 // |thread_|. | 152 // |thread_|. |
| 149 void StartImpl(Mode mode); | 153 void StartImpl(Mode mode); |
| 150 void ScheduleNudgeImpl(const base::TimeDelta& delay, | 154 void ScheduleNudgeImpl(const base::TimeDelta& delay, |
| 151 NudgeSource source, | 155 NudgeSource source, |
| 152 const sessions::TypePayloadMap& types_with_payloads); | 156 const sessions::TypePayloadMap& types_with_payloads); |
| 153 void ScheduleConfigImpl(const base::TimeDelta& delay, | 157 void ScheduleConfigImpl(const base::TimeDelta& delay, |
| 154 const ModelSafeRoutingInfo& routing_info, | 158 const ModelSafeRoutingInfo& routing_info, |
| 155 const std::vector<ModelSafeWorker*>& workers); | 159 const std::vector<ModelSafeWorker*>& workers); |
| 160 void ScheduleClearUserDataImpl(); |
| 156 | 161 |
| 157 // Returns true if the client is currently in exponential backoff. | 162 // Returns true if the client is currently in exponential backoff. |
| 158 bool IsBackingOff() const; | 163 bool IsBackingOff() const; |
| 159 | 164 |
| 160 // Helper to signal all listeners registered with |session_context_|. | 165 // Helper to signal all listeners registered with |session_context_|. |
| 161 void Notify(SyncEngineEvent::EventCause cause); | 166 void Notify(SyncEngineEvent::EventCause cause); |
| 162 | 167 |
| 163 // ServerConnectionEventListener implementation. | 168 // ServerConnectionEventListener implementation. |
| 164 // TODO(tim): schedule a nudge when valid connection detected? in 1 minute? | 169 // TODO(tim): schedule a nudge when valid connection detected? in 1 minute? |
| 165 virtual void OnServerConnectionEvent(const ServerConnectionEvent& event); | 170 virtual void OnServerConnectionEvent(const ServerConnectionEvent& event); |
| 166 | 171 |
| 167 // Callback to change backoff state. | 172 // Callback to change backoff state. |
| 168 void DoCanaryJob(); | 173 void DoCanaryJob(); |
| 169 void Unthrottle(); | 174 void Unthrottle(); |
| 170 | 175 |
| 171 // Creates a session for a poll and performs the sync. | 176 // Creates a session for a poll and performs the sync. |
| 172 void PollTimerCallback(); | 177 void PollTimerCallback(); |
| 173 | 178 |
| 179 // Assign |start| and |end| to appropriate SyncerStep values for the |
| 180 // specified |purpose|. |
| 181 void SetSyncerStepsForPurpose(SyncSessionJobPurpose purpose, |
| 182 SyncerStep* start, |
| 183 SyncerStep* end); |
| 184 |
| 174 base::Thread thread_; | 185 base::Thread thread_; |
| 175 | 186 |
| 176 // Modifiable versions of kDefaultLongPollIntervalSeconds which can be | 187 // Modifiable versions of kDefaultLongPollIntervalSeconds which can be |
| 177 // updated by the server. | 188 // updated by the server. |
| 178 base::TimeDelta syncer_short_poll_interval_seconds_; | 189 base::TimeDelta syncer_short_poll_interval_seconds_; |
| 179 base::TimeDelta syncer_long_poll_interval_seconds_; | 190 base::TimeDelta syncer_long_poll_interval_seconds_; |
| 180 | 191 |
| 181 // Periodic timer for polling. See AdjustPolling. | 192 // Periodic timer for polling. See AdjustPolling. |
| 182 base::RepeatingTimer<SyncerThread> poll_timer_; | 193 base::RepeatingTimer<SyncerThread> poll_timer_; |
| 183 | 194 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 209 | 220 |
| 210 } // namespace s3 | 221 } // namespace s3 |
| 211 | 222 |
| 212 } // namespace browser_sync | 223 } // namespace browser_sync |
| 213 | 224 |
| 214 // The SyncerThread manages its own internal thread and thus outlives it. We | 225 // The SyncerThread manages its own internal thread and thus outlives it. We |
| 215 // don't need refcounting for posting tasks to this internal thread. | 226 // don't need refcounting for posting tasks to this internal thread. |
| 216 DISABLE_RUNNABLE_METHOD_REFCOUNT(browser_sync::s3::SyncerThread); | 227 DISABLE_RUNNABLE_METHOD_REFCOUNT(browser_sync::s3::SyncerThread); |
| 217 | 228 |
| 218 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD2_H_ | 229 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD2_H_ |
| OLD | NEW |