diff options
author | morrita@chromium.org <morrita@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-24 05:08:10 +0000 |
---|---|---|
committer | morrita@chromium.org <morrita@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-24 05:08:10 +0000 |
commit | ae428afa0b4956151d38ac88d3311c36a825e88f (patch) | |
tree | 9ab2f474971df06485369eaf2fb986d71e823a5b /chrome/browser/spellchecker | |
parent | 5c68d695f520f4f393ba6a9380dd4f7a4f8280c2 (diff) | |
download | chromium_src-ae428afa0b4956151d38ac88d3311c36a825e88f.zip chromium_src-ae428afa0b4956151d38ac88d3311c36a825e88f.tar.gz chromium_src-ae428afa0b4956151d38ac88d3311c36a825e88f.tar.bz2 |
Renamed SpellCheckHostObserver to SpellCheckProfileProvider
since it provides an accessor and no longer simple observer.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/7712023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97992 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/spellchecker')
-rw-r--r-- | chrome/browser/spellchecker/spellcheck_host.cc | 4 | ||||
-rw-r--r-- | chrome/browser/spellchecker/spellcheck_host.h | 10 | ||||
-rw-r--r-- | chrome/browser/spellchecker/spellcheck_host_impl.cc | 42 | ||||
-rw-r--r-- | chrome/browser/spellchecker/spellcheck_host_impl.h | 24 | ||||
-rw-r--r-- | chrome/browser/spellchecker/spellcheck_profile.cc | 8 | ||||
-rw-r--r-- | chrome/browser/spellchecker/spellcheck_profile.h | 10 | ||||
-rw-r--r-- | chrome/browser/spellchecker/spellcheck_profile_provider.h (renamed from chrome/browser/spellchecker/spellcheck_host_observer.h) | 20 | ||||
-rw-r--r-- | chrome/browser/spellchecker/spellcheck_profile_unittest.cc | 6 |
8 files changed, 64 insertions, 60 deletions
diff --git a/chrome/browser/spellchecker/spellcheck_host.cc b/chrome/browser/spellchecker/spellcheck_host.cc index d9a19b9..bfdad0f 100644 --- a/chrome/browser/spellchecker/spellcheck_host.cc +++ b/chrome/browser/spellchecker/spellcheck_host.cc @@ -24,12 +24,12 @@ SpellCheckHost::EventType g_status_type = SpellCheckHost::BDICT_NOTINITIALIZED; // static scoped_refptr<SpellCheckHost> SpellCheckHost::Create( - SpellCheckHostObserver* observer, + SpellCheckProfileProvider* profile, const std::string& language, net::URLRequestContextGetter* request_context_getter, SpellCheckHostMetrics* metrics) { scoped_refptr<SpellCheckHostImpl> host = - new SpellCheckHostImpl(observer, + new SpellCheckHostImpl(profile, language, request_context_getter, metrics); diff --git a/chrome/browser/spellchecker/spellcheck_host.h b/chrome/browser/spellchecker/spellcheck_host.h index 7c36b69..ef08f34 100644 --- a/chrome/browser/spellchecker/spellcheck_host.h +++ b/chrome/browser/spellchecker/spellcheck_host.h @@ -21,7 +21,7 @@ class WaitableEvent; class Profile; class RenderProcessHost; class SpellCheckHostMetrics; -class SpellCheckHostObserver; +class SpellCheckProfileProvider; namespace net { class URLRequestContextGetter; @@ -36,7 +36,7 @@ class URLRequestContextGetter; // * Listing available languages for a Profile object; // * Accepting an observer to reacting the state change of the object. // You can also remove the observer from the SpellCheckHost object. -// The object should implement SpellCheckHostObserver interface. +// The object should implement SpellCheckProfileProvider interface. // // The following snippet describes how to use this class, // std::vector<std::string> languages; @@ -63,14 +63,14 @@ class SpellCheckHost // Creates the instance of SpellCheckHost implementation object. static scoped_refptr<SpellCheckHost> Create( - SpellCheckHostObserver* observer, + SpellCheckProfileProvider* profile, const std::string& language, net::URLRequestContextGetter* request_context_getter, SpellCheckHostMetrics* metrics); - // Clears an observer which is set on creation. + // Clears a profile which is set on creation. // Used to prevent calling back to a deleted object. - virtual void UnsetObserver() = 0; + virtual void UnsetProfile() = 0; // Pass the renderer some basic intialization information. Note that the // renderer will not load Hunspell until it needs to. diff --git a/chrome/browser/spellchecker/spellcheck_host_impl.cc b/chrome/browser/spellchecker/spellcheck_host_impl.cc index ceb7f2b..1dae2300 100644 --- a/chrome/browser/spellchecker/spellcheck_host_impl.cc +++ b/chrome/browser/spellchecker/spellcheck_host_impl.cc @@ -15,7 +15,7 @@ #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" -#include "chrome/browser/spellchecker/spellcheck_host_observer.h" +#include "chrome/browser/spellchecker/spellcheck_profile_provider.h" #include "chrome/browser/spellchecker/spellchecker_platform_engine.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" @@ -80,18 +80,18 @@ FilePath GetFallbackFilePath(const FilePath& first_choice) { // Constructed on UI thread. SpellCheckHostImpl::SpellCheckHostImpl( - SpellCheckHostObserver* observer, + SpellCheckProfileProvider* profile, const std::string& language, net::URLRequestContextGetter* request_context_getter, SpellCheckHostMetrics* metrics) - : observer_(observer), + : profile_(profile), language_(language), file_(base::kInvalidPlatformFileValue), tried_to_download_(false), use_platform_spellchecker_(false), request_context_getter_(request_context_getter), metrics_(metrics) { - DCHECK(observer_); + DCHECK(profile_); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); FilePath personal_file_directory; @@ -118,7 +118,7 @@ void SpellCheckHostImpl::Initialize() { SpellCheckerPlatform::SetLanguage(language_); MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this, - &SpellCheckHostImpl::InformObserverOfInitialization)); + &SpellCheckHostImpl::InformProfileOfInitialization)); return; } @@ -131,10 +131,10 @@ void SpellCheckHostImpl::Initialize() { &SpellCheckHostImpl::InitializeDictionaryLocation)); } -void SpellCheckHostImpl::UnsetObserver() { +void SpellCheckHostImpl::UnsetProfile() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - observer_ = NULL; + profile_ = NULL; request_context_getter_ = NULL; fetcher_.reset(); registrar_.RemoveAll(); @@ -163,7 +163,7 @@ void SpellCheckHostImpl::InitForRenderer(RenderProcessHost* process) { process->Send(new SpellCheckMsg_Init( file, - observer_ ? observer_->GetCustomWords() : CustomWordList(), + profile_ ? profile_->GetCustomWords() : CustomWordList(), GetLanguage(), prefs->GetBoolean(prefs::kEnableAutoSpellCorrect))); } @@ -171,8 +171,8 @@ void SpellCheckHostImpl::InitForRenderer(RenderProcessHost* process) { void SpellCheckHostImpl::AddWord(const std::string& word) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (observer_) - observer_->CustomWordAddedLocally(word); + if (profile_) + profile_->CustomWordAddedLocally(word); BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, NewRunnableMethod(this, &SpellCheckHostImpl::WriteWordToCustomDictionary, word)); @@ -206,7 +206,7 @@ void SpellCheckHostImpl::InitializeDictionaryLocation() { void SpellCheckHostImpl::InitializeInternal() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - if (!observer_) + if (!profile_) return; if (!VerifyBDict(bdict_file_path_)) { @@ -250,7 +250,7 @@ void SpellCheckHostImpl::InitializeInternal() { BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod( this, - &SpellCheckHostImpl::InformObserverOfInitializationWithCustomWords, + &SpellCheckHostImpl::InformProfileOfInitializationWithCustomWords, custom_words.release())); } @@ -261,19 +261,19 @@ void SpellCheckHostImpl::InitializeOnFileThread() { NewRunnableMethod(this, &SpellCheckHostImpl::Initialize)); } -void SpellCheckHostImpl::InformObserverOfInitialization() { - InformObserverOfInitializationWithCustomWords(NULL); +void SpellCheckHostImpl::InformProfileOfInitialization() { + InformProfileOfInitializationWithCustomWords(NULL); } -void SpellCheckHostImpl::InformObserverOfInitializationWithCustomWords( +void SpellCheckHostImpl::InformProfileOfInitializationWithCustomWords( CustomWordList* custom_words) { - // Non-null |custom_words| should be given only if the observer is available + // Non-null |custom_words| should be given only if the profile is available // for simplifying the life-cycle management of the word list. - DCHECK(observer_ || !custom_words); + DCHECK(profile_ || !custom_words); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (observer_) - observer_->SpellCheckHostInitialized(custom_words); + if (profile_) + profile_->SpellCheckHostInitialized(custom_words); for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); !i.IsAtEnd(); i.Advance()) { @@ -371,7 +371,7 @@ void SpellCheckHostImpl::SaveDictionaryData() { LOG(ERROR) << "Failure to verify the downloaded dictionary."; BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod(this, - &SpellCheckHostImpl::InformObserverOfInitialization)); + &SpellCheckHostImpl::InformProfileOfInitialization)); return; } @@ -396,7 +396,7 @@ void SpellCheckHostImpl::SaveDictionaryData() { // Initialize() call. BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod(this, - &SpellCheckHostImpl::InformObserverOfInitialization)); + &SpellCheckHostImpl::InformProfileOfInitialization)); return; } } diff --git a/chrome/browser/spellchecker/spellcheck_host_impl.h b/chrome/browser/spellchecker/spellcheck_host_impl.h index f81e1fd..cb99838 100644 --- a/chrome/browser/spellchecker/spellcheck_host_impl.h +++ b/chrome/browser/spellchecker/spellcheck_host_impl.h @@ -12,7 +12,7 @@ #include "base/file_path.h" #include "base/memory/scoped_ptr.h" #include "chrome/browser/spellchecker/spellcheck_host.h" -#include "chrome/browser/spellchecker/spellcheck_host_observer.h" +#include "chrome/browser/spellchecker/spellcheck_profile_provider.h" #include "content/common/notification_observer.h" #include "content/common/notification_registrar.h" #include "content/common/url_fetcher.h" @@ -28,7 +28,7 @@ // To download a dictionary and initialize it without blocking the UI thread, // this class also implements the URLFetcher::Delegate() interface. This // initialization status is notified to the UI thread through the -// SpellCheckHostObserver interface. +// SpellCheckProfileProvider interface. // // We expect a profile creates an instance of this class through a factory // method, SpellCheckHost::Create() and uses only the SpellCheckHost interface @@ -41,7 +41,7 @@ class SpellCheckHostImpl : public SpellCheckHost, public URLFetcher::Delegate, public NotificationObserver { public: - SpellCheckHostImpl(SpellCheckHostObserver* observer, + SpellCheckHostImpl(SpellCheckProfileProvider* profile, const std::string& language, net::URLRequestContextGetter* request_context_getter, SpellCheckHostMetrics* metrics); @@ -49,7 +49,7 @@ class SpellCheckHostImpl : public SpellCheckHost, void Initialize(); // SpellCheckHost implementation - virtual void UnsetObserver(); + virtual void UnsetProfile(); virtual void InitForRenderer(RenderProcessHost* process); virtual void AddWord(const std::string& word); virtual const base::PlatformFile& GetDictionaryFile() const; @@ -57,7 +57,7 @@ class SpellCheckHostImpl : public SpellCheckHost, virtual bool IsUsingPlatformChecker() const; private: - typedef SpellCheckHostObserver::CustomWordList CustomWordList; + typedef SpellCheckProfileProvider::CustomWordList CustomWordList; // These two classes can destruct us. friend class BrowserThread; @@ -79,15 +79,15 @@ class SpellCheckHostImpl : public SpellCheckHost, void InitializeOnFileThread(); - // Inform |observer_| that initialization has finished. + // Inform |profile_| that initialization has finished. // |custom_words| holds the custom word list which was // loaded at the file thread. - void InformObserverOfInitializationWithCustomWords( + void InformProfileOfInitializationWithCustomWords( CustomWordList* custom_words); - // An alternative version of InformObserverOfInitializationWithCustomWords() + // An alternative version of InformProfileOfInitializationWithCustomWords() // which implies empty |custom_words|. - void InformObserverOfInitialization(); + void InformProfileOfInitialization(); // If |dictionary_file_| is missing, we attempt to download it. void DownloadDictionary(); @@ -111,7 +111,7 @@ class SpellCheckHostImpl : public SpellCheckHost, const net::ResponseCookies& cookies, const std::string& data); - // NotificationObserver implementation. + // NotificationProfile implementation. virtual void Observe(int type, const NotificationSource& source, const NotificationDetails& details); @@ -125,7 +125,7 @@ class SpellCheckHostImpl : public SpellCheckHost, bool VerifyBDict(const FilePath& path) const; // May be NULL. - SpellCheckHostObserver* observer_; + SpellCheckProfileProvider* profile_; // The desired location of the dictionary file (whether or not t exists yet). FilePath bdict_file_path_; @@ -160,6 +160,8 @@ class SpellCheckHostImpl : public SpellCheckHost, // An optional metrics counter given by the constructor. SpellCheckHostMetrics* metrics_; + + DISALLOW_COPY_AND_ASSIGN(SpellCheckHostImpl); }; #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HOST_IMPL_H_ diff --git a/chrome/browser/spellchecker/spellcheck_profile.cc b/chrome/browser/spellchecker/spellcheck_profile.cc index f540180..dd79b96 100644 --- a/chrome/browser/spellchecker/spellcheck_profile.cc +++ b/chrome/browser/spellchecker/spellcheck_profile.cc @@ -22,7 +22,7 @@ SpellCheckProfile::SpellCheckProfile() SpellCheckProfile::~SpellCheckProfile() { if (host_.get()) - host_->UnsetObserver(); + host_->UnsetProfile(); } SpellCheckHost* SpellCheckProfile::GetHost() { @@ -44,7 +44,7 @@ SpellCheckProfile::ReinitializeResult SpellCheckProfile::ReinitializeHost( bool host_deleted = false; if (host_.get()) { - host_->UnsetObserver(); + host_->UnsetProfile(); host_ = NULL; host_deleted = true; } @@ -59,12 +59,12 @@ SpellCheckProfile::ReinitializeResult SpellCheckProfile::ReinitializeHost( } SpellCheckHost* SpellCheckProfile::CreateHost( - SpellCheckHostObserver* observer, + SpellCheckProfileProvider* provider, const std::string& language, net::URLRequestContextGetter* request_context, SpellCheckHostMetrics* metrics) { return SpellCheckHost::Create( - observer, language, request_context, metrics); + provider, language, request_context, metrics); } bool SpellCheckProfile::IsTesting() const { diff --git a/chrome/browser/spellchecker/spellcheck_profile.h b/chrome/browser/spellchecker/spellcheck_profile.h index 0255182..7a7bf0d 100644 --- a/chrome/browser/spellchecker/spellcheck_profile.h +++ b/chrome/browser/spellchecker/spellcheck_profile.h @@ -11,7 +11,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/ref_counted.h" -#include "chrome/browser/spellchecker/spellcheck_host_observer.h" +#include "chrome/browser/spellchecker/spellcheck_profile_provider.h" class Profile; class SpellCheckHost; @@ -39,7 +39,7 @@ class URLRequestContextGetter; // The class is intended to be owned and managed by ProfileImpl internally. // Any usable APIs are provided by SpellCheckHost interface, // which can be retrieved from Profile::GetSpellCheckHost(). -class SpellCheckProfile : public SpellCheckHostObserver { +class SpellCheckProfile : public SpellCheckProfileProvider { public: // Return value of ReinitializeHost() enum ReinitializeResult { @@ -81,7 +81,7 @@ class SpellCheckProfile : public SpellCheckHostObserver { // This should be called only if the metrics recording is active. void StartRecordingMetrics(bool spellcheck_enabled); - // SpellCheckHostObserver implementation. + // SpellCheckProfileProvider implementation. virtual void SpellCheckHostInitialized(CustomWordList* custom_words); virtual const CustomWordList& GetCustomWords() const; virtual void CustomWordAddedLocally(const std::string& word); @@ -89,7 +89,7 @@ class SpellCheckProfile : public SpellCheckHostObserver { protected: // Only tests should override this. virtual SpellCheckHost* CreateHost( - SpellCheckHostObserver* observer, + SpellCheckProfileProvider* provider, const std::string& language, net::URLRequestContextGetter* request_context, SpellCheckHostMetrics* metrics); @@ -106,6 +106,8 @@ class SpellCheckProfile : public SpellCheckHostObserver { // In-memory cache of the custom words file. scoped_ptr<CustomWordList> custom_words_; + + DISALLOW_COPY_AND_ASSIGN(SpellCheckProfile); }; #endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PROFILE_H_ diff --git a/chrome/browser/spellchecker/spellcheck_host_observer.h b/chrome/browser/spellchecker/spellcheck_profile_provider.h index 7f1920e..9376982 100644 --- a/chrome/browser/spellchecker/spellcheck_host_observer.h +++ b/chrome/browser/spellchecker/spellcheck_profile_provider.h @@ -2,31 +2,31 @@ // 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_HOST_OBSERVER_H_ -#define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HOST_OBSERVER_H_ +#ifndef CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PROFILE_PROVIDER_H_ +#define CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PROFILE_PROVIDER_H_ #pragma once #include <string> #include <vector> -// Observer for the SpellCheckHost. -// -// TODO(morrita): This class is no longer observer. So we need to -// rename this to SpellCheckProfile and existing SpellCheckProfile to -// SpellCheckProfileImpl. -class SpellCheckHostObserver { +// A user profile provider and state notification receiver for the +// SpellCheckHost. +class SpellCheckProfileProvider { public: typedef std::vector<std::string> CustomWordList; + // Invoked on the UI thread when SpellCheckHost is initialized. virtual void SpellCheckHostInitialized( CustomWordList* custom_words) = 0; + // Returns in-memory cache of custom word list. virtual const CustomWordList& GetCustomWords() const = 0; + // Invoked on the Ui thread when new custom word is registered. virtual void CustomWordAddedLocally(const std::string& word) = 0; protected: - virtual ~SpellCheckHostObserver() {} + virtual ~SpellCheckProfileProvider() {} }; -#endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_HOST_OBSERVER_H_ +#endif // CHROME_BROWSER_SPELLCHECKER_SPELLCHECK_PROFILE_PROVIDER_H_ diff --git a/chrome/browser/spellchecker/spellcheck_profile_unittest.cc b/chrome/browser/spellchecker/spellcheck_profile_unittest.cc index daffc9c..4e03fa9 100644 --- a/chrome/browser/spellchecker/spellcheck_profile_unittest.cc +++ b/chrome/browser/spellchecker/spellcheck_profile_unittest.cc @@ -14,7 +14,7 @@ namespace { class MockSpellCheckHost : public SpellCheckHost { public: - MOCK_METHOD0(UnsetObserver, void()); + MOCK_METHOD0(UnsetProfile, void()); MOCK_METHOD1(InitForRenderer, void(RenderProcessHost* process)); MOCK_METHOD1(AddWord, void(const std::string& word)); MOCK_CONST_METHOD0(GetDictionaryFile, const base::PlatformFile&()); @@ -34,7 +34,7 @@ class TestingSpellCheckProfile : public SpellCheckProfile { } virtual SpellCheckHost* CreateHost( - SpellCheckHostObserver* observer, + SpellCheckProfileProvider* profile, const std::string& language, net::URLRequestContextGetter* request_context, SpellCheckHostMetrics* metrics) { @@ -51,7 +51,7 @@ class TestingSpellCheckProfile : public SpellCheckProfile { } void SetHostToBeCreated(MockSpellCheckHost* host) { - EXPECT_CALL(*host, UnsetObserver()).Times(1); + EXPECT_CALL(*host, UnsetProfile()).Times(1); EXPECT_CALL(*host, IsReady()).WillRepeatedly(testing::Return(true)); returning_from_create_ = host; } |