| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 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/time.h" | |
| 10 #include "base/tracked_objects.h" | |
| 11 #include "sync/engine/sync_scheduler.h" | |
| 12 #include "sync/engine/syncer.h" | |
| 13 #include "sync/sessions/sync_session.h" | |
| 14 | |
| 15 namespace syncer { | |
| 16 | |
| 17 class SyncSessionJob { | |
| 18 public: | |
| 19 enum Purpose { | |
| 20 // Uninitialized state, should never be hit in practice. | |
| 21 UNKNOWN = -1, | |
| 22 // Our poll timer schedules POLL jobs periodically based on a server | |
| 23 // assigned poll interval. | |
| 24 POLL, | |
| 25 // A nudge task can come from a variety of components needing to force | |
| 26 // a sync. The source is inferable from |session.source()|. | |
| 27 NUDGE, | |
| 28 // Typically used for fetching updates for a subset of the enabled types | |
| 29 // during initial sync or reconfiguration. | |
| 30 CONFIGURATION, | |
| 31 }; | |
| 32 | |
| 33 SyncSessionJob(Purpose purpose, | |
| 34 base::TimeTicks start, | |
| 35 scoped_ptr<sessions::SyncSession> session, | |
| 36 const ConfigurationParams& config_params, | |
| 37 const tracked_objects::Location& nudge_location); | |
| 38 ~SyncSessionJob(); | |
| 39 | |
| 40 // Returns a new clone of the job, with a cloned SyncSession ready to be | |
| 41 // retried / rescheduled. The returned job will *never* be a canary, | |
| 42 // regardless of |this|. A job can only be cloned once it has finished, | |
| 43 // to prevent bugs where multiple jobs are scheduled with the same session. | |
| 44 // Use CloneAndAbandon if you want to clone before finishing. | |
| 45 scoped_ptr<SyncSessionJob> Clone() const; | |
| 46 scoped_ptr<SyncSessionJob> CloneFromLocation( | |
| 47 const tracked_objects::Location& from_here) const; | |
| 48 | |
| 49 // Same as Clone() above, but also ejects the SyncSession from this job, | |
| 50 // preventing it from ever being used for a sync cycle. | |
| 51 scoped_ptr<SyncSessionJob> CloneAndAbandon(); | |
| 52 | |
| 53 // Record that the scheduler has deemed the job as finished and give it a | |
| 54 // chance to perform any remaining cleanup and/or notification completion | |
| 55 // callback invocations. | |
| 56 // |early_exit| specifies whether the job 1) cycled through all the | |
| 57 // SyncerSteps it needed, or 2) was pre-empted by the scheduler. | |
| 58 // Returns true if we completely ran the session without errors. | |
| 59 // There are many errors that could prevent a sync cycle from succeeding, | |
| 60 // such as invalid local state, inability to contact the server, inability | |
| 61 // to authenticate with the server, and server errors. What they have in | |
| 62 // common is that the we either need to take some action and then retry the | |
| 63 // sync cycle or, in the case of transient errors, retry after some backoff | |
| 64 // timer has expired. Most importantly, the SyncScheduler should not assume | |
| 65 // that the original action that triggered the sync cycle (ie. a nudge or a | |
| 66 // notification) has been properly serviced. | |
| 67 bool Finish(bool early_exit); | |
| 68 | |
| 69 // Causes is_canary() to return true. Use with caution. | |
| 70 void GrantCanaryPrivilege(); | |
| 71 | |
| 72 static const char* GetPurposeString(Purpose purpose); | |
| 73 static void GetSyncerStepsForPurpose(Purpose purpose, | |
| 74 SyncerStep* start, | |
| 75 SyncerStep* end); | |
| 76 | |
| 77 bool is_canary() const; | |
| 78 Purpose purpose() const; | |
| 79 base::TimeTicks scheduled_start() const; | |
| 80 void set_scheduled_start(base::TimeTicks start); | |
| 81 const sessions::SyncSession* session() const; | |
| 82 sessions::SyncSession* mutable_session(); | |
| 83 const tracked_objects::Location& from_location() const; | |
| 84 SyncerStep start_step() const; | |
| 85 SyncerStep end_step() const; | |
| 86 ConfigurationParams config_params() const; | |
| 87 | |
| 88 private: | |
| 89 // A SyncSessionJob can be in one of these three states, controlled by the | |
| 90 // Finish() function, see method comments. | |
| 91 enum FinishedState { | |
| 92 NOT_FINISHED, // Finish has not been called. | |
| 93 EARLY_EXIT, // Finish was called but the job was "preempted", | |
| 94 FINISHED // Indicates a "clean" finish operation. | |
| 95 }; | |
| 96 | |
| 97 scoped_ptr<sessions::SyncSession> CloneSession() const; | |
| 98 | |
| 99 const Purpose purpose_; | |
| 100 | |
| 101 base::TimeTicks scheduled_start_; | |
| 102 scoped_ptr<sessions::SyncSession> session_; | |
| 103 bool is_canary_; | |
| 104 | |
| 105 // Only used for purpose_ == CONFIGURATION. This, and different Finish() and | |
| 106 // Succeeded() behavior may be arguments to subclass in the future. | |
| 107 const ConfigurationParams config_params_; | |
| 108 | |
| 109 // Set to true if Finish() was called, false otherwise. True implies that | |
| 110 // a SyncShare operation took place with |session_| and it cycled through | |
| 111 // all requisite steps given |purpose_| without being preempted. | |
| 112 FinishedState finished_; | |
| 113 | |
| 114 // This is the location the job came from. Used for debugging. | |
| 115 // In case of multiple nudges getting coalesced this stores the | |
| 116 // first location that came in. | |
| 117 tracked_objects::Location from_location_; | |
| 118 | |
| 119 DISALLOW_COPY_AND_ASSIGN(SyncSessionJob); | |
| 120 }; | |
| 121 | |
| 122 } // namespace syncer | |
| 123 | |
| 124 #endif // SYNC_ENGINE_SYNC_SESSION_JOB_H_ | |
| OLD | NEW |