Rename WaitForSyncerForTest to Wait
Wait is currently used not only in tests but also in applications.
BUG=
TEST=
REF_BUG=26841123
REF_CL=122016336
REF_TIME=2016-05-11T12:01:55+09:00
REF_TIME_RAW=1462935715 +0900
Noriyuki Takahashi
7 years ago
0 | 0 | MAJOR=2 |
1 | 1 | MINOR=18 |
2 | BUILD=2564 | |
2 | BUILD=2565 | |
3 | 3 | REVISION=102 |
4 | 4 | # CAUTION: NACL_DICTIONARY_VERSION is going to be migrated to ENGINE_VERSION. |
5 | 5 | # NACL_DICTIONARY_VERSION is the target version of the system dictionary to be |
85 | 85 | bool ClearUnusedUserPrediction() override; |
86 | 86 | bool ClearUserPredictionEntry( |
87 | 87 | const string &key, const string &value) override; |
88 | bool WaitForSyncerForTest() override; | |
88 | bool Wait() override; | |
89 | 89 | |
90 | 90 | private: |
91 | 91 | PredictorInterface *predictor_; |
128 | 128 | return predictor_->ClearHistoryEntry(key, value); |
129 | 129 | } |
130 | 130 | |
131 | bool UserDataManagerImpl::WaitForSyncerForTest() { | |
132 | return predictor_->WaitForSyncerForTest(); | |
131 | bool UserDataManagerImpl::Wait() { | |
132 | return predictor_->Wait(); | |
133 | 133 | } |
134 | 134 | |
135 | 135 | } // namespace |
39 | 39 | |
40 | 40 | class UserDataManagerInterface { |
41 | 41 | public: |
42 | virtual ~UserDataManagerInterface() {} | |
42 | virtual ~UserDataManagerInterface() = default; | |
43 | 43 | |
44 | 44 | // Syncs mutable user data to local file system. |
45 | 45 | virtual bool Sync() = 0; |
61 | 61 | const string &key, const string &value) = 0; |
62 | 62 | |
63 | 63 | // Waits for syncer thread to complete. |
64 | virtual bool WaitForSyncerForTest() = 0; | |
65 | ||
66 | // TODO(noriyukit): Rename WaitForSyncerForTest() to Wait(). | |
67 | bool Wait() { return WaitForSyncerForTest(); } | |
64 | virtual bool Wait() = 0; | |
68 | 65 | }; |
69 | 66 | |
70 | 67 | } // namespace mozc |
67 | 67 | return true; |
68 | 68 | } |
69 | 69 | |
70 | bool UserDataManagerMock::WaitForSyncerForTest() { | |
71 | function_counters_["WaitForSyncer"]++; | |
70 | bool UserDataManagerMock::Wait() { | |
71 | function_counters_["Wait"]++; | |
72 | 72 | return true; |
73 | 73 | } |
74 | 74 |
43 | 43 | class UserDataManagerMock : public UserDataManagerInterface { |
44 | 44 | public: |
45 | 45 | UserDataManagerMock(); |
46 | virtual ~UserDataManagerMock(); | |
46 | ~UserDataManagerMock() override; | |
47 | 47 | |
48 | virtual bool Sync(); | |
49 | virtual bool Reload(); | |
50 | virtual bool ClearUserHistory(); | |
51 | virtual bool ClearUserPrediction(); | |
52 | virtual bool ClearUnusedUserPrediction(); | |
53 | virtual bool ClearUserPredictionEntry(const string &key, const string &value); | |
54 | virtual bool WaitForSyncerForTest(); | |
48 | bool Sync() override; | |
49 | bool Reload() override; | |
50 | bool ClearUserHistory() override; | |
51 | bool ClearUserPrediction() override; | |
52 | bool ClearUnusedUserPrediction() override; | |
53 | bool ClearUserPredictionEntry(const string &key, | |
54 | const string &value) override; | |
55 | bool Wait() override; | |
55 | 56 | |
56 | 57 | int GetFunctionCallCount(const string &name); |
57 | 58 |
117 | 117 | return user_history_predictor_->ClearHistoryEntry(key, value); |
118 | 118 | } |
119 | 119 | |
120 | bool BasePredictor::WaitForSyncerForTest() { | |
121 | return user_history_predictor_->WaitForSyncerForTest(); | |
120 | bool BasePredictor::Wait() { | |
121 | return user_history_predictor_->Wait(); | |
122 | 122 | } |
123 | 123 | |
124 | 124 | bool BasePredictor::Sync() { |
44 | 44 | // instance. |
45 | 45 | BasePredictor(PredictorInterface *dictionary_predictor, |
46 | 46 | PredictorInterface *user_history_predictor); |
47 | virtual ~BasePredictor(); | |
48 | ||
49 | // Overwrite predictor | |
50 | virtual bool PredictForRequest(const ConversionRequest &request, | |
51 | Segments *segments) const = 0; | |
47 | ~BasePredictor() override; | |
52 | 48 | |
53 | 49 | // Hook(s) for all mutable operations. |
54 | virtual void Finish(const ConversionRequest &request, Segments *segments); | |
50 | void Finish(const ConversionRequest &request, Segments *segments) override; | |
55 | 51 | |
56 | 52 | // Reverts the last Finish operation. |
57 | virtual void Revert(Segments *segments); | |
53 | void Revert(Segments *segments) override; | |
58 | 54 | |
59 | 55 | // Clears all history data of UserHistoryPredictor. |
60 | virtual bool ClearAllHistory(); | |
56 | bool ClearAllHistory() override; | |
61 | 57 | |
62 | 58 | // Clears unused history data of UserHistoryPredictor. |
63 | virtual bool ClearUnusedHistory(); | |
59 | bool ClearUnusedHistory() override; | |
64 | 60 | |
65 | 61 | // Clears a specific user history data of UserHistoryPredictor. |
66 | virtual bool ClearHistoryEntry(const string &key, const string &value); | |
62 | bool ClearHistoryEntry(const string &key, const string &value) override; | |
67 | 63 | |
68 | 64 | // Syncs user history. |
69 | virtual bool Sync(); | |
65 | bool Sync() override; | |
70 | 66 | |
71 | 67 | // Reloads usre history. |
72 | virtual bool Reload(); | |
68 | bool Reload() override; | |
73 | 69 | |
74 | 70 | // Waits for syncer to complete. |
75 | virtual bool WaitForSyncerForTest(); | |
71 | bool Wait() override; | |
76 | 72 | |
77 | virtual const string &GetPredictorName() const = 0; | |
73 | // The following interfaces are implemented in derived classes. | |
74 | // const string &GetPredictorName() const = 0; | |
75 | // bool PredictForRequest(const ConversionRequest &request, | |
76 | // Segments *segments) const = 0; | |
78 | 77 | |
79 | 78 | protected: |
80 | 79 | std::unique_ptr<PredictorInterface> dictionary_predictor_; |
90 | 89 | |
91 | 90 | DefaultPredictor(PredictorInterface *dictionary_predictor, |
92 | 91 | PredictorInterface *user_history_predictor); |
93 | virtual ~DefaultPredictor(); | |
92 | ~DefaultPredictor() override; | |
94 | 93 | |
95 | virtual bool PredictForRequest(const ConversionRequest &request, | |
96 | Segments *segments) const; | |
94 | bool PredictForRequest(const ConversionRequest &request, | |
95 | Segments *segments) const override; | |
97 | 96 | |
98 | virtual const string &GetPredictorName() const { return predictor_name_; } | |
97 | const string &GetPredictorName() const override { return predictor_name_; } | |
99 | 98 | |
100 | 99 | private: |
101 | 100 | const ConversionRequest empty_request_; |
110 | 109 | |
111 | 110 | MobilePredictor(PredictorInterface *dictionary_predictor, |
112 | 111 | PredictorInterface *user_history_predictor); |
113 | virtual ~MobilePredictor(); | |
112 | ~MobilePredictor() override; | |
114 | 113 | |
115 | virtual bool PredictForRequest(const ConversionRequest &request, | |
116 | Segments *segments) const; | |
114 | bool PredictForRequest(const ConversionRequest &request, | |
115 | Segments *segments) const override; | |
117 | 116 | |
118 | virtual const string &GetPredictorName() const { return predictor_name_; } | |
117 | const string &GetPredictorName() const override { return predictor_name_; } | |
119 | 118 | |
120 | 119 | private: |
121 | 120 | const ConversionRequest empty_request_; |
38 | 38 | |
39 | 39 | class PredictorInterface { |
40 | 40 | public: |
41 | virtual ~PredictorInterface() {} | |
41 | virtual ~PredictorInterface() = default; | |
42 | 42 | |
43 | 43 | // Returns suggestions. |
44 | 44 | // You may need to change the behavior according to the |
72 | 72 | virtual bool Reload() { return true; } |
73 | 73 | |
74 | 74 | // Waits for syncer thread to complete. |
75 | virtual bool WaitForSyncerForTest() { return true; } | |
75 | virtual bool Wait() { return true; } | |
76 | 76 | |
77 | 77 | virtual const string &GetPredictorName() const = 0; |
78 | 78 | |
79 | 79 | protected: |
80 | 80 | // Disable the construction. |
81 | PredictorInterface() {} | |
81 | PredictorInterface() = default; | |
82 | 82 | }; |
83 | 83 | |
84 | 84 | } // namespace mozc |
434 | 434 | } |
435 | 435 | } |
436 | 436 | |
437 | bool UserHistoryPredictor::WaitForSyncerForTest() { | |
437 | bool UserHistoryPredictor::Wait() { | |
438 | 438 | WaitForSyncer(); |
439 | 439 | return true; |
440 | 440 | } |
87 | 87 | const dictionary::POSMatcher *pos_matcher, |
88 | 88 | const dictionary::SuppressionDictionary *suppression_dictionary, |
89 | 89 | bool enable_content_word_learning); |
90 | virtual ~UserHistoryPredictor(); | |
90 | ~UserHistoryPredictor() override; | |
91 | 91 | |
92 | 92 | void set_content_word_learning_enabled(bool value) { |
93 | 93 | content_word_learning_enabled_ = value; |
94 | 94 | } |
95 | 95 | |
96 | virtual bool Predict(Segments *segments) const; | |
97 | virtual bool PredictForRequest(const ConversionRequest &request, | |
98 | Segments *segments) const; | |
96 | bool Predict(Segments *segments) const; | |
97 | bool PredictForRequest(const ConversionRequest &request, | |
98 | Segments *segments) const override; | |
99 | 99 | |
100 | 100 | // Hook(s) for all mutable operations. |
101 | virtual void Finish(const ConversionRequest &request, Segments *segments); | |
101 | void Finish(const ConversionRequest &request, Segments *segments) override; | |
102 | 102 | |
103 | 103 | // Revert last Finish operation. |
104 | virtual void Revert(Segments *segments); | |
104 | void Revert(Segments *segments) override; | |
105 | 105 | |
106 | 106 | // Sync user history data to local file. |
107 | 107 | // You can call either Save() or AsyncSave(). |
108 | virtual bool Sync(); | |
108 | bool Sync() override; | |
109 | 109 | |
110 | 110 | // Reloads from local disk. |
111 | 111 | // Do not call Sync() before Reload(). |
112 | virtual bool Reload(); | |
112 | bool Reload() override; | |
113 | 113 | |
114 | 114 | // Clears LRU data. |
115 | virtual bool ClearAllHistory(); | |
115 | bool ClearAllHistory() override; | |
116 | 116 | |
117 | 117 | // Clears unused data. |
118 | virtual bool ClearUnusedHistory(); | |
118 | bool ClearUnusedHistory() override; | |
119 | 119 | |
120 | 120 | // Clears a specific history entry. |
121 | virtual bool ClearHistoryEntry(const string &key, const string &value); | |
121 | bool ClearHistoryEntry(const string &key, const string &value) override; | |
122 | 122 | |
123 | 123 | // Implements PredictorInterface. |
124 | virtual bool WaitForSyncerForTest(); | |
124 | bool Wait() override; | |
125 | 125 | |
126 | 126 | // Gets user history filename. |
127 | 127 | static string GetUserHistoryFileName(); |
128 | 128 | |
129 | virtual const string &GetPredictorName() const { return predictor_name_; } | |
129 | const string &GetPredictorName() const override { return predictor_name_; } | |
130 | 130 | |
131 | 131 | // From user_history_predictor.proto |
132 | 132 | typedef user_history_predictor::UserHistory::Entry Entry; |