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 const base::TimeTicks& start, | |
akalin
2012/09/25 22:37:24
no const ref for timeticks
tim (not reviewing)
2012/10/08 00:20:03
Done.
| |
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 // Returns true if we completely ran the session without errors. | |
54 // There are many errors that could prevent a sync cycle from succeeding. | |
55 // These include invalid local state, inability to contact the server, | |
56 // inability to authenticate with the server, and server errors. What they | |
57 // have in common is that the we either need to take some action and then | |
58 // retry the sync cycle or, in the case of transient errors, retry after some | |
59 // backoff timer has expired. Most importantly, the SyncScheduler should not | |
60 // assume that the original action that triggered the sync cycle (ie. a nudge | |
61 // or a notification) has been properly serviced. | |
62 bool Succeeded() const; | |
63 | |
64 // Record that the scheduler has deemed the job as finished, and give it a | |
65 // chance to perform any remaining cleanup and/or notification completion | |
66 // callback invocations. | |
67 // |early_exit| specifies whether the job 1) cycled through all the | |
68 // SyncerSteps it needed, or 2) was pre-empted by the scheduler. | |
69 void Finish(bool early_exit); | |
70 | |
71 // Causes is_canary() to return true. Use with caution. | |
72 void GrantCanaryPrivilege(); | |
73 | |
74 static const char* GetPurposeString(Purpose purpose); | |
75 static void GetSyncerStepsForPurpose(Purpose purpose, | |
76 SyncerStep* start, | |
77 SyncerStep* end); | |
78 | |
79 bool is_canary() const; | |
80 Purpose purpose() const; | |
81 const base::TimeTicks& scheduled_start() const; | |
akalin
2012/09/25 22:37:24
return by value
tim (not reviewing)
2012/10/08 00:20:03
Done.
| |
82 void set_scheduled_start(const base::TimeTicks& start); | |
akalin
2012/09/25 22:37:24
here too
tim (not reviewing)
2012/10/08 00:20:03
Done.
| |
83 const sessions::SyncSession* session() const; | |
84 sessions::SyncSession* mutable_session(); | |
85 const tracked_objects::Location& from_location() const; | |
86 SyncerStep start_step() const; | |
87 SyncerStep end_step() const; | |
88 ConfigurationParams config_params() const; | |
89 | |
90 private: | |
91 // A SyncSessionJob can be in one of these three states, controlled by the | |
92 // Finish() function, see method comments. | |
93 enum FinishedState { | |
94 NOT_FINISHED, // Finish has not been called. | |
95 EARLY_EXIT, // Finish was called but the job was "preempted", | |
96 FINISHED // Indicates a "clean" finish operation. | |
97 }; | |
98 | |
99 scoped_ptr<sessions::SyncSession> CloneSession() const; | |
100 const Purpose purpose_; | |
akalin
2012/10/03 00:11:34
newline between start of variables
tim (not reviewing)
2012/10/08 00:20:03
Done.
| |
101 | |
102 base::TimeTicks scheduled_start_; | |
103 scoped_ptr<sessions::SyncSession> session_; | |
104 bool is_canary_; | |
105 | |
106 // Only used for purpose_ == CONFIGURATION. This, and different Finish() and | |
107 // Succeeded() behavior may be arguments to subclass in the future. | |
108 const ConfigurationParams config_params_; | |
109 | |
110 // Set to true if Finish() was called, false otherwise. True implies that | |
111 // a SyncShare operation took place with |session_| and it cycled through | |
112 // all requisite steps given |purpose_| without being preempted. | |
113 FinishedState finished_; | |
114 | |
115 // This is the location the job came from. Used for debugging. | |
116 // In case of multiple nudges getting coalesced this stores the | |
117 // first location that came in. | |
118 tracked_objects::Location from_location_; | |
119 | |
120 DISALLOW_COPY_AND_ASSIGN(SyncSessionJob); | |
121 }; | |
122 | |
123 } // namespace syncer | |
124 | |
125 #endif // SYNC_ENGINE_SYNC_SESSION_JOB_H_ | |
OLD | NEW |