| OLD | NEW |
| (Empty) |
| 1 // Copyright 2012 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. | |
| 4 | |
| 5 #ifndef SYNC_ENGINE_SYNC_SESSION_JOB_H_ | |
| 6 #define SYNC_ENGINE_SYNC_SESSION_JOB_H_ | |
| 7 | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/memory/weak_ptr.h" | |
| 10 #include "base/time.h" | |
| 11 #include "sync/base/sync_export.h" | |
| 12 #include "sync/engine/sync_scheduler.h" | |
| 13 #include "sync/engine/syncer.h" | |
| 14 #include "sync/sessions/sync_session.h" | |
| 15 | |
| 16 namespace syncer { | |
| 17 | |
| 18 class SYNC_EXPORT_PRIVATE SyncSessionJob { | |
| 19 public: | |
| 20 enum Purpose { | |
| 21 // Uninitialized state, should never be hit in practice. | |
| 22 UNKNOWN = -1, | |
| 23 // Our poll timer schedules POLL jobs periodically based on a server | |
| 24 // assigned poll interval. | |
| 25 POLL, | |
| 26 // A nudge task can come from a variety of components needing to force | |
| 27 // a sync. The source is inferable from |session.source()|. | |
| 28 NUDGE, | |
| 29 // Typically used for fetching updates for a subset of the enabled types | |
| 30 // during initial sync or reconfiguration. | |
| 31 CONFIGURATION, | |
| 32 }; | |
| 33 | |
| 34 SyncSessionJob(Purpose purpose, | |
| 35 base::TimeTicks start, | |
| 36 const sessions::SyncSourceInfo& source_info, | |
| 37 const ConfigurationParams& config_params); | |
| 38 ~SyncSessionJob(); | |
| 39 | |
| 40 // Overwrite the sync update source with the most recent and merge the | |
| 41 // type/state map. | |
| 42 void CoalesceSources(const sessions::SyncSourceInfo& source); | |
| 43 | |
| 44 // Record that the scheduler has deemed the job as finished and give it a | |
| 45 // chance to perform any remaining cleanup and/or notification completion | |
| 46 // callback invocations. | |
| 47 // |early_exit| specifies whether the job 1) cycled through all the | |
| 48 // SyncerSteps it needed, or 2) was pre-empted by the scheduler. | |
| 49 // Returns true if we completely ran the session without errors. | |
| 50 // There are many errors that could prevent a sync cycle from succeeding, | |
| 51 // such as invalid local state, inability to contact the server, inability | |
| 52 // to authenticate with the server, and server errors. What they have in | |
| 53 // common is that the we either need to take some action and then retry the | |
| 54 // sync cycle or, in the case of transient errors, retry after some backoff | |
| 55 // timer has expired. Most importantly, the SyncScheduler should not assume | |
| 56 // that the original action that triggered the sync cycle (ie. a nudge or a | |
| 57 // notification) has been properly serviced. | |
| 58 bool Finish(bool early_exit, sessions::SyncSession* session); | |
| 59 | |
| 60 static const char* GetPurposeString(Purpose purpose); | |
| 61 static void GetSyncerStepsForPurpose(Purpose purpose, | |
| 62 SyncerStep* start, | |
| 63 SyncerStep* end); | |
| 64 | |
| 65 Purpose purpose() const; | |
| 66 const sessions::SyncSourceInfo& source_info() const; | |
| 67 base::TimeTicks scheduled_start() const; | |
| 68 void set_scheduled_start(base::TimeTicks start); | |
| 69 SyncerStep start_step() const; | |
| 70 SyncerStep end_step() const; | |
| 71 ConfigurationParams config_params() const; | |
| 72 | |
| 73 private: | |
| 74 const Purpose purpose_; | |
| 75 sessions::SyncSourceInfo source_info_; | |
| 76 | |
| 77 base::TimeTicks scheduled_start_; | |
| 78 | |
| 79 // Only used for purpose_ == CONFIGURATION. This, and different Finish() and | |
| 80 // Succeeded() behavior may be arguments to subclass in the future. | |
| 81 const ConfigurationParams config_params_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(SyncSessionJob); | |
| 84 }; | |
| 85 | |
| 86 } // namespace syncer | |
| 87 | |
| 88 #endif // SYNC_ENGINE_SYNC_SESSION_JOB_H_ | |
| OLD | NEW |