| 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_SPELLCHECKER_SPELLING_SERVICE_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_SPELLCHECKER_SPELLING_SERVICE_CLIENT_H_ |
| 6 #define CHROME_BROWSER_SPELLCHECKER_SPELLING_SERVICE_CLIENT_H_ | 6 #define CHROME_BROWSER_SPELLCHECKER_SPELLING_SERVICE_CLIENT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // consists of a couple of backends: | 59 // consists of a couple of backends: |
| 60 // * SUGGEST: Retrieving suggestions for a word (used by Google Search), and; | 60 // * SUGGEST: Retrieving suggestions for a word (used by Google Search), and; |
| 61 // * SPELLCHECK: Spellchecking text (used by Google Docs). | 61 // * SPELLCHECK: Spellchecking text (used by Google Docs). |
| 62 // This type is used for choosing a backend when sending a JSON-RPC request to | 62 // This type is used for choosing a backend when sending a JSON-RPC request to |
| 63 // the service. | 63 // the service. |
| 64 enum ServiceType { | 64 enum ServiceType { |
| 65 SUGGEST = 1, | 65 SUGGEST = 1, |
| 66 SPELLCHECK = 2, | 66 SPELLCHECK = 2, |
| 67 }; | 67 }; |
| 68 typedef base::Callback<void( | 68 typedef base::Callback<void( |
| 69 int /* tag */, | |
| 70 bool /* success */, | 69 bool /* success */, |
| 71 const string16& /* text */, | 70 const string16& /* text */, |
| 72 const std::vector<SpellCheckResult>& /* results */)> | 71 const std::vector<SpellCheckResult>& /* results */)> |
| 73 TextCheckCompleteCallback; | 72 TextCheckCompleteCallback; |
| 74 | 73 |
| 75 SpellingServiceClient(); | 74 SpellingServiceClient(); |
| 76 virtual ~SpellingServiceClient(); | 75 virtual ~SpellingServiceClient(); |
| 77 | 76 |
| 78 // net::URLFetcherDelegate implementation. | 77 // net::URLFetcherDelegate implementation. |
| 79 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 78 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 80 | 79 |
| 81 // Sends a text-check request to the Spelling service. When we send a request | 80 // Sends a text-check request to the Spelling service. When we send a request |
| 82 // to the Spelling service successfully, this function returns true. (This | 81 // to the Spelling service successfully, this function returns true. (This |
| 83 // does not mean the service finishes checking text successfully.) We will | 82 // does not mean the service finishes checking text successfully.) We will |
| 84 // call |callback| when we receive a text-check response from the service. | 83 // call |callback| when we receive a text-check response from the service. |
| 85 bool RequestTextCheck(Profile* profile, | 84 bool RequestTextCheck(Profile* profile, |
| 86 int tag, | |
| 87 ServiceType type, | 85 ServiceType type, |
| 88 const string16& text, | 86 const string16& text, |
| 89 const TextCheckCompleteCallback& callback); | 87 const TextCheckCompleteCallback& callback); |
| 90 | 88 |
| 91 // Returns whether the specified service is available for the given profile. | 89 // Returns whether the specified service is available for the given profile. |
| 92 static bool IsAvailable(Profile* profile, ServiceType type); | 90 static bool IsAvailable(Profile* profile, ServiceType type); |
| 93 | 91 |
| 94 private: | 92 private: |
| 95 // Creates a URLFetcher object used for sending a JSON-RPC request. This | 93 // Creates a URLFetcher object used for sending a JSON-RPC request. This |
| 96 // function is overriden by unit tests to prevent them from actually sending | 94 // function is overriden by unit tests to prevent them from actually sending |
| 97 // requests to the Spelling service. | 95 // requests to the Spelling service. |
| 98 virtual net::URLFetcher* CreateURLFetcher(const GURL& url); | 96 virtual net::URLFetcher* CreateURLFetcher(const GURL& url); |
| 99 | 97 |
| 100 // Parses a JSON-RPC response from the Spelling service. | 98 // Parses a JSON-RPC response from the Spelling service. |
| 101 bool ParseResponse(const std::string& data, | 99 bool ParseResponse(const std::string& data, |
| 102 std::vector<SpellCheckResult>* results); | 100 std::vector<SpellCheckResult>* results); |
| 103 | 101 |
| 104 // The URLFetcher object used for sending a JSON-RPC request. | 102 // The URLFetcher object used for sending a JSON-RPC request. |
| 105 scoped_ptr<net::URLFetcher> fetcher_; | 103 scoped_ptr<net::URLFetcher> fetcher_; |
| 106 | 104 |
| 107 // The callback function to be called when we receive a response from the | 105 // The callback function to be called when we receive a response from the |
| 108 // Spelling service and parse it. | 106 // Spelling service and parse it. |
| 109 TextCheckCompleteCallback callback_; | 107 TextCheckCompleteCallback callback_; |
| 110 | 108 |
| 111 // The text checked by the Spelling service. | 109 // The text checked by the Spelling service. |
| 112 string16 text_; | 110 string16 text_; |
| 113 | |
| 114 // The identifier provided by users so they can identify a text-check request. | |
| 115 // When a JSON-RPC call finishes successfully, this value is used as the | |
| 116 // first parameter to |callback_|. | |
| 117 int tag_; | |
| 118 }; | 111 }; |
| 119 | 112 |
| 120 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLING_SERVICE_CLIENT_H_ | 113 #endif // CHROME_BROWSER_SPELLCHECKER_SPELLING_SERVICE_CLIENT_H_ |
| OLD | NEW |