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