| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // An object to record and send user feedback to spelling service. The spelling | 5 // An object to record and send user feedback to spelling service. The spelling |
| 6 // service uses the feedback to improve its suggestions. | 6 // service uses the feedback to improve its suggestions. |
| 7 // | 7 // |
| 8 // Assigns uint32 hash identifiers to spelling suggestions from spelling service | 8 // Assigns uint32 hash identifiers to spelling suggestions from spelling service |
| 9 // and stores these suggestions. Records user's actions on these suggestions. | 9 // and stores these suggestions. Records user's actions on these suggestions. |
| 10 // Periodically sends batches of user feedback to the spelling service. | 10 // Periodically sends batches of user feedback to the spelling service. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 void OnSpellcheckResults(int renderer_process_id, | 96 void OnSpellcheckResults(int renderer_process_id, |
| 97 const string16& text, | 97 const string16& text, |
| 98 const std::vector<SpellCheckMarker>& markers, | 98 const std::vector<SpellCheckMarker>& markers, |
| 99 std::vector<SpellCheckResult>* results); | 99 std::vector<SpellCheckResult>* results); |
| 100 | 100 |
| 101 // Receives updated language and country code for feedback. Finalizes and | 101 // Receives updated language and country code for feedback. Finalizes and |
| 102 // sends out all of the feedback data. | 102 // sends out all of the feedback data. |
| 103 void OnLanguageCountryChange(const std::string& language, | 103 void OnLanguageCountryChange(const std::string& language, |
| 104 const std::string& country); | 104 const std::string& country); |
| 105 | 105 |
| 106 // Starts collecting feedback, if it's not already being collected. |
| 107 void StartFeedbackCollection(); |
| 108 |
| 109 // Sends out all previously collected data and stops collecting feedback, if |
| 110 // it was being collected. |
| 111 void StopFeedbackCollection(); |
| 112 |
| 106 private: | 113 private: |
| 107 friend class FeedbackSenderTest; | 114 friend class FeedbackSenderTest; |
| 108 | 115 |
| 109 // net::URLFetcherDelegate implementation. Takes ownership of |source|. | 116 // net::URLFetcherDelegate implementation. Takes ownership of |source|. |
| 110 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 117 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 111 | 118 |
| 112 // Requests the document markers from all of the renderers to determine which | 119 // Requests the document markers from all of the renderers to determine which |
| 113 // feedback can be finalized. Finalizes feedback for renderers that are gone. | 120 // feedback can be finalized. Finalizes feedback for renderers that are gone. |
| 114 // Called periodically when |timer_| fires. | 121 // Called periodically when |timer_| fires. |
| 115 void RequestDocumentMarkers(); | 122 void RequestDocumentMarkers(); |
| 116 | 123 |
| 117 // Sends out all feedback data. Resets the session-start timestamp to now. | 124 // Sends out all feedback data. Resets the session-start timestamp to now. |
| 118 // Restarts the timer that requests markers from the renderers. | 125 // Restarts the timer that requests markers from the renderers. |
| 119 void FlushFeedback(); | 126 void FlushFeedback(); |
| 120 | 127 |
| 121 // Sends out the |feedback_data|. | 128 // Sends out the |feedback_data|. |
| 122 void SendFeedback(const std::vector<Misspelling>& feedback_data, | 129 void SendFeedback(const std::vector<Misspelling>& feedback_data, |
| 123 bool is_first_feedback_batch); | 130 bool is_first_feedback_batch); |
| 124 | 131 |
| 125 // URL request context for the feedback senders. | 132 // URL request context for the feedback senders. |
| 126 scoped_refptr<net::URLRequestContextGetter> request_context_; | 133 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 127 | 134 |
| 135 // The feedback API version. |
| 136 const std::string api_version_; |
| 137 |
| 128 // The language of text. The string is a BCP 47 language tag. | 138 // The language of text. The string is a BCP 47 language tag. |
| 129 std::string language_; | 139 std::string language_; |
| 130 | 140 |
| 131 // The country of origin. The string is the ISO 3166-1 alpha-3 code. | 141 // The country of origin. The string is the ISO 3166-1 alpha-3 code. |
| 132 std::string country_; | 142 std::string country_; |
| 133 | 143 |
| 134 // Misspelling counter used to generate unique hash identifier for each | 144 // Misspelling counter used to generate unique hash identifier for each |
| 135 // misspelling. | 145 // misspelling. |
| 136 size_t misspelling_counter_; | 146 size_t misspelling_counter_; |
| 137 | 147 |
| 138 // Feedback data. | 148 // Feedback data. |
| 139 Feedback feedback_; | 149 Feedback feedback_; |
| 140 | 150 |
| 141 // A set of renderer process IDs for renderers that have sent out feedback in | 151 // A set of renderer process IDs for renderers that have sent out feedback in |
| 142 // this session. | 152 // this session. |
| 143 std::set<int> renderers_sent_feedback_; | 153 std::set<int> renderers_sent_feedback_; |
| 144 | 154 |
| 145 // When the session started. | 155 // When the session started. |
| 146 base::Time session_start_; | 156 base::Time session_start_; |
| 147 | 157 |
| 148 // The URL where the feedback data should be sent. | 158 // The URL where the feedback data should be sent. |
| 149 GURL feedback_service_url_; | 159 GURL feedback_service_url_; |
| 150 | 160 |
| 151 // A timer to periodically request a list of document spelling markers from | 161 // A timer to periodically request a list of document spelling markers from |
| 152 // all of the renderers. The timer runs while an instance of this class is | 162 // all of the renderers. The timer starts in StartFeedbackCollection() and |
| 153 // alive. | 163 // stops in StopFeedbackCollection(). The timer stops and abandons its tasks |
| 164 // on destruction. |
| 154 base::RepeatingTimer<FeedbackSender> timer_; | 165 base::RepeatingTimer<FeedbackSender> timer_; |
| 155 | 166 |
| 156 // Feedback senders that need to stay alive for the duration of sending data. | 167 // Feedback senders that need to stay alive for the duration of sending data. |
| 157 // If a sender is destroyed before it finishes, then sending feedback will be | 168 // If a sender is destroyed before it finishes, then sending feedback will be |
| 158 // canceled. | 169 // canceled. |
| 159 ScopedVector<net::URLFetcher> senders_; | 170 ScopedVector<net::URLFetcher> senders_; |
| 160 | 171 |
| 161 DISALLOW_COPY_AND_ASSIGN(FeedbackSender); | 172 DISALLOW_COPY_AND_ASSIGN(FeedbackSender); |
| 162 }; | 173 }; |
| 163 | 174 |
| 164 } // namespace spellcheck | 175 } // namespace spellcheck |
| 165 | 176 |
| 166 #endif // CHROME_BROWSER_SPELLCHECKER_FEEDBACK_SENDER_H_ | 177 #endif // CHROME_BROWSER_SPELLCHECKER_FEEDBACK_SENDER_H_ |
| OLD | NEW |