Index: chrome/browser/garbled_text_service.h |
diff --git a/chrome/browser/garbled_text_service.h b/chrome/browser/garbled_text_service.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..603fd94b472dd00fe9d03c85b82e45d534fd304a |
--- /dev/null |
+++ b/chrome/browser/garbled_text_service.h |
@@ -0,0 +1,102 @@ |
+// Copyright (c) 2011 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_GARBLED_TEXT_SERVICE_H_ |
+#define CHROME_BROWSER_GARBLED_TEXT_SERVICE_H_ |
+#pragma once |
+ |
+#include "base/callback_forward.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/singleton.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/threading/non_thread_safe.h" |
+#include "chrome/browser/garbled_text_url_tracker.h" |
+#include "chrome/browser/prefs/pref_change_registrar.h" |
+#include "chrome/browser/profiles/profile_keyed_service.h" |
+#include "chrome/browser/profiles/profile_keyed_service_factory.h" |
+#include "content/public/browser/notification_observer.h" |
+#include "content/public/browser/notification_registrar.h" |
+ |
+class Profile; |
+namespace content { |
+class NotificationDetails; |
+class NotificationSource; |
+} |
+ |
+class GarbledTextService; |
+ |
+// Factory class of GarbledTextURLTracker. This class is instantiated on UI |
+// thread and create GarbledTextURLTracker on IO thread. |
+class GarbledTextServiceParams { |
+ public: |
+ explicit GarbledTextServiceParams(PrefService* user_prefs, |
+ GarbledTextService* service); |
+ ~GarbledTextServiceParams(); |
+ scoped_ptr<GarbledTextURLTracker> CreateTracker( |
+ const BooleanPrefMember& enabled); |
+ |
+ private: |
+ base::WeakPtr<GarbledTextService> service_; |
+ GarbledTextURLTracker::Blacklist blacklist_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(GarbledTextServiceParams); |
+}; |
+ |
+// Factory class of GarbledTextService. |
+class GarbledTextServiceFactory : public ProfileKeyedServiceFactory { |
+ public: |
+ static GarbledTextService* GetForProfile(Profile* profile); |
+ static GarbledTextServiceFactory* GetInstance(); |
+ |
+ virtual void RegisterUserPrefs(PrefService* user_prefs) OVERRIDE; |
+ virtual bool ServiceHasOwnInstanceInIncognito() OVERRIDE; |
+ virtual bool ServiceIsNULLWhileTesting() OVERRIDE; |
+ |
+ private: |
+ friend struct DefaultSingletonTraits<GarbledTextServiceFactory>; |
+ |
+ GarbledTextServiceFactory(); |
+ virtual ~GarbledTextServiceFactory(); |
+ |
+ virtual ProfileKeyedService* BuildServiceInstanceFor( |
+ Profile* profile) const OVERRIDE; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(GarbledTextServiceFactory); |
+}; |
+ |
+// Proxy class for GarbledTextURLTracker from UI thread. This class is |
+// instantiated per Profile instance and held as ProfileKeyedService. |
+class GarbledTextService |
+ : public base::NonThreadSafe, |
+ public base::SupportsWeakPtr<GarbledTextService>, |
+ public ProfileKeyedService { |
+ public: |
+ typedef GarbledTextURLTracker::Blacklist Blacklist; |
+ typedef GarbledTextURLTracker::GarbledURLs GarbledURLs; |
+ |
+ static const char kPrefGarbledTextBlacklist[]; |
+ |
+ explicit GarbledTextService(Profile* profile); |
+ virtual ~GarbledTextService(); |
+ |
+ // Appends normalized |garbled_urls| to the blacklist asynchronously. |
+ void UpdateBlacklist(const GarbledURLs& garbled_urls, |
+ const base::Closure& callback); |
+ |
+ void SetTracker(base::WeakPtr<GarbledTextURLTracker> tracker); |
+ |
+ private: |
+ friend class GarbledTextHelperTest; |
+ friend class GarbledTextServiceTest; |
+ |
+ void UpdatePref(const Blacklist* blacklist_delta, |
+ const base::Closure& callback); |
+ |
+ Profile* profile_; |
+ base::WeakPtr<GarbledTextURLTracker> tracker_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(GarbledTextService); |
+}; |
+ |
+#endif // CHROME_BROWSER_GARBLED_TEXT_SERVICE_H_ |