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 COMPONENTS_SPELLCHECK_BROWSER_SPELLING_SERVICE_CLIENT_H_ | 5 #ifndef COMPONENTS_SPELLCHECK_BROWSER_SPELLING_SERVICE_CLIENT_H_ |
6 #define COMPONENTS_SPELLCHECK_BROWSER_SPELLING_SERVICE_CLIENT_H_ | 6 #define COMPONENTS_SPELLCHECK_BROWSER_SPELLING_SERVICE_CLIENT_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // Returns whether the specified service is available for the given context. | 90 // Returns whether the specified service is available for the given context. |
91 static bool IsAvailable(content::BrowserContext* context, ServiceType type); | 91 static bool IsAvailable(content::BrowserContext* context, ServiceType type); |
92 | 92 |
93 protected: | 93 protected: |
94 // Parses a JSON-RPC response from the Spelling service. | 94 // Parses a JSON-RPC response from the Spelling service. |
95 bool ParseResponse(const std::string& data, | 95 bool ParseResponse(const std::string& data, |
96 std::vector<SpellCheckResult>* results); | 96 std::vector<SpellCheckResult>* results); |
97 | 97 |
98 private: | 98 private: |
99 struct TextCheckCallbackData { | 99 struct TextCheckCallbackData { |
100 TextCheckCallbackData(TextCheckCompleteCallback callback, | 100 TextCheckCallbackData(std::unique_ptr<net::URLFetcher> fetcher, |
| 101 TextCheckCompleteCallback callback, |
101 base::string16 text); | 102 base::string16 text); |
102 ~TextCheckCallbackData(); | 103 ~TextCheckCallbackData(); |
103 | 104 |
| 105 // The fetcher used. |
| 106 std::unique_ptr<net::URLFetcher> fetcher; |
| 107 |
104 // The callback function to be called when we receive a response from the | 108 // The callback function to be called when we receive a response from the |
105 // Spelling service and parse it. | 109 // Spelling service and parse it. |
106 TextCheckCompleteCallback callback; | 110 TextCheckCompleteCallback callback; |
107 | 111 |
108 // The text checked by the Spelling service. | 112 // The text checked by the Spelling service. |
109 base::string16 text; | 113 base::string16 text; |
110 }; | 114 }; |
111 | 115 |
112 // net::URLFetcherDelegate implementation. | 116 // net::URLFetcherDelegate implementation. |
113 void OnURLFetchComplete(const net::URLFetcher* source) override; | 117 void OnURLFetchComplete(const net::URLFetcher* source) override; |
114 | 118 |
115 // Creates a URLFetcher object used for sending a JSON-RPC request. This | 119 // Creates a URLFetcher object used for sending a JSON-RPC request. This |
116 // function is overridden by unit tests to prevent them from actually sending | 120 // function is overridden by unit tests to prevent them from actually sending |
117 // requests to the Spelling service. | 121 // requests to the Spelling service. |
118 virtual std::unique_ptr<net::URLFetcher> CreateURLFetcher(const GURL& url); | 122 virtual std::unique_ptr<net::URLFetcher> CreateURLFetcher(const GURL& url); |
119 | 123 |
120 // The URLFetcher object used for sending a JSON-RPC request. | 124 // The URLFetcher object used for sending a JSON-RPC request. |
121 std::map<const net::URLFetcher*, TextCheckCallbackData*> spellcheck_fetchers_; | 125 std::map<const net::URLFetcher*, std::unique_ptr<TextCheckCallbackData>> |
| 126 spellcheck_fetchers_; |
122 }; | 127 }; |
123 | 128 |
124 #endif // COMPONENTS_SPELLCHECK_BROWSER_SPELLING_SERVICE_CLIENT_H_ | 129 #endif // COMPONENTS_SPELLCHECK_BROWSER_SPELLING_SERVICE_CLIENT_H_ |
OLD | NEW |