blob: 9100849d6fb2dcd67f8a7ffad3bebe71b061a494 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HUNSPELL_DICTIONARY_H_
#define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HUNSPELL_DICTIONARY_H_
#include "chrome/browser/spellchecker/spellcheck_dictionary.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/platform_file.h"
#include "net/url_request/url_fetcher_delegate.h"
class Profile;
class SpellcheckService;
struct DictionaryFile;
namespace net {
class URLFetcher;
class URLRequestContextGetter;
} // namespace net
// Defines the browser-side hunspell dictionary and provides access to it.
class SpellcheckHunspellDictionary
: public SpellcheckDictionary,
public net::URLFetcherDelegate,
public base::SupportsWeakPtr<SpellcheckHunspellDictionary> {
public:
// Interface to implement for observers of the Hunspell dictionary.
class Observer {
public:
// The dictionary has been initialized.
virtual void OnHunspellDictionaryInitialized() = 0;
// Dictionary download began.
virtual void OnHunspellDictionaryDownloadBegin() = 0;
// Dictionary download succeeded.
virtual void OnHunspellDictionaryDownloadSuccess() = 0;
// Dictionary download failed.
virtual void OnHunspellDictionaryDownloadFailure() = 0;
};
// TODO(rlp): Passing in the host is very temporary. In the next CL this
// will be removed.
SpellcheckHunspellDictionary(
const std::string& language,
net::URLRequestContextGetter* request_context_getter,
SpellcheckService* spellcheck_service);
virtual ~SpellcheckHunspellDictionary();
// SpellcheckDictionary implementation:
virtual void Load() OVERRIDE;
// Retry downloading |dictionary_file_|.
void RetryDownloadDictionary(
net::URLRequestContextGetter* request_context_getter);
// Returns true if the dictionary is ready to use.
virtual bool IsReady() const;
// TODO(rlp): Return by value.
const base::PlatformFile& GetDictionaryFile() const;
const std::string& GetLanguage() const;
bool IsUsingPlatformChecker() const;
// Add an observer for Hunspell dictionary events.
void AddObserver(Observer* observer);
// Remove an observer for Hunspell dictionary events.
void RemoveObserver(Observer* observer);
// Whether dictionary is being downloaded.
bool IsDownloadInProgress();
// Whether dictionary download failed.
bool IsDownloadFailure();
private:
// Dictionary download status.
enum DownloadStatus {
DOWNLOAD_NONE,
DOWNLOAD_IN_PROGRESS,
DOWNLOAD_FAILED,
};
// net::URLFetcherDelegate implementation. Called when dictionary download
// finishes.
virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
// Attempt to download the dictionary.
void DownloadDictionary();
// The reply point for PostTaskAndReplyWithResult, called after the dictionary
// file has been initialized.
void InitializeDictionaryLocationComplete(scoped_ptr<DictionaryFile> file);
// The reply point for PostTaskAndReplyWithResult, called after the dictionary
// file has been saved.
void SaveDictionaryDataComplete(bool dictionary_saved);
// Notify listeners that the dictionary has been initialized.
void InformListenersOfInitialization();
// Notify listeners that the dictionary download failed.
void InformListenersOfDownloadFailure();
// The language of the dictionary file.
std::string language_;
// Whether to use the platform spellchecker instead of Hunspell.
bool use_platform_spellchecker_;
// Used for downloading the dictionary file. SpellcheckHunspellDictionary does
// not hold a reference, and it is only valid to use it on the UI thread.
net::URLRequestContextGetter* request_context_getter_;
// Used for downloading the dictionary file.
scoped_ptr<net::URLFetcher> fetcher_;
base::WeakPtrFactory<SpellcheckHunspellDictionary> weak_ptr_factory_;
SpellcheckService* spellcheck_service_;
// Observers of Hunspell dictionary events.
ObserverList<Observer> observers_;
// Status of the dictionary download.
DownloadStatus download_status_;
// Dictionary file path and descriptor.
scoped_ptr<DictionaryFile> dictionary_file_;
DISALLOW_COPY_AND_ASSIGN(SpellcheckHunspellDictionary);
};
#endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HUNSPELL_DICTIONARY_H_
|