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" |
11 #include "base/tracked_objects.h" | |
12 #include "sync/base/sync_export.h" | 11 #include "sync/base/sync_export.h" |
13 #include "sync/engine/sync_scheduler.h" | 12 #include "sync/engine/sync_scheduler.h" |
14 #include "sync/engine/syncer.h" | 13 #include "sync/engine/syncer.h" |
15 #include "sync/sessions/sync_session.h" | 14 #include "sync/sessions/sync_session.h" |
16 | 15 |
17 namespace syncer { | 16 namespace syncer { |
18 | 17 |
19 class SYNC_EXPORT_PRIVATE SyncSessionJob { | 18 class SYNC_EXPORT_PRIVATE SyncSessionJob { |
20 public: | 19 public: |
21 enum Purpose { | 20 enum Purpose { |
(...skipping 13 matching lines...) Expand all Loading... |
35 // This class exists to inform an interested party about the destruction of | 34 // This class exists to inform an interested party about the destruction of |
36 // a SyncSessionJob. | 35 // a SyncSessionJob. |
37 class SYNC_EXPORT_PRIVATE DestructionObserver { | 36 class SYNC_EXPORT_PRIVATE DestructionObserver { |
38 public: | 37 public: |
39 virtual void OnJobDestroyed(SyncSessionJob* job) = 0; | 38 virtual void OnJobDestroyed(SyncSessionJob* job) = 0; |
40 }; | 39 }; |
41 | 40 |
42 SyncSessionJob(Purpose purpose, | 41 SyncSessionJob(Purpose purpose, |
43 base::TimeTicks start, | 42 base::TimeTicks start, |
44 scoped_ptr<sessions::SyncSession> session, | 43 scoped_ptr<sessions::SyncSession> session, |
45 const ConfigurationParams& config_params, | 44 const ConfigurationParams& config_params); |
46 const tracked_objects::Location& nudge_location); | |
47 ~SyncSessionJob(); | 45 ~SyncSessionJob(); |
48 | 46 |
49 // 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 |
50 // retried / rescheduled. The returned job will *never* be a canary, | 48 // retried / rescheduled. The returned job will *never* be a canary, |
51 // regardless of |this|. A job can only be cloned once it has finished, | 49 // regardless of |this|. A job can only be cloned once it has finished, |
52 // to prevent bugs where multiple jobs are scheduled with the same session. | 50 // to prevent bugs where multiple jobs are scheduled with the same session. |
53 // Use CloneAndAbandon if you want to clone before finishing. | 51 // Use CloneAndAbandon if you want to clone before finishing. |
54 scoped_ptr<SyncSessionJob> Clone() const; | 52 scoped_ptr<SyncSessionJob> Clone() const; |
55 scoped_ptr<SyncSessionJob> CloneFromLocation( | |
56 const tracked_objects::Location& from_here) const; | |
57 | 53 |
58 // Same as Clone() above, but also ejects the SyncSession from this job, | 54 // Same as Clone() above, but also ejects the SyncSession from this job, |
59 // preventing it from ever being used for a sync cycle. | 55 // preventing it from ever being used for a sync cycle. |
60 scoped_ptr<SyncSessionJob> CloneAndAbandon(); | 56 scoped_ptr<SyncSessionJob> CloneAndAbandon(); |
61 | 57 |
62 // Record that the scheduler has deemed the job as finished and give it a | 58 // 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 | 59 // chance to perform any remaining cleanup and/or notification completion |
64 // callback invocations. | 60 // callback invocations. |
65 // |early_exit| specifies whether the job 1) cycled through all the | 61 // |early_exit| specifies whether the job 1) cycled through all the |
66 // SyncerSteps it needed, or 2) was pre-empted by the scheduler. | 62 // SyncerSteps it needed, or 2) was pre-empted by the scheduler. |
(...skipping 15 matching lines...) Expand all Loading... |
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; | 82 bool is_canary() const; |
87 Purpose purpose() const; | 83 Purpose purpose() const; |
88 base::TimeTicks scheduled_start() const; | 84 base::TimeTicks scheduled_start() const; |
89 void set_scheduled_start(base::TimeTicks start); | 85 void set_scheduled_start(base::TimeTicks start); |
90 const sessions::SyncSession* session() const; | 86 const sessions::SyncSession* session() const; |
91 sessions::SyncSession* mutable_session(); | 87 sessions::SyncSession* mutable_session(); |
92 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 { |
(...skipping 12 matching lines...) Expand all Loading... |
115 | 110 |
116 // Only used for purpose_ == CONFIGURATION. This, and different Finish() and | 111 // Only used for purpose_ == CONFIGURATION. This, and different Finish() and |
117 // Succeeded() behavior may be arguments to subclass in the future. | 112 // Succeeded() behavior may be arguments to subclass in the future. |
118 const ConfigurationParams config_params_; | 113 const ConfigurationParams config_params_; |
119 | 114 |
120 // Set to true if Finish() was called, false otherwise. True implies that | 115 // Set to true if Finish() was called, false otherwise. True implies that |
121 // a SyncShare operation took place with |session_| and it cycled through | 116 // a SyncShare operation took place with |session_| and it cycled through |
122 // all requisite steps given |purpose_| without being preempted. | 117 // all requisite steps given |purpose_| without being preempted. |
123 FinishedState finished_; | 118 FinishedState finished_; |
124 | 119 |
125 // This is the location the job came from. Used for debugging. | |
126 // In case of multiple nudges getting coalesced this stores the | |
127 // first location that came in. | |
128 tracked_objects::Location from_location_; | |
129 | |
130 base::WeakPtr<DestructionObserver> destruction_observer_; | 120 base::WeakPtr<DestructionObserver> destruction_observer_; |
131 | 121 |
132 DISALLOW_COPY_AND_ASSIGN(SyncSessionJob); | 122 DISALLOW_COPY_AND_ASSIGN(SyncSessionJob); |
133 }; | 123 }; |
134 | 124 |
135 } // namespace syncer | 125 } // namespace syncer |
136 | 126 |
137 #endif // SYNC_ENGINE_SYNC_SESSION_JOB_H_ | 127 #endif // SYNC_ENGINE_SYNC_SESSION_JOB_H_ |
OLD | NEW |