Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / sessions / session_data_type_controller.h
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.
4
5 #ifndef CHROME_BROWSER_SYNC_SESSIONS_SESSION_DATA_TYPE_CONTROLLER_H_
6 #define CHROME_BROWSER_SYNC_SESSIONS_SESSION_DATA_TYPE_CONTROLLER_H_
7
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"
12
13 class Profile;
14
15 namespace browser_sync {
16
17 class SyncedWindowDelegatesGetter;
18
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 {
24  public:
25   SessionDataTypeController(sync_driver::SyncApiComponentFactory* factory,
26                             Profile* profile,
27                             SyncedWindowDelegatesGetter* synced_window_getter,
28                             LocalDeviceInfoProvider* local_device);
29
30   // NotificationObserver interface.
31   virtual void Observe(int type,
32                        const content::NotificationSource& source,
33                        const content::NotificationDetails& details) OVERRIDE;
34
35  protected:
36   virtual ~SessionDataTypeController();
37   virtual bool StartModels() OVERRIDE;
38   virtual void StopModels() OVERRIDE;
39
40  private:
41   bool IsWaiting();
42   void MaybeCompleteLoading();
43   void OnLocalDeviceInfoInitialized();
44
45   Profile* const profile_;
46
47   SyncedWindowDelegatesGetter* synced_window_getter_;
48   content::NotificationRegistrar notification_registrar_;
49
50   LocalDeviceInfoProvider* const local_device_;
51   scoped_ptr<LocalDeviceInfoProvider::Subscription> subscription_;
52
53   // Flags that indicate the reason for pending loading models.
54   bool waiting_on_session_restore_;
55   bool waiting_on_local_device_info_;
56
57   DISALLOW_COPY_AND_ASSIGN(SessionDataTypeController);
58 };
59
60 }  // namespace browser_sync
61
62 #endif  // CHROME_BROWSER_SYNC_SESSIONS_SESSION_DATA_TYPE_CONTROLLER_H_
63