1// Copyright (c) 2011 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_H__
6#define CHROME_BROWSER_SYNC_GLUE_DATA_TYPE_MANAGER_H__
7#pragma once
8
9#include <set>
10
11#include "base/memory/scoped_ptr.h"
12#include "base/task.h"
13#include "chrome/browser/sync/glue/data_type_controller.h"
14#include "chrome/browser/sync/syncable/model_type.h"
15
16namespace browser_sync {
17
18// This interface is for managing the start up and shut down life cycle
19// of many different syncable data types.
20class DataTypeManager {
21 public:
22  enum State {
23    STOPPED,           // No data types are currently running.
24    DOWNLOAD_PENDING,  // Not implemented yet: Waiting for the syncer to
25                       // complete the initial download of new data
26                       // types.
27
28    CONFIGURING,       // Data types are being started.
29    BLOCKED,           // We can't move forward with configuration because some
30                       // external action must take place (i.e. passphrase).
31
32    CONFIGURED,        // All enabled data types are running.
33    STOPPING           // Data types are being stopped.
34  };
35
36  enum ConfigureResult {
37    OK,                  // Configuration finished without error.
38    ASSOCIATION_FAILED,  // An error occurred during model association.
39    ABORTED,             // Start was aborted by calling Stop() before
40                         // all types were started.
41    UNRECOVERABLE_ERROR  // A data type experienced an unrecoverable error
42                         // during startup.
43  };
44
45  typedef std::set<syncable::ModelType> TypeSet;
46
47  // In case of an error the location is filled with the location the
48  // error originated from. In case of a success the error location value
49  // is to be not used.
50  // TODO(tim): We should rename this / ConfigureResult to something more
51  // flexible like SyncConfigureDoneDetails.
52  struct ConfigureResultWithErrorLocation {
53    ConfigureResult result;
54    TypeSet requested_types;
55    scoped_ptr<tracked_objects::Location> location;
56
57    ConfigureResultWithErrorLocation();
58    ConfigureResultWithErrorLocation(const ConfigureResult& result,
59        const tracked_objects::Location& location,
60        const TypeSet& requested_types)
61        : result(result),
62          requested_types(requested_types) {
63      this->location.reset(new tracked_objects::Location(
64          location.function_name(),
65          location.file_name(),
66          location.line_number()));
67    }
68
69      ~ConfigureResultWithErrorLocation();
70  };
71
72
73  virtual ~DataTypeManager() {}
74
75  // Begins asynchronous configuration of data types.  Any currently
76  // running data types that are not in the desired_types set will be
77  // stopped.  Any stopped data types that are in the desired_types
78  // set will be started.  All other data types are left in their
79  // current state.  A SYNC_CONFIGURE_START notification will be sent
80  // to the UI thread when configuration is started and a
81  // SYNC_CONFIGURE_DONE notification will be sent (with a
82  // ConfigureResult detail) when configuration is complete.
83  //
84  // Note that you may call Configure() while configuration is in
85  // progress.  Configuration will be complete only when the
86  // desired_types supplied in the last call to Configure is achieved.
87  virtual void Configure(const TypeSet& desired_types) = 0;
88
89  // Synchronously stops all registered data types.  If called after
90  // Configure() is called but before it finishes, it will abort the
91  // configure and any data types that have been started will be
92  // stopped.
93  virtual void Stop() = 0;
94
95  // Reference to map of data type controllers.
96  virtual const DataTypeController::TypeMap& controllers() = 0;
97
98  // The current state of the data type manager.
99  virtual State state() = 0;
100};
101
102}  // namespace browser_sync
103
104#endif  // CHROME_BROWSER_SYNC_GLUE_DATA_TYPE_MANAGER_H__
105