1 // Copyright 2014 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_SYNC_SESSIONS_SESSION_DATA_TYPE_CONTROLLER_H_
6 #define CHROME_BROWSER_SYNC_SESSIONS_SESSION_DATA_TYPE_CONTROLLER_H_
8 #include "base/prefs/pref_change_registrar.h"
9 #include "components/sync_driver/local_device_info_provider.h"
10 #include "components/sync_driver/ui_data_type_controller.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
16 namespace browser_sync {
18 class SyncedWindowDelegatesGetter;
20 // Overrides StartModels to avoid sync contention with sessions during
21 // a session restore operation at startup and to wait for the local
22 // device info to become available.
23 class SessionDataTypeController : public sync_driver::UIDataTypeController,
24 public content::NotificationObserver {
26 SessionDataTypeController(sync_driver::SyncApiComponentFactory* factory,
28 SyncedWindowDelegatesGetter* synced_window_getter,
29 sync_driver::LocalDeviceInfoProvider* local_device);
31 // NotificationObserver interface.
32 virtual void Observe(int type,
33 const content::NotificationSource& source,
34 const content::NotificationDetails& details) OVERRIDE;
36 // UIDataTypeController interface.
37 virtual bool StartModels() OVERRIDE;
38 virtual void StopModels() OVERRIDE;
39 virtual bool ReadyForStart() const OVERRIDE;
42 virtual ~SessionDataTypeController();
46 void MaybeCompleteLoading();
47 void OnLocalDeviceInfoInitialized();
48 void OnSavingBrowserHistoryPrefChanged();
50 Profile* const profile_;
52 SyncedWindowDelegatesGetter* synced_window_getter_;
53 content::NotificationRegistrar notification_registrar_;
55 sync_driver::LocalDeviceInfoProvider* const local_device_;
56 scoped_ptr<sync_driver::LocalDeviceInfoProvider::Subscription> subscription_;
58 // Flags that indicate the reason for pending loading models.
59 bool waiting_on_session_restore_;
60 bool waiting_on_local_device_info_;
62 PrefChangeRegistrar pref_registrar_;
64 DISALLOW_COPY_AND_ASSIGN(SessionDataTypeController);
67 } // namespace browser_sync
69 #endif // CHROME_BROWSER_SYNC_SESSIONS_SESSION_DATA_TYPE_CONTROLLER_H_