| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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 SYNC_ENGINE_SYNC_SESSION_JOB_H_ | 5 #ifndef SYNC_ENGINE_SYNC_SESSION_JOB_H_ |
| 6 #define SYNC_ENGINE_SYNC_SESSION_JOB_H_ | 6 #define SYNC_ENGINE_SYNC_SESSION_JOB_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 virtual void OnJobDestroyed(SyncSessionJob* job) = 0; | 38 virtual void OnJobDestroyed(SyncSessionJob* job) = 0; |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 SyncSessionJob(Purpose purpose, | 41 SyncSessionJob(Purpose purpose, |
| 42 base::TimeTicks start, | 42 base::TimeTicks start, |
| 43 scoped_ptr<sessions::SyncSession> session, | 43 scoped_ptr<sessions::SyncSession> session, |
| 44 const ConfigurationParams& config_params); | 44 const ConfigurationParams& config_params); |
| 45 ~SyncSessionJob(); | 45 ~SyncSessionJob(); |
| 46 | 46 |
| 47 // Returns a new clone of the job, with a cloned SyncSession ready to be | 47 // Returns a new clone of the job, with a cloned SyncSession ready to be |
| 48 // retried / rescheduled. The returned job will *never* be a canary, | 48 // retried / rescheduled. A job can only be cloned once it has finished, to |
| 49 // regardless of |this|. A job can only be cloned once it has finished, | 49 // prevent bugs where multiple jobs are scheduled with the same session. Use |
| 50 // to prevent bugs where multiple jobs are scheduled with the same session. | 50 // CloneAndAbandon if you want to clone before finishing. |
| 51 // Use CloneAndAbandon if you want to clone before finishing. | |
| 52 scoped_ptr<SyncSessionJob> Clone() const; | 51 scoped_ptr<SyncSessionJob> Clone() const; |
| 53 | 52 |
| 54 // Same as Clone() above, but also ejects the SyncSession from this job, | 53 // Same as Clone() above, but also ejects the SyncSession from this job, |
| 55 // preventing it from ever being used for a sync cycle. | 54 // preventing it from ever being used for a sync cycle. |
| 56 scoped_ptr<SyncSessionJob> CloneAndAbandon(); | 55 scoped_ptr<SyncSessionJob> CloneAndAbandon(); |
| 57 | 56 |
| 58 // Record that the scheduler has deemed the job as finished and give it a | 57 // Record that the scheduler has deemed the job as finished and give it a |
| 59 // chance to perform any remaining cleanup and/or notification completion | 58 // chance to perform any remaining cleanup and/or notification completion |
| 60 // callback invocations. | 59 // callback invocations. |
| 61 // |early_exit| specifies whether the job 1) cycled through all the | 60 // |early_exit| specifies whether the job 1) cycled through all the |
| 62 // SyncerSteps it needed, or 2) was pre-empted by the scheduler. | 61 // SyncerSteps it needed, or 2) was pre-empted by the scheduler. |
| 63 // Returns true if we completely ran the session without errors. | 62 // Returns true if we completely ran the session without errors. |
| 64 // There are many errors that could prevent a sync cycle from succeeding, | 63 // There are many errors that could prevent a sync cycle from succeeding, |
| 65 // such as invalid local state, inability to contact the server, inability | 64 // such as invalid local state, inability to contact the server, inability |
| 66 // to authenticate with the server, and server errors. What they have in | 65 // to authenticate with the server, and server errors. What they have in |
| 67 // common is that the we either need to take some action and then retry the | 66 // common is that the we either need to take some action and then retry the |
| 68 // sync cycle or, in the case of transient errors, retry after some backoff | 67 // sync cycle or, in the case of transient errors, retry after some backoff |
| 69 // timer has expired. Most importantly, the SyncScheduler should not assume | 68 // timer has expired. Most importantly, the SyncScheduler should not assume |
| 70 // that the original action that triggered the sync cycle (ie. a nudge or a | 69 // that the original action that triggered the sync cycle (ie. a nudge or a |
| 71 // notification) has been properly serviced. | 70 // notification) has been properly serviced. |
| 72 bool Finish(bool early_exit); | 71 bool Finish(bool early_exit); |
| 73 | 72 |
| 74 // Causes is_canary() to return true. Use with caution. | |
| 75 void GrantCanaryPrivilege(); | |
| 76 | |
| 77 static const char* GetPurposeString(Purpose purpose); | 73 static const char* GetPurposeString(Purpose purpose); |
| 78 static void GetSyncerStepsForPurpose(Purpose purpose, | 74 static void GetSyncerStepsForPurpose(Purpose purpose, |
| 79 SyncerStep* start, | 75 SyncerStep* start, |
| 80 SyncerStep* end); | 76 SyncerStep* end); |
| 81 | 77 |
| 82 bool is_canary() const; | |
| 83 Purpose purpose() const; | 78 Purpose purpose() const; |
| 84 base::TimeTicks scheduled_start() const; | 79 base::TimeTicks scheduled_start() const; |
| 85 void set_scheduled_start(base::TimeTicks start); | 80 void set_scheduled_start(base::TimeTicks start); |
| 86 const sessions::SyncSession* session() const; | 81 const sessions::SyncSession* session() const; |
| 87 sessions::SyncSession* mutable_session(); | 82 sessions::SyncSession* mutable_session(); |
| 88 SyncerStep start_step() const; | 83 SyncerStep start_step() const; |
| 89 SyncerStep end_step() const; | 84 SyncerStep end_step() const; |
| 90 ConfigurationParams config_params() const; | 85 ConfigurationParams config_params() const; |
| 91 | 86 |
| 92 void set_destruction_observer( | 87 void set_destruction_observer( |
| 93 const base::WeakPtr<DestructionObserver>& observer); | 88 const base::WeakPtr<DestructionObserver>& observer); |
| 94 private: | 89 private: |
| 95 // A SyncSessionJob can be in one of these three states, controlled by the | 90 // A SyncSessionJob can be in one of these three states, controlled by the |
| 96 // Finish() function, see method comments. | 91 // Finish() function, see method comments. |
| 97 enum FinishedState { | 92 enum FinishedState { |
| 98 NOT_FINISHED, // Finish has not been called. | 93 NOT_FINISHED, // Finish has not been called. |
| 99 EARLY_EXIT, // Finish was called but the job was "preempted", | 94 EARLY_EXIT, // Finish was called but the job was "preempted", |
| 100 FINISHED // Indicates a "clean" finish operation. | 95 FINISHED // Indicates a "clean" finish operation. |
| 101 }; | 96 }; |
| 102 | 97 |
| 103 scoped_ptr<sessions::SyncSession> CloneSession() const; | 98 scoped_ptr<sessions::SyncSession> CloneSession() const; |
| 104 | 99 |
| 105 const Purpose purpose_; | 100 const Purpose purpose_; |
| 106 | 101 |
| 107 base::TimeTicks scheduled_start_; | 102 base::TimeTicks scheduled_start_; |
| 108 scoped_ptr<sessions::SyncSession> session_; | 103 scoped_ptr<sessions::SyncSession> session_; |
| 109 bool is_canary_; | |
| 110 | 104 |
| 111 // Only used for purpose_ == CONFIGURATION. This, and different Finish() and | 105 // Only used for purpose_ == CONFIGURATION. This, and different Finish() and |
| 112 // Succeeded() behavior may be arguments to subclass in the future. | 106 // Succeeded() behavior may be arguments to subclass in the future. |
| 113 const ConfigurationParams config_params_; | 107 const ConfigurationParams config_params_; |
| 114 | 108 |
| 115 // Set to true if Finish() was called, false otherwise. True implies that | 109 // Set to true if Finish() was called, false otherwise. True implies that |
| 116 // a SyncShare operation took place with |session_| and it cycled through | 110 // a SyncShare operation took place with |session_| and it cycled through |
| 117 // all requisite steps given |purpose_| without being preempted. | 111 // all requisite steps given |purpose_| without being preempted. |
| 118 FinishedState finished_; | 112 FinishedState finished_; |
| 119 | 113 |
| 120 base::WeakPtr<DestructionObserver> destruction_observer_; | 114 base::WeakPtr<DestructionObserver> destruction_observer_; |
| 121 | 115 |
| 122 DISALLOW_COPY_AND_ASSIGN(SyncSessionJob); | 116 DISALLOW_COPY_AND_ASSIGN(SyncSessionJob); |
| 123 }; | 117 }; |
| 124 | 118 |
| 125 } // namespace syncer | 119 } // namespace syncer |
| 126 | 120 |
| 127 #endif // SYNC_ENGINE_SYNC_SESSION_JOB_H_ | 121 #endif // SYNC_ENGINE_SYNC_SESSION_JOB_H_ |
| OLD | NEW |