Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / ash / app_sync_ui_state.h
blob55dc6c2d2da8a298e9dabcec8c10315a99f22bf2
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 "chrome/browser/sync/profile_sync_service_observer.h"
13 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
17 class AppSyncUIStateObserver;
18 class Profile;
19 class ProfileSyncService;
21 // AppSyncUIState watches app sync and installation and change its state
22 // accordingly. Its status is for UI display only. It only watches for new
23 // normal user profile (i.e. it does not watch for guest profile or exsiting
24 // user profile) and lasts for at the most 1 minute.
25 class AppSyncUIState : public BrowserContextKeyedService,
26 public content::NotificationObserver,
27 public ProfileSyncServiceObserver {
28 public:
29 enum Status {
30 STATUS_NORMAL,
31 STATUS_SYNCING, // Syncing apps or installing synced apps.
32 STATUS_TIMED_OUT, // Timed out when waiting for sync to finish.
35 // Returns the instance for the given |profile|. It's a convenience wrapper
36 // of AppSyncUIStateFactory::GetForProfile. Note this function returns
37 // NULL if ShouldObserveAppSyncForProfile returns false for |profile|.
38 static AppSyncUIState* Get(Profile* profile);
40 // Returns true if |profile| should be watched for app syncing.
41 static bool ShouldObserveAppSyncForProfile(Profile* profile);
43 explicit AppSyncUIState(Profile* profile);
44 virtual ~AppSyncUIState();
46 void AddObserver(AppSyncUIStateObserver* observer);
47 void RemoveObserver(AppSyncUIStateObserver* observer);
49 Status status() const { return status_; }
51 private:
52 void StartObserving();
53 void StopObserving();
55 void SetStatus(Status status);
57 // Checks and sets app sync status. If sync has not setup, do nothing. If sync
58 // is completed and there is no pending synced extension install, sets
59 // STATUS_SYNCING. Otherwise, sets STATUS_NORMAL.
60 void CheckAppSync();
62 // Invoked when |max_syncing_status_timer_| fires.
63 void OnMaxSyncingTimer();
65 // content::NotificationObserver overrides:
66 virtual void Observe(int type,
67 const content::NotificationSource& source,
68 const content::NotificationDetails& details) OVERRIDE;
70 // ProfileSyncServiceObserver overrides:
71 virtual void OnStateChanged() OVERRIDE;
73 content::NotificationRegistrar registrar_;
75 Profile* profile_;
76 ProfileSyncService* sync_service_;
78 // Timer to limit how much time STATUS_SYNCING is allowed.
79 base::OneShotTimer<AppSyncUIState> max_syncing_status_timer_;
81 Status status_;
82 ObserverList<AppSyncUIStateObserver> observers_;
84 DISALLOW_COPY_AND_ASSIGN(AppSyncUIState);
87 #endif // CHROME_BROWSER_UI_ASH_APP_SYNC_UI_STATE_H_