OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_SPELLCHECK_HOST_IMPL_H_ | 5 #ifndef CHROME_BROWSER_SPELLCHECK_HOST_IMPL_H_ |
6 #define CHROME_BROWSER_SPELLCHECK_HOST_IMPL_H_ | 6 #define CHROME_BROWSER_SPELLCHECK_HOST_IMPL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "chrome/browser/spellcheck_host.h" | 14 #include "chrome/browser/spellcheck_host.h" |
15 #include "chrome/browser/spellcheck_host_observer.h" | 15 #include "chrome/browser/spellcheck_host_observer.h" |
16 #include "chrome/common/net/url_fetcher.h" | 16 #include "chrome/common/net/url_fetcher.h" |
| 17 #include "content/common/notification_observer.h" |
| 18 #include "content/common/notification_registrar.h" |
17 | 19 |
18 // This class implements the SpellCheckHost interface to provide the | 20 // This class implements the SpellCheckHost interface to provide the |
19 // functionalities listed below: | 21 // functionalities listed below: |
20 // * Adding a word to the custom dictionary; | 22 // * Adding a word to the custom dictionary; |
21 // * Storing the custom dictionary to the file, and read it back | 23 // * Storing the custom dictionary to the file, and read it back |
22 // from the file during the initialization. | 24 // from the file during the initialization. |
23 // * Downloading a dictionary and map it for the renderer, and; | 25 // * Downloading a dictionary and map it for the renderer, and; |
24 // * Calling the platform spellchecker attached to the browser; | 26 // * Calling the platform spellchecker attached to the browser; |
25 // | 27 // |
26 // To download a dictionary and initialize it without blocking the UI thread, | 28 // To download a dictionary and initialize it without blocking the UI thread, |
27 // this class also implements the URLFetcher::Delegate() interface. This | 29 // this class also implements the URLFetcher::Delegate() interface. This |
28 // initialization status is notified to the UI thread through the | 30 // initialization status is notified to the UI thread through the |
29 // SpellCheckHostObserver interface. | 31 // SpellCheckHostObserver interface. |
30 // | 32 // |
31 // We expect a profile creates an instance of this class through a factory | 33 // We expect a profile creates an instance of this class through a factory |
32 // method, SpellCheckHost::Create() and uses only the SpellCheckHost interface | 34 // method, SpellCheckHost::Create() and uses only the SpellCheckHost interface |
33 // provided by this class. | 35 // provided by this class. |
34 // spell_check_host_ = SpellCheckHost::Create(...) | 36 // spell_check_host_ = SpellCheckHost::Create(...) |
35 // | 37 // |
36 // Available languages for the checker, which we need to specify via Create(), | 38 // Available languages for the checker, which we need to specify via Create(), |
37 // can be listed using SpellCheckHost::GetAvailableLanguages() static method. | 39 // can be listed using SpellCheckHost::GetAvailableLanguages() static method. |
38 class SpellCheckHostImpl : public SpellCheckHost, | 40 class SpellCheckHostImpl : public SpellCheckHost, |
39 public URLFetcher::Delegate { | 41 public URLFetcher::Delegate, |
| 42 public NotificationObserver { |
40 public: | 43 public: |
41 SpellCheckHostImpl(SpellCheckHostObserver* observer, | 44 SpellCheckHostImpl(SpellCheckHostObserver* observer, |
42 const std::string& language, | 45 const std::string& language, |
43 net::URLRequestContextGetter* request_context_getter); | 46 net::URLRequestContextGetter* request_context_getter); |
44 | 47 |
45 void Initialize(); | 48 void Initialize(); |
46 | 49 |
47 // SpellCheckHost implementation | 50 // SpellCheckHost implementation |
48 | |
49 virtual void UnsetObserver(); | 51 virtual void UnsetObserver(); |
50 | 52 virtual void InitForRenderer(RenderProcessHost* process); |
51 virtual void AddWord(const std::string& word); | 53 virtual void AddWord(const std::string& word); |
52 | |
53 virtual const base::PlatformFile& GetDictionaryFile() const; | 54 virtual const base::PlatformFile& GetDictionaryFile() const; |
54 | |
55 virtual const std::vector<std::string>& GetCustomWords() const; | 55 virtual const std::vector<std::string>& GetCustomWords() const; |
56 | |
57 virtual const std::string& GetLastAddedFile() const; | 56 virtual const std::string& GetLastAddedFile() const; |
58 | |
59 virtual const std::string& GetLanguage() const; | 57 virtual const std::string& GetLanguage() const; |
60 | |
61 virtual bool IsUsingPlatformChecker() const; | 58 virtual bool IsUsingPlatformChecker() const; |
62 | 59 |
63 private: | 60 private: |
64 // These two classes can destruct us. | 61 // These two classes can destruct us. |
65 friend class BrowserThread; | 62 friend class BrowserThread; |
66 friend class DeleteTask<SpellCheckHostImpl>; | 63 friend class DeleteTask<SpellCheckHostImpl>; |
67 | 64 |
68 virtual ~SpellCheckHostImpl(); | 65 virtual ~SpellCheckHostImpl(); |
69 | 66 |
70 // Figure out the location for the dictionary. This is only non-trivial for | 67 // Figure out the location for the dictionary. This is only non-trivial for |
(...skipping 21 matching lines...) Expand all Loading... |
92 | 89 |
93 // URLFetcher::Delegate implementation. Called when we finish downloading the | 90 // URLFetcher::Delegate implementation. Called when we finish downloading the |
94 // spellcheck dictionary; saves the dictionary to |data_|. | 91 // spellcheck dictionary; saves the dictionary to |data_|. |
95 virtual void OnURLFetchComplete(const URLFetcher* source, | 92 virtual void OnURLFetchComplete(const URLFetcher* source, |
96 const GURL& url, | 93 const GURL& url, |
97 const net::URLRequestStatus& status, | 94 const net::URLRequestStatus& status, |
98 int response_code, | 95 int response_code, |
99 const ResponseCookies& cookies, | 96 const ResponseCookies& cookies, |
100 const std::string& data); | 97 const std::string& data); |
101 | 98 |
| 99 // NotificationObserver implementation. |
| 100 virtual void Observe(NotificationType type, |
| 101 const NotificationSource& source, |
| 102 const NotificationDetails& details); |
| 103 |
102 // Saves |data_| to disk. Run on the file thread. | 104 // Saves |data_| to disk. Run on the file thread. |
103 void SaveDictionaryData(); | 105 void SaveDictionaryData(); |
104 | 106 |
105 // May be NULL. | 107 // May be NULL. |
106 SpellCheckHostObserver* observer_; | 108 SpellCheckHostObserver* observer_; |
107 | 109 |
108 // The desired location of the dictionary file (whether or not t exists yet). | 110 // The desired location of the dictionary file (whether or not t exists yet). |
109 FilePath bdict_file_path_; | 111 FilePath bdict_file_path_; |
110 | 112 |
111 // The location of the custom words file. | 113 // The location of the custom words file. |
(...skipping 17 matching lines...) Expand all Loading... |
129 | 131 |
130 // Data received from the dictionary download. | 132 // Data received from the dictionary download. |
131 std::string data_; | 133 std::string data_; |
132 | 134 |
133 // Used for downloading the dictionary file. We don't hold a reference, and | 135 // Used for downloading the dictionary file. We don't hold a reference, and |
134 // it is only valid to use it on the UI thread. | 136 // it is only valid to use it on the UI thread. |
135 net::URLRequestContextGetter* request_context_getter_; | 137 net::URLRequestContextGetter* request_context_getter_; |
136 | 138 |
137 // Used for downloading the dictionary file. | 139 // Used for downloading the dictionary file. |
138 scoped_ptr<URLFetcher> fetcher_; | 140 scoped_ptr<URLFetcher> fetcher_; |
| 141 |
| 142 NotificationRegistrar registrar_; |
139 }; | 143 }; |
140 | 144 |
141 #endif // CHROME_BROWSER_SPELLCHECK_HOST_IMPL_H_ | 145 #endif // CHROME_BROWSER_SPELLCHECK_HOST_IMPL_H_ |
OLD | NEW |