Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(914)

Side by Side Diff: components/sync/api/mock_model_type_store.h

Issue 2401223002: [Sync] Renaming sync/api* to sync/model*. (Closed)
Patch Set: Missed a comment in a DEPS file, and rebasing. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 COMPONENTS_SYNC_API_MOCK_MODEL_TYPE_STORE_H_
6 #define COMPONENTS_SYNC_API_MOCK_MODEL_TYPE_STORE_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/callback.h"
12 #include "components/sync/api/model_type_store.h"
13
14 namespace syncer {
15
16 // MockModelTypeStore is implementation of ModelTypeStore that does nothing.
17 // Use it when testing components that depend on ModelTypeStore.
18 //
19 // By default all methods return SUCCESS and empty results. It is possible to
20 // register custom handlers for certain functions to override behavior. It is
21 // responsibility of handler to post callback with result.
22 // Here is an example:
23 // ===
24 // void OnReadData(const ModelTypeStore::IdList& id_list,
25 // const ModelTypeStore::ReadAllDataCallback& callback) {
26 // // Verify id_list here.
27 // // Prepare fake response.
28 // std::unique_ptr<ModelTypeStore::RecordList> record_list(
29 // new ModelTypeStore::RecordList);
30 // record_list->push_back(ModelTypeStore::Record("id1", "value1"));
31 // base::ThreadTaskRunnerHandle::Get()->PostTask(
32 // FROM_HERE, base::Bind(callback, Result::SUCCESS,
33 // base::Passed(record_list)));
34 // }
35 //
36 // MockModelTypeStore mock_model_type_store;
37 // mock_model_type_store.RegisterReadDataHandler(base::Bind(&OnReadData));
38 // ModelTypeStore::IdList id_list;
39 // id_list.push_back("id1");
40 // mock_model_type_store.ReadData(id_list, base::Bind(&ReadDone));
41 // ===
42 // TODO(pavel): When in-memory store is available this class should delegate all
43 // calls to it instead of returning empty successful results.
44 class MockModelTypeStore : public ModelTypeStore {
45 public:
46 // Signatures for all ModelTypeStore virtual functions.
47 typedef base::Callback<void(const ReadAllDataCallback&)> ReadAllDataSignature;
48 typedef base::Callback<void(const IdList&, const ReadDataCallback&)>
49 ReadDataSignature;
50 typedef base::Callback<void(const ReadMetadataCallback& callback)>
51 ReadAllMetadataSignature;
52 typedef base::Callback<void(std::unique_ptr<WriteBatch>, CallbackWithResult)>
53 CommitWriteBatchSignature;
54 typedef base::Callback<
55 void(WriteBatch*, const std::string&, const std::string&)>
56 WriteRecordSignature;
57 typedef base::Callback<void(WriteBatch*, const std::string&)>
58 WriteGlobalMetadataSignature;
59 typedef base::Callback<void(WriteBatch*, const std::string&)>
60 DeleteRecordSignature;
61 typedef base::Callback<void(WriteBatch*)> DeleteGlobalMetadataSignature;
62
63 MockModelTypeStore();
64 ~MockModelTypeStore() override;
65
66 // ModelTypeStore implementation.
67 void ReadData(const IdList& id_list,
68 const ReadDataCallback& callback) override;
69 void ReadAllData(const ReadAllDataCallback& callback) override;
70 void ReadAllMetadata(const ReadMetadataCallback& callback) override;
71
72 std::unique_ptr<WriteBatch> CreateWriteBatch() override;
73 void CommitWriteBatch(std::unique_ptr<WriteBatch> write_batch,
74 const CallbackWithResult& callback) override;
75
76 void WriteData(WriteBatch* write_batch,
77 const std::string& id,
78 const std::string& value) override;
79 void WriteMetadata(WriteBatch* write_batch,
80 const std::string& id,
81 const std::string& value) override;
82 void WriteGlobalMetadata(WriteBatch* write_batch,
83 const std::string& value) override;
84 void DeleteData(WriteBatch* write_batch, const std::string& id) override;
85 void DeleteMetadata(WriteBatch* write_batch, const std::string& id) override;
86 void DeleteGlobalMetadata(WriteBatch* write_batch) override;
87
88 // Register handler functions.
89 void RegisterReadDataHandler(const ReadDataSignature& handler);
90 void RegisterReadAllDataHandler(const ReadAllDataSignature& handler);
91 void RegisterReadAllMetadataHandler(const ReadAllMetadataSignature& handler);
92 void RegisterCommitWriteBatchHandler(
93 const CommitWriteBatchSignature& handler);
94 void RegisterWriteDataHandler(const WriteRecordSignature& handler);
95 void RegisterWriteMetadataHandler(const WriteRecordSignature& handler);
96 void RegisterWriteGlobalMetadataHandler(
97 const WriteGlobalMetadataSignature& handler);
98 void RegisterDeleteDataHandler(const DeleteRecordSignature& handler);
99 void RegisterDeleteMetadataHandler(const DeleteRecordSignature& handler);
100 void RegisterDeleteGlobalMetadataHandler(
101 const DeleteGlobalMetadataSignature& handler);
102
103 private:
104 ReadDataSignature read_data_handler_;
105 ReadAllDataSignature read_all_data_handler_;
106 ReadAllMetadataSignature read_all_metadata_handler_;
107 CommitWriteBatchSignature commit_write_batch_handler_;
108 WriteRecordSignature write_data_handler_;
109 WriteRecordSignature write_metadata_handler_;
110 WriteGlobalMetadataSignature write_global_metadata_handler_;
111 DeleteRecordSignature delete_data_handler_;
112 DeleteRecordSignature delete_metadata_handler_;
113 DeleteGlobalMetadataSignature delete_global_metadata_handler_;
114 };
115
116 } // namespace syncer
117
118 #endif // COMPONENTS_SYNC_API_MOCK_MODEL_TYPE_STORE_H_
OLDNEW
« no previous file with comments | « components/sync/api/metadata_change_list.h ('k') | components/sync/api/mock_model_type_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698