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.
5 #ifndef CHROME_BROWSER_UI_ASH_APP_SYNC_UI_STATE_H_
6 #define CHROME_BROWSER_UI_ASH_APP_SYNC_UI_STATE_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/observer_list.h"
11 #include "base/timer/timer.h"
12 #include "components/keyed_service/core/keyed_service.h"
13 #include "components/sync_driver/sync_service_observer.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "extensions/browser/extension_registry_observer.h"
18 class AppSyncUIStateObserver
;
20 class ProfileSyncService
;
22 namespace extensions
{
23 class ExtensionRegistry
;
26 // AppSyncUIState watches app sync and installation and change its state
27 // accordingly. Its status is for UI display only. It only watches for new
28 // normal user profile (i.e. it does not watch for guest profile or exsiting
29 // user profile) and lasts for at the most 1 minute.
30 class AppSyncUIState
: public KeyedService
,
31 public sync_driver::SyncServiceObserver
,
32 public extensions::ExtensionRegistryObserver
{
36 STATUS_SYNCING
, // Syncing apps or installing synced apps.
37 STATUS_TIMED_OUT
, // Timed out when waiting for sync to finish.
40 // Returns the instance for the given |profile|. It's a convenience wrapper
41 // of AppSyncUIStateFactory::GetForProfile. Note this function returns
42 // NULL if ShouldObserveAppSyncForProfile returns false for |profile|.
43 static AppSyncUIState
* Get(Profile
* profile
);
45 // Returns true if |profile| should be watched for app syncing.
46 static bool ShouldObserveAppSyncForProfile(Profile
* profile
);
48 explicit AppSyncUIState(Profile
* profile
);
49 ~AppSyncUIState() override
;
51 void AddObserver(AppSyncUIStateObserver
* observer
);
52 void RemoveObserver(AppSyncUIStateObserver
* observer
);
54 Status
status() const { return status_
; }
57 void StartObserving();
60 void SetStatus(Status status
);
62 // Checks and sets app sync status. If sync has not setup, do nothing. If sync
63 // is completed and there is no pending synced extension install, sets
64 // STATUS_SYNCING. Otherwise, sets STATUS_NORMAL.
67 // Invoked when |max_syncing_status_timer_| fires.
68 void OnMaxSyncingTimer();
70 // sync_driver::SyncServiceObserver overrides:
71 void OnStateChanged() override
;
73 // extensions::ExtensionRegistryObserver overrides:
74 void OnExtensionLoaded(content::BrowserContext
* browser_context
,
75 const extensions::Extension
* extension
) override
;
78 ProfileSyncService
* sync_service_
;
80 // Timer to limit how much time STATUS_SYNCING is allowed.
81 base::OneShotTimer
<AppSyncUIState
> max_syncing_status_timer_
;
84 base::ObserverList
<AppSyncUIStateObserver
> observers_
;
86 extensions::ExtensionRegistry
* extension_registry_
;
88 DISALLOW_COPY_AND_ASSIGN(AppSyncUIState
);
91 #endif // CHROME_BROWSER_UI_ASH_APP_SYNC_UI_STATE_H_