data_type_manager_impl.h revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2010 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_GLUE_DATA_TYPE_MANAGER_IMPL_H__
6#define CHROME_BROWSER_SYNC_GLUE_DATA_TYPE_MANAGER_IMPL_H__
7
8#include "chrome/browser/sync/glue/data_type_manager.h"
9
10#include <map>
11#include <vector>
12
13#include "base/basictypes.h"
14#include "base/scoped_ptr.h"
15#include "base/task.h"
16#include "chrome/common/notification_observer.h"
17#include "chrome/common/notification_registrar.h"
18#include "chrome/common/notification_type.h"
19
20class NotificationSource;
21class NotificationDetails;
22
23namespace browser_sync {
24
25class DataTypeController;
26class SyncBackendHost;
27
28class DataTypeManagerImpl : public DataTypeManager,
29                            public NotificationObserver {
30 public:
31  DataTypeManagerImpl(SyncBackendHost* backend,
32                      const DataTypeController::TypeMap& controllers);
33  virtual ~DataTypeManagerImpl();
34
35  // DataTypeManager interface.
36  virtual void Configure(const TypeSet& desired_types);
37
38  virtual void Stop();
39
40  virtual const DataTypeController::TypeMap& controllers() {
41    return controllers_;
42  };
43
44  virtual State state() {
45    return state_;
46  }
47
48  // NotificationObserver implementation.
49  virtual void Observe(NotificationType type,
50                       const NotificationSource& source,
51                       const NotificationDetails& details);
52
53 private:
54  // Starts the next data type in the kStartOrder list, indicated by
55  // the current_type_ member.  If there are no more data types to
56  // start, the stashed start_callback_ is invoked.
57  void StartNextType();
58
59  // Callback passed to each data type controller on startup.
60  void TypeStartCallback(DataTypeController::StartResult result);
61
62  // Stops all data types.
63  void FinishStop();
64  void FinishStopAndNotify(ConfigureResult result);
65
66  void Restart();
67  void DownloadReady();
68  void AddObserver(NotificationType type);
69  void RemoveObserver(NotificationType type);
70  void NotifyStart();
71  void NotifyDone(ConfigureResult result);
72  void ResumeSyncer();
73  void PauseSyncer();
74
75  SyncBackendHost* backend_;
76  // Map of all data type controllers that are available for sync.
77  // This list is determined at startup by various command line flags.
78  const DataTypeController::TypeMap controllers_;
79  State state_;
80  DataTypeController* current_dtc_;
81  std::map<syncable::ModelType, int> start_order_;
82  TypeSet last_requested_types_;
83  std::vector<DataTypeController*> needs_start_;
84  std::vector<DataTypeController*> needs_stop_;
85
86  NotificationRegistrar notification_registrar_;
87  ScopedRunnableMethodFactory<DataTypeManagerImpl> method_factory_;
88
89  DISALLOW_COPY_AND_ASSIGN(DataTypeManagerImpl);
90};
91
92}  // namespace browser_sync
93
94#endif  // CHROME_BROWSER_SYNC_GLUE_DATA_TYPE_MANAGER_IMPL_H__
95