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 // The AllStatus object watches various sync engine components and aggregates | |
6 // the status of all of them into one place. | |
7 | |
8 #ifndef SYNC_ENGINE_ALL_STATUS_H_ | |
9 #define SYNC_ENGINE_ALL_STATUS_H_ | |
10 | |
11 #include <map> | |
12 #include <string> | |
13 | |
14 #include "base/compiler_specific.h" | |
15 #include "base/macros.h" | |
16 #include "base/synchronization/lock.h" | |
17 #include "sync/engine/nudge_source.h" | |
18 #include "sync/engine/sync_engine_event_listener.h" | |
19 #include "sync/engine/syncer_types.h" | |
20 #include "sync/internal_api/public/base/model_type.h" | |
21 #include "sync/internal_api/public/engine/sync_status.h" | |
22 | |
23 namespace syncer { | |
24 | |
25 class ScopedStatusLock; | |
26 struct ServerConnectionEvent; | |
27 struct SyncCycleEvent; | |
28 | |
29 // This class collects data and uses it to update its internal state. It can | |
30 // return a snapshot of this state as a SyncerStatus object. | |
31 // | |
32 // Most of this data ends up on the about:sync page. But the page is only | |
33 // 'pinged' to update itself at the end of a sync cycle. A user could refresh | |
34 // manually, but unless their timing is excellent it's unlikely that a user will | |
35 // see any state in mid-sync cycle. We have no plans to change this. However, | |
36 // we will continue to collect data and update state mid-sync-cycle in case we | |
37 // need to debug slow or stuck sync cycles. | |
38 class AllStatus : public SyncEngineEventListener { | |
39 public: | |
40 AllStatus(); | |
41 ~AllStatus() override; | |
42 | |
43 // SyncEngineEventListener implementation. | |
44 void OnSyncCycleEvent(const SyncCycleEvent& event) override; | |
45 void OnActionableError(const SyncProtocolError& error) override; | |
46 void OnRetryTimeChanged(base::Time retry_time) override; | |
47 void OnThrottledTypesChanged(ModelTypeSet throttled_types) override; | |
48 void OnMigrationRequested(ModelTypeSet types) override; | |
49 void OnProtocolEvent(const ProtocolEvent& event) override; | |
50 | |
51 SyncStatus status() const; | |
52 | |
53 void SetNotificationsEnabled(bool notifications_enabled); | |
54 | |
55 void IncrementNotifiableCommits(); | |
56 | |
57 void IncrementNotificationsReceived(); | |
58 | |
59 void SetEncryptedTypes(ModelTypeSet types); | |
60 void SetCryptographerReady(bool ready); | |
61 void SetCryptoHasPendingKeys(bool has_pending_keys); | |
62 void SetPassphraseType(PassphraseType type); | |
63 void SetHasKeystoreKey(bool has_keystore_key); | |
64 void SetKeystoreMigrationTime(const base::Time& migration_time); | |
65 | |
66 void SetSyncId(const std::string& sync_id); | |
67 void SetInvalidatorClientId(const std::string& invalidator_client_id); | |
68 | |
69 void IncrementNudgeCounter(NudgeSource source); | |
70 | |
71 protected: | |
72 // Examines syncer to calculate syncing and the unsynced count, | |
73 // and returns a Status with new values. | |
74 SyncStatus CalcSyncing(const SyncCycleEvent& event) const; | |
75 SyncStatus CreateBlankStatus() const; | |
76 | |
77 SyncStatus status_; | |
78 | |
79 mutable base::Lock mutex_; // Protects all data members. | |
80 | |
81 private: | |
82 friend class ScopedStatusLock; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(AllStatus); | |
85 }; | |
86 | |
87 class ScopedStatusLock { | |
88 public: | |
89 explicit ScopedStatusLock(AllStatus* allstatus); | |
90 ~ScopedStatusLock(); | |
91 protected: | |
92 AllStatus* allstatus_; | |
93 }; | |
94 | |
95 } // namespace syncer | |
96 | |
97 #endif // SYNC_ENGINE_ALL_STATUS_H_ | |
OLD | NEW |