OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SYNC_API_SYNCABLE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_API_SYNCABLE_SERVICE_H_ |
6 #define CHROME_BROWSER_SYNC_API_SYNCABLE_SERVICE_H_ | 6 #define CHROME_BROWSER_SYNC_API_SYNCABLE_SERVICE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "chrome/browser/sync/api/sync_change_processor.h" | 14 #include "chrome/browser/sync/api/sync_change_processor.h" |
14 #include "chrome/browser/sync/api/sync_data.h" | 15 #include "chrome/browser/sync/api/sync_data.h" |
15 #include "chrome/browser/sync/api/sync_error.h" | 16 #include "chrome/browser/sync/api/sync_error.h" |
16 #include "sync/syncable/model_type.h" | 17 #include "sync/syncable/model_type.h" |
17 | 18 |
18 class SyncData; | 19 class SyncData; |
19 | 20 |
20 typedef std::vector<SyncData> SyncDataList; | 21 typedef std::vector<SyncData> SyncDataList; |
21 | 22 |
22 // TODO(zea): remove SupportsWeakPtr in favor of having all SyncableService | 23 // TODO(zea): remove SupportsWeakPtr in favor of having all SyncableService |
23 // implementers provide a way of getting a weak pointer to themselves. | 24 // implementers provide a way of getting a weak pointer to themselves. |
24 // See crbug.com/100114. | 25 // See crbug.com/100114. |
25 class SyncableService : public SyncChangeProcessor, | 26 class SyncableService : public SyncChangeProcessor, |
26 public base::SupportsWeakPtr<SyncableService> { | 27 public base::SupportsWeakPtr<SyncableService> { |
27 public: | 28 public: |
28 // Informs the service to begin syncing the specified synced datatype |type|. | 29 // Informs the service to begin syncing the specified synced datatype |type|. |
29 // The service should then merge |initial_sync_data| into it's local data, | 30 // The service should then merge |initial_sync_data| into it's local data, |
30 // calling |sync_processor|'s ProcessSyncChanges as necessary to reconcile the | 31 // calling |sync_processor|'s ProcessSyncChanges as necessary to reconcile the |
31 // two. After this, the SyncableService's local data should match the server | 32 // two. After this, the SyncableService's local data should match the server |
32 // data, and the service should be ready to receive and process any further | 33 // data, and the service should be ready to receive and process any further |
33 // SyncChange's as they occur. | 34 // SyncChange's as they occur. |
34 // Returns: A default SyncError (IsSet() == false) if no errors were | 35 // Returns: A default SyncError (IsSet() == false) if no errors were |
35 // encountered, and a filled SyncError (IsSet() == true) | 36 // encountered, and a filled SyncError (IsSet() == true) |
36 // otherwise. | 37 // otherwise. |
37 virtual SyncError MergeDataAndStartSyncing( | 38 virtual SyncError MergeDataAndStartSyncing( |
38 syncable::ModelType type, | 39 syncable::ModelType type, |
39 const SyncDataList& initial_sync_data, | 40 const SyncDataList& initial_sync_data, |
40 SyncChangeProcessor* sync_processor) = 0; | 41 scoped_ptr<SyncChangeProcessor> sync_processor) = 0; |
41 | 42 |
42 // Stop syncing the specified type and reset state. | 43 // Stop syncing the specified type and reset state. |
43 virtual void StopSyncing(syncable::ModelType type) = 0; | 44 virtual void StopSyncing(syncable::ModelType type) = 0; |
44 | 45 |
45 // Fills a list of SyncData from the local data. This should create an up | 46 // Fills a list of SyncData from the local data. This should create an up |
46 // to date representation of the SyncableService's view of that datatype, and | 47 // to date representation of the SyncableService's view of that datatype, and |
47 // should match/be a subset of the server's view of that datatype. | 48 // should match/be a subset of the server's view of that datatype. |
48 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const = 0; | 49 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const = 0; |
49 | 50 |
50 // SyncChangeProcessor interface. | 51 // SyncChangeProcessor interface. |
51 // Process a list of new SyncChanges and update the local data as necessary. | 52 // Process a list of new SyncChanges and update the local data as necessary. |
52 // Returns: A default SyncError (IsSet() == false) if no errors were | 53 // Returns: A default SyncError (IsSet() == false) if no errors were |
53 // encountered, and a filled SyncError (IsSet() == true) | 54 // encountered, and a filled SyncError (IsSet() == true) |
54 // otherwise. | 55 // otherwise. |
55 virtual SyncError ProcessSyncChanges( | 56 virtual SyncError ProcessSyncChanges( |
56 const tracked_objects::Location& from_here, | 57 const tracked_objects::Location& from_here, |
57 const SyncChangeList& change_list) OVERRIDE = 0; | 58 const SyncChangeList& change_list) OVERRIDE = 0; |
58 | 59 |
59 protected: | 60 protected: |
60 virtual ~SyncableService(); | 61 virtual ~SyncableService(); |
61 }; | 62 }; |
62 | 63 |
63 #endif // CHROME_BROWSER_SYNC_API_SYNCABLE_SERVICE_H_ | 64 #endif // CHROME_BROWSER_SYNC_API_SYNCABLE_SERVICE_H_ |
OLD | NEW |