• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_
9 #define CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_
10 #pragma once
11 
12 #include <map>
13 
14 #include "base/memory/scoped_ptr.h"
15 #include "base/synchronization/lock.h"
16 #include "chrome/browser/sync/engine/syncapi.h"
17 #include "chrome/browser/sync/engine/syncer_types.h"
18 
19 namespace browser_sync {
20 
21 class ScopedStatusLock;
22 class ServerConnectionManager;
23 class Syncer;
24 class SyncerThread;
25 struct AuthWatcherEvent;
26 struct ServerConnectionEvent;
27 
28 class AllStatus : public SyncEngineEventListener {
29   friend class ScopedStatusLock;
30  public:
31 
32   AllStatus();
33   ~AllStatus();
34 
35   void HandleServerConnectionEvent(const ServerConnectionEvent& event);
36 
37   void HandleAuthWatcherEvent(const AuthWatcherEvent& event);
38 
39   virtual void OnSyncEngineEvent(const SyncEngineEvent& event);
40 
41   sync_api::SyncManager::Status status() const;
42 
43   void SetNotificationsEnabled(bool notifications_enabled);
44 
45   void IncrementNotificationsSent();
46 
47   void IncrementNotificationsReceived();
48 
49  protected:
50   // Examines syncer to calculate syncing and the unsynced count,
51   // and returns a Status with new values.
52   sync_api::SyncManager::Status CalcSyncing(const SyncEngineEvent& event) const;
53   sync_api::SyncManager::Status CreateBlankStatus() const;
54 
55   // Examines status to see what has changed, updates old_status in place.
56   void CalcStatusChanges();
57 
58   sync_api::SyncManager::Status status_;
59 
60   mutable base::Lock mutex_;  // Protects all data members.
61   DISALLOW_COPY_AND_ASSIGN(AllStatus);
62 };
63 
64 class ScopedStatusLock {
65  public:
66   explicit ScopedStatusLock(AllStatus* allstatus);
67   ~ScopedStatusLock();
68  protected:
69   AllStatus* allstatus_;
70 };
71 
72 }  // namespace browser_sync
73 
74 #endif  // CHROME_BROWSER_SYNC_ENGINE_ALL_STATUS_H_
75