Codebase list mozc / 152e571
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
11 changed file(s) with 58 addition(s) and 61 deletion(s). Raw diff Collapse all Expand all
00 MAJOR=2
11 MINOR=18
2 BUILD=2564
2 BUILD=2565
33 REVISION=102
44 # CAUTION: NACL_DICTIONARY_VERSION is going to be migrated to ENGINE_VERSION.
55 # NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
8585 bool ClearUnusedUserPrediction() override;
8686 bool ClearUserPredictionEntry(
8787 const string &key, const string &value) override;
88 bool WaitForSyncerForTest() override;
88 bool Wait() override;
8989
9090 private:
9191 PredictorInterface *predictor_;
128128 return predictor_->ClearHistoryEntry(key, value);
129129 }
130130
131 bool UserDataManagerImpl::WaitForSyncerForTest() {
132 return predictor_->WaitForSyncerForTest();
131 bool UserDataManagerImpl::Wait() {
132 return predictor_->Wait();
133133 }
134134
135135 } // namespace
3939
4040 class UserDataManagerInterface {
4141 public:
42 virtual ~UserDataManagerInterface() {}
42 virtual ~UserDataManagerInterface() = default;
4343
4444 // Syncs mutable user data to local file system.
4545 virtual bool Sync() = 0;
6161 const string &key, const string &value) = 0;
6262
6363 // 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;
6865 };
6966
7067 } // namespace mozc
6767 return true;
6868 }
6969
70 bool UserDataManagerMock::WaitForSyncerForTest() {
71 function_counters_["WaitForSyncer"]++;
70 bool UserDataManagerMock::Wait() {
71 function_counters_["Wait"]++;
7272 return true;
7373 }
7474
4343 class UserDataManagerMock : public UserDataManagerInterface {
4444 public:
4545 UserDataManagerMock();
46 virtual ~UserDataManagerMock();
46 ~UserDataManagerMock() override;
4747
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;
5556
5657 int GetFunctionCallCount(const string &name);
5758
117117 return user_history_predictor_->ClearHistoryEntry(key, value);
118118 }
119119
120 bool BasePredictor::WaitForSyncerForTest() {
121 return user_history_predictor_->WaitForSyncerForTest();
120 bool BasePredictor::Wait() {
121 return user_history_predictor_->Wait();
122122 }
123123
124124 bool BasePredictor::Sync() {
4444 // instance.
4545 BasePredictor(PredictorInterface *dictionary_predictor,
4646 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;
5248
5349 // Hook(s) for all mutable operations.
54 virtual void Finish(const ConversionRequest &request, Segments *segments);
50 void Finish(const ConversionRequest &request, Segments *segments) override;
5551
5652 // Reverts the last Finish operation.
57 virtual void Revert(Segments *segments);
53 void Revert(Segments *segments) override;
5854
5955 // Clears all history data of UserHistoryPredictor.
60 virtual bool ClearAllHistory();
56 bool ClearAllHistory() override;
6157
6258 // Clears unused history data of UserHistoryPredictor.
63 virtual bool ClearUnusedHistory();
59 bool ClearUnusedHistory() override;
6460
6561 // 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;
6763
6864 // Syncs user history.
69 virtual bool Sync();
65 bool Sync() override;
7066
7167 // Reloads usre history.
72 virtual bool Reload();
68 bool Reload() override;
7369
7470 // Waits for syncer to complete.
75 virtual bool WaitForSyncerForTest();
71 bool Wait() override;
7672
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;
7877
7978 protected:
8079 std::unique_ptr<PredictorInterface> dictionary_predictor_;
9089
9190 DefaultPredictor(PredictorInterface *dictionary_predictor,
9291 PredictorInterface *user_history_predictor);
93 virtual ~DefaultPredictor();
92 ~DefaultPredictor() override;
9493
95 virtual bool PredictForRequest(const ConversionRequest &request,
96 Segments *segments) const;
94 bool PredictForRequest(const ConversionRequest &request,
95 Segments *segments) const override;
9796
98 virtual const string &GetPredictorName() const { return predictor_name_; }
97 const string &GetPredictorName() const override { return predictor_name_; }
9998
10099 private:
101100 const ConversionRequest empty_request_;
110109
111110 MobilePredictor(PredictorInterface *dictionary_predictor,
112111 PredictorInterface *user_history_predictor);
113 virtual ~MobilePredictor();
112 ~MobilePredictor() override;
114113
115 virtual bool PredictForRequest(const ConversionRequest &request,
116 Segments *segments) const;
114 bool PredictForRequest(const ConversionRequest &request,
115 Segments *segments) const override;
117116
118 virtual const string &GetPredictorName() const { return predictor_name_; }
117 const string &GetPredictorName() const override { return predictor_name_; }
119118
120119 private:
121120 const ConversionRequest empty_request_;
3838
3939 class PredictorInterface {
4040 public:
41 virtual ~PredictorInterface() {}
41 virtual ~PredictorInterface() = default;
4242
4343 // Returns suggestions.
4444 // You may need to change the behavior according to the
7272 virtual bool Reload() { return true; }
7373
7474 // Waits for syncer thread to complete.
75 virtual bool WaitForSyncerForTest() { return true; }
75 virtual bool Wait() { return true; }
7676
7777 virtual const string &GetPredictorName() const = 0;
7878
7979 protected:
8080 // Disable the construction.
81 PredictorInterface() {}
81 PredictorInterface() = default;
8282 };
8383
8484 } // namespace mozc
434434 }
435435 }
436436
437 bool UserHistoryPredictor::WaitForSyncerForTest() {
437 bool UserHistoryPredictor::Wait() {
438438 WaitForSyncer();
439439 return true;
440440 }
8787 const dictionary::POSMatcher *pos_matcher,
8888 const dictionary::SuppressionDictionary *suppression_dictionary,
8989 bool enable_content_word_learning);
90 virtual ~UserHistoryPredictor();
90 ~UserHistoryPredictor() override;
9191
9292 void set_content_word_learning_enabled(bool value) {
9393 content_word_learning_enabled_ = value;
9494 }
9595
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;
9999
100100 // Hook(s) for all mutable operations.
101 virtual void Finish(const ConversionRequest &request, Segments *segments);
101 void Finish(const ConversionRequest &request, Segments *segments) override;
102102
103103 // Revert last Finish operation.
104 virtual void Revert(Segments *segments);
104 void Revert(Segments *segments) override;
105105
106106 // Sync user history data to local file.
107107 // You can call either Save() or AsyncSave().
108 virtual bool Sync();
108 bool Sync() override;
109109
110110 // Reloads from local disk.
111111 // Do not call Sync() before Reload().
112 virtual bool Reload();
112 bool Reload() override;
113113
114114 // Clears LRU data.
115 virtual bool ClearAllHistory();
115 bool ClearAllHistory() override;
116116
117117 // Clears unused data.
118 virtual bool ClearUnusedHistory();
118 bool ClearUnusedHistory() override;
119119
120120 // 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;
122122
123123 // Implements PredictorInterface.
124 virtual bool WaitForSyncerForTest();
124 bool Wait() override;
125125
126126 // Gets user history filename.
127127 static string GetUserHistoryFileName();
128128
129 virtual const string &GetPredictorName() const { return predictor_name_; }
129 const string &GetPredictorName() const override { return predictor_name_; }
130130
131131 // From user_history_predictor.proto
132132 typedef user_history_predictor::UserHistory::Entry Entry;
120120 }
121121
122122 void SyncDataToStorage() {
123 EXPECT_TRUE(engine_->GetUserDataManager()->WaitForSyncerForTest());
123 EXPECT_TRUE(engine_->GetUserDataManager()->Wait());
124124 }
125125
126126 void ClearUserPrediction() {