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 "chrome/browser/sync/glue/local_device_info_provider.h"
9 #include "components/sync_driver/ui_data_type_controller.h"
10 #include "content/public/browser/notification_observer.h"
11 #include "content/public/browser/notification_registrar.h"
15 namespace browser_sync {
17 class SyncedWindowDelegatesGetter;
19 // Overrides StartModels to avoid sync contention with sessions during
20 // a session restore operation at startup and to wait for the local
21 // device info to become available.
22 class SessionDataTypeController : public sync_driver::UIDataTypeController,
23 public content::NotificationObserver {
25 SessionDataTypeController(sync_driver::SyncApiComponentFactory* factory,
27 SyncedWindowDelegatesGetter* synced_window_getter,
28 LocalDeviceInfoProvider* local_device);
30 // NotificationObserver interface.
31 virtual void Observe(int type,
32 const content::NotificationSource& source,
33 const content::NotificationDetails& details) OVERRIDE;
36 virtual ~SessionDataTypeController();
37 virtual bool StartModels() OVERRIDE;
38 virtual void StopModels() OVERRIDE;
42 void MaybeCompleteLoading();
43 void OnLocalDeviceInfoInitialized();
45 Profile* const profile_;
47 SyncedWindowDelegatesGetter* synced_window_getter_;
48 content::NotificationRegistrar notification_registrar_;
50 LocalDeviceInfoProvider* const local_device_;
51 scoped_ptr<LocalDeviceInfoProvider::Subscription> subscription_;
53 // Flags that indicate the reason for pending loading models.
54 bool waiting_on_session_restore_;
55 bool waiting_on_local_device_info_;
57 DISALLOW_COPY_AND_ASSIGN(SessionDataTypeController);
60 } // namespace browser_sync
62 #endif // CHROME_BROWSER_SYNC_SESSIONS_SESSION_DATA_TYPE_CONTROLLER_H_