Upstream version 10.39.225.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 "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"
13
14 class Profile;
15
16 namespace browser_sync {
17
18 class SyncedWindowDelegatesGetter;
19
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 {
25  public:
26   SessionDataTypeController(sync_driver::SyncApiComponentFactory* factory,
27                             Profile* profile,
28                             SyncedWindowDelegatesGetter* synced_window_getter,
29                             sync_driver::LocalDeviceInfoProvider* local_device);
30
31   // NotificationObserver interface.
32   virtual void Observe(int type,
33                        const content::NotificationSource& source,
34                        const content::NotificationDetails& details) OVERRIDE;
35
36   // UIDataTypeController interface.
37   virtual bool StartModels() OVERRIDE;
38   virtual void StopModels() OVERRIDE;
39   virtual bool ReadyForStart() const OVERRIDE;
40
41  protected:
42   virtual ~SessionDataTypeController();
43
44  private:
45   bool IsWaiting();
46   void MaybeCompleteLoading();
47   void OnLocalDeviceInfoInitialized();
48   void OnSavingBrowserHistoryPrefChanged();
49
50   Profile* const profile_;
51
52   SyncedWindowDelegatesGetter* synced_window_getter_;
53   content::NotificationRegistrar notification_registrar_;
54
55   sync_driver::LocalDeviceInfoProvider* const local_device_;
56   scoped_ptr<sync_driver::LocalDeviceInfoProvider::Subscription> subscription_;
57
58   // Flags that indicate the reason for pending loading models.
59   bool waiting_on_session_restore_;
60   bool waiting_on_local_device_info_;
61
62   PrefChangeRegistrar pref_registrar_;
63
64   DISALLOW_COPY_AND_ASSIGN(SessionDataTypeController);
65 };
66
67 }  // namespace browser_sync
68
69 #endif  // CHROME_BROWSER_SYNC_SESSIONS_SESSION_DATA_TYPE_CONTROLLER_H_