Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1973)

Unified Diff: chrome/browser/spellchecker/spellcheck_profile.h

Issue 9289007: Profiles: Move the Spelling system onto a ProfileKeyedServiceFactory. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove stray mark Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/spellchecker/spellcheck_profile.h
diff --git a/chrome/browser/spellchecker/spellcheck_profile.h b/chrome/browser/spellchecker/spellcheck_profile.h
index bc97ec9fce93204217ed86794604b80d3763b132..4235e31e14c06d89b3199e455999b71069be1711 100644
--- a/chrome/browser/spellchecker/spellcheck_profile.h
+++ b/chrome/browser/spellchecker/spellcheck_profile.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -11,9 +11,13 @@
#include "base/compiler_specific.h"
#include "base/file_path.h"
-#include "base/memory/scoped_ptr.h"
+#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/prefs/pref_change_registrar.h"
+#include "chrome/browser/profiles/profile_keyed_service.h"
#include "chrome/browser/spellchecker/spellcheck_profile_provider.h"
+#include "content/public/browser/notification_observer.h"
class Profile;
class SpellCheckHost;
@@ -28,37 +32,14 @@ class URLRequestContextGetter;
// * SpellCheckHost object (instantiation, deletion, reset)
// * SpellCheckHostMetrics object (only initiate when metrics is enabled)
//
-// The following snippet describes how to use this class:
-//
-// PrefService* pref = ....;
-// net::URLRequestContextGetter* context = ...;
-// SpellCheckProfile* profile = new SpellCheckProfile();
-// profile->StartRecordingMetrics(true); // to enable recording
-// profile->ReinitializeResult(true, true, pref->GetLanguage(), context);
-// ...
-// SpellCheckHost* host = profile->GetHost();
-//
-// 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 SpellCheckProfileProvider {
+// The class is intended to be owned and managed by SpellCheckFactory
+// internally. Any usable APIs are provided by SpellCheckHost interface, which
+// can be retrieved from SpellCheckFactory::GetHostForProfile();
+class SpellCheckProfile : public SpellCheckProfileProvider,
+ public ProfileKeyedService,
+ public content::NotificationObserver {
public:
- // Return value of ReinitializeHost()
- enum ReinitializeResult {
- // SpellCheckProfile created new SpellCheckHost object. We can
- // retrieve it once the asynchronous initialization task is
- // finished.
- REINITIALIZE_CREATED_HOST,
- // An existing SpellCheckHost insntace is deleted, that means
- // the spell-check feature just tunred from enabled to disabled.
- // The state should be synced to renderer processes
- REINITIALIZE_REMOVED_HOST,
- // The API did nothing. SpellCheckHost instance isn't created nor
- // deleted.
- REINITIALIZE_DID_NOTHING
- };
-
- explicit SpellCheckProfile(const FilePath& profile_dir);
+ explicit SpellCheckProfile(Profile* profile);
virtual ~SpellCheckProfile();
// Retrieves SpellCheckHost object.
@@ -66,17 +47,10 @@ class SpellCheckProfile : public SpellCheckProfileProvider {
// or the host object is not ready yet.
SpellCheckHost* GetHost();
- // Initializes or deletes SpellCheckHost object if necessary.
- // The caller should provide URLRequestContextGetter for
- // possible dictionary download.
- //
- // If |force| is true, the host instance is newly created
- // regardless there is existing instance.
- ReinitializeResult ReinitializeHost(
- bool force,
- bool enable,
- const std::string& language,
- net::URLRequestContextGetter* request_context);
+ // If |force| is false, and the spellchecker is already initialized (or is in
+ // the process of initializing), then do nothing. Otherwise clobber the
+ // current spellchecker and replace it with a new one.
+ void ReinitializeSpellCheckHost(bool force);
// Instantiates SpellCheckHostMetrics object and
// makes it ready for recording metrics.
@@ -90,6 +64,14 @@ class SpellCheckProfile : public SpellCheckProfileProvider {
virtual void LoadCustomDictionary(CustomWordList* custom_words) OVERRIDE;
virtual void WriteWordToCustomDictionary(const std::string& word) OVERRIDE;
+ // ProfileKeyedService implementation.
+ virtual void Shutdown() OVERRIDE;
+
+ // content::NotificationObserver implementation.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
protected:
// Only tests should override this.
virtual SpellCheckHost* CreateHost(
@@ -101,8 +83,49 @@ class SpellCheckProfile : public SpellCheckProfileProvider {
virtual bool IsTesting() const;
private:
+ FRIEND_TEST_ALL_PREFIXES(SpellCheckProfileTest, ReinitializeEnabled);
+ FRIEND_TEST_ALL_PREFIXES(SpellCheckProfileTest, ReinitializeDisabled);
+ FRIEND_TEST_ALL_PREFIXES(SpellCheckProfileTest, ReinitializeRemove);
+ FRIEND_TEST_ALL_PREFIXES(SpellCheckProfileTest, ReinitializeRecreate);
+ FRIEND_TEST_ALL_PREFIXES(SpellCheckProfileTest,
+ SpellCheckHostInitializedWithCustomWords);
+ FRIEND_TEST_ALL_PREFIXES(SpellCheckProfileTest, CustomWordAddedLocally);
+ FRIEND_TEST_ALL_PREFIXES(SpellCheckProfileTest, SaveAndLoad);
+ FRIEND_TEST_ALL_PREFIXES(SpellCheckProfileTest, MultiProfile);
+
+ // Return value of ReinitializeHost()
+ enum ReinitializeResult {
+ // SpellCheckProfile created new SpellCheckHost object. We can
+ // retrieve it once the asynchronous initialization task is
+ // finished.
+ REINITIALIZE_CREATED_HOST,
+ // An existing SpellCheckHost insntace is deleted, that means
+ // the spell-check feature just tunred from enabled to disabled.
+ // The state should be synced to renderer processes
+ REINITIALIZE_REMOVED_HOST,
+ // The API did nothing. SpellCheckHost instance isn't created nor
+ // deleted.
+ REINITIALIZE_DID_NOTHING
+ };
+
+ // Initializes or deletes SpellCheckHost object if necessary.
+ // The caller should provide URLRequestContextGetter for
+ // possible dictionary download.
+ //
+ // If |force| is true, the host instance is newly created
+ // regardless there is existing instance.
+ ReinitializeResult ReinitializeHostImpl(
+ bool force,
+ bool enable,
+ const std::string& language,
+ net::URLRequestContextGetter* request_context);
+
const FilePath& GetCustomDictionaryPath();
+ PrefChangeRegistrar pref_change_registrar_;
+
+ Profile* profile_;
+
scoped_ptr<SpellCheckHost> host_;
scoped_ptr<SpellCheckHostMetrics> metrics_;

Powered by Google App Engine
This is Rietveld 408576698