session_data_type_controller.h revision 5f1c94371a64b3196d4be9466099bb892df9b88e
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
13class Profile;
14
15namespace browser_sync {
16
17class 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.
22class 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                            const DisableTypeCallback& disable_callback);
30
31  // NotificationObserver interface.
32  virtual void Observe(int type,
33                       const content::NotificationSource& source,
34                       const content::NotificationDetails& details) OVERRIDE;
35
36 protected:
37  virtual ~SessionDataTypeController();
38  virtual bool StartModels() OVERRIDE;
39  virtual void StopModels() OVERRIDE;
40
41 private:
42  bool IsWaiting();
43  void MaybeCompleteLoading();
44  void OnLocalDeviceInfoInitialized();
45
46  Profile* const profile_;
47
48  SyncedWindowDelegatesGetter* synced_window_getter_;
49  content::NotificationRegistrar notification_registrar_;
50
51  LocalDeviceInfoProvider* const local_device_;
52  scoped_ptr<LocalDeviceInfoProvider::Subscription> subscription_;
53
54  // Flags that indicate the reason for pending loading models.
55  bool waiting_on_session_restore_;
56  bool waiting_on_local_device_info_;
57
58  DISALLOW_COPY_AND_ASSIGN(SessionDataTypeController);
59};
60
61}  // namespace browser_sync
62
63#endif  // CHROME_BROWSER_SYNC_SESSIONS_SESSION_DATA_TYPE_CONTROLLER_H_
64
65