| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 // The AllStatus object watches various sync engine components and aggregates | 5 // The AllStatus object watches various sync engine components and aggregates |
| 6 // the status of all of them into one place. | 6 // the status of all of them into one place. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_ | 8 #ifndef CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_ |
| 9 #define CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_ | 9 #define CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_ |
| 10 #pragma once | 10 #pragma once |
| 11 | 11 |
| 12 #include <map> | 12 #include <map> |
| 13 | 13 |
| 14 #include "base/lock.h" | 14 #include "base/lock.h" |
| 15 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
| 16 #include "chrome/browser/sync/engine/syncapi.h" |
| 16 #include "chrome/browser/sync/engine/syncer_types.h" | 17 #include "chrome/browser/sync/engine/syncer_types.h" |
| 17 | 18 |
| 18 namespace browser_sync { | 19 namespace browser_sync { |
| 19 | 20 |
| 20 class ScopedStatusLock; | 21 class ScopedStatusLock; |
| 21 class ServerConnectionManager; | 22 class ServerConnectionManager; |
| 22 class Syncer; | 23 class Syncer; |
| 23 class SyncerThread; | 24 class SyncerThread; |
| 24 struct AuthWatcherEvent; | 25 struct AuthWatcherEvent; |
| 25 struct ServerConnectionEvent; | 26 struct ServerConnectionEvent; |
| 26 | 27 |
| 27 class AllStatus : public SyncEngineEventListener { | 28 class AllStatus : public SyncEngineEventListener { |
| 28 friend class ScopedStatusLock; | 29 friend class ScopedStatusLock; |
| 29 public: | 30 public: |
| 30 // Status of the entire sync process distilled into a single enum. | |
| 31 enum SyncStatus { | |
| 32 // Can't connect to server, but there are no pending changes in | |
| 33 // our local dataase. | |
| 34 OFFLINE, | |
| 35 // Can't connect to server, and there are pending changes in our | |
| 36 // local cache. | |
| 37 OFFLINE_UNSYNCED, | |
| 38 // Connected and syncing. | |
| 39 SYNCING, | |
| 40 // Connected, no pending changes. | |
| 41 READY, | |
| 42 // Internal sync error. | |
| 43 CONFLICT, | |
| 44 // Can't connect to server, and we haven't completed the initial | |
| 45 // sync yet. So there's nothing we can do but wait for the server. | |
| 46 OFFLINE_UNUSABLE, | |
| 47 // For array sizing, etc. | |
| 48 ICON_STATUS_COUNT | |
| 49 }; | |
| 50 | |
| 51 struct Status { | |
| 52 SyncStatus icon; | |
| 53 int unsynced_count; | |
| 54 int conflicting_count; | |
| 55 bool syncing; | |
| 56 bool authenticated; // Successfully authenticated via gaia | |
| 57 // True if we have received at least one good reply from the server. | |
| 58 bool server_up; | |
| 59 bool server_reachable; | |
| 60 // True after a client has done a first sync. | |
| 61 bool initial_sync_ended; | |
| 62 // True if any syncer is stuck. | |
| 63 bool syncer_stuck; | |
| 64 // True if any syncer is stopped because of server issues. | |
| 65 bool server_broken; | |
| 66 // True only if the notification listener has subscribed. | |
| 67 bool notifications_enabled; | |
| 68 // Notifications counters updated by the actions in synapi. | |
| 69 int notifications_received; | |
| 70 int notifications_sent; | |
| 71 // The max number of consecutive errors from any component. | |
| 72 int max_consecutive_errors; | |
| 73 bool disk_full; | |
| 74 | |
| 75 // Contains current transfer item meta handle | |
| 76 int64 current_item_meta_handle; | |
| 77 // The next two values will be equal if all updates have been received. | |
| 78 // total updates available. | |
| 79 int64 updates_available; | |
| 80 // total updates received. | |
| 81 int64 updates_received; | |
| 82 }; | |
| 83 | 31 |
| 84 AllStatus(); | 32 AllStatus(); |
| 85 ~AllStatus(); | 33 ~AllStatus(); |
| 86 | 34 |
| 87 void HandleServerConnectionEvent(const ServerConnectionEvent& event); | 35 void HandleServerConnectionEvent(const ServerConnectionEvent& event); |
| 88 | 36 |
| 89 void HandleAuthWatcherEvent(const AuthWatcherEvent& event); | 37 void HandleAuthWatcherEvent(const AuthWatcherEvent& event); |
| 90 | 38 |
| 91 virtual void OnSyncEngineEvent(const SyncEngineEvent& event); | 39 virtual void OnSyncEngineEvent(const SyncEngineEvent& event); |
| 92 | 40 |
| 93 // Returns a string description of the SyncStatus (currently just the ascii | 41 // Returns a string description of the SyncStatus (currently just the ascii |
| 94 // version of the enum). Will LOG(FATAL) if the status us out of range. | 42 // version of the enum). Will LOG(FATAL) if the status us out of range. |
| 95 static const char* GetSyncStatusString(SyncStatus status); | 43 static const char* GetSyncStatusString( |
| 44 sync_api::SyncManager::Status::Summary status); |
| 96 | 45 |
| 97 Status status() const; | 46 sync_api::SyncManager::Status status() const; |
| 98 | 47 |
| 99 void SetNotificationsEnabled(bool notifications_enabled); | 48 void SetNotificationsEnabled(bool notifications_enabled); |
| 100 | 49 |
| 101 void IncrementNotificationsSent(); | 50 void IncrementNotificationsSent(); |
| 102 | 51 |
| 103 void IncrementNotificationsReceived(); | 52 void IncrementNotificationsReceived(); |
| 104 | 53 |
| 105 protected: | 54 protected: |
| 106 // Examines syncer to calculate syncing and the unsynced count, | 55 // Examines syncer to calculate syncing and the unsynced count, |
| 107 // and returns a Status with new values. | 56 // and returns a Status with new values. |
| 108 Status CalcSyncing(const SyncEngineEvent& event) const; | 57 sync_api::SyncManager::Status CalcSyncing(const SyncEngineEvent& event) const; |
| 109 Status CreateBlankStatus() const; | 58 sync_api::SyncManager::Status CreateBlankStatus() const; |
| 110 | 59 |
| 111 // Examines status to see what has changed, updates old_status in place. | 60 // Examines status to see what has changed, updates old_status in place. |
| 112 void CalcStatusChanges(); | 61 void CalcStatusChanges(); |
| 113 | 62 |
| 114 Status status_; | 63 sync_api::SyncManager::Status status_; |
| 115 | 64 |
| 116 mutable Lock mutex_; // Protects all data members. | 65 mutable Lock mutex_; // Protects all data members. |
| 117 DISALLOW_COPY_AND_ASSIGN(AllStatus); | 66 DISALLOW_COPY_AND_ASSIGN(AllStatus); |
| 118 }; | 67 }; |
| 119 | 68 |
| 120 class ScopedStatusLock { | 69 class ScopedStatusLock { |
| 121 public: | 70 public: |
| 122 explicit ScopedStatusLock(AllStatus* allstatus); | 71 explicit ScopedStatusLock(AllStatus* allstatus); |
| 123 ~ScopedStatusLock(); | 72 ~ScopedStatusLock(); |
| 124 protected: | 73 protected: |
| 125 AllStatus* allstatus_; | 74 AllStatus* allstatus_; |
| 126 }; | 75 }; |
| 127 | 76 |
| 128 } // namespace browser_sync | 77 } // namespace browser_sync |
| 129 | 78 |
| 130 #endif // CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_ | 79 #endif // CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_ |
| OLD | NEW |