OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_PRIVACY_BLACKLIST_BLACKLIST_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_MANAGER_H_ |
6 #define CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_MANAGER_H_ | 6 #define CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_MANAGER_H_ |
7 | 7 |
8 #include <set> | |
9 #include <vector> | 8 #include <vector> |
10 | 9 |
11 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
12 #include "base/file_path.h" | 11 #include "base/file_path.h" |
13 #include "base/non_thread_safe.h" | 12 #include "base/non_thread_safe.h" |
14 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
15 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
16 #include "chrome/common/notification_registrar.h" | 15 #include "chrome/common/notification_registrar.h" |
17 | 16 |
18 class Blacklist; | 17 class Blacklist; |
19 class MessageLoop; | 18 class MessageLoop; |
20 class Profile; | 19 class Profile; |
21 class Task; | 20 class Task; |
22 | 21 |
23 namespace base { | 22 namespace base { |
24 class Thread; | 23 class Thread; |
25 } | 24 } |
26 | 25 |
27 class BlacklistPathProvider { | 26 class BlacklistPathProvider { |
28 public: | 27 public: |
29 virtual ~BlacklistPathProvider(); | 28 virtual ~BlacklistPathProvider(); |
30 | 29 |
31 virtual std::vector<FilePath> GetBlacklistPaths() = 0; | 30 virtual std::vector<FilePath> GetPersistentBlacklistPaths() = 0; |
| 31 |
| 32 virtual std::vector<FilePath> GetTransientBlacklistPaths() = 0; |
32 }; | 33 }; |
33 | 34 |
34 // Updates one compiled binary blacklist based on a list of plaintext | 35 // Updates one compiled binary blacklist based on a list of plaintext |
35 // blacklists. | 36 // blacklists. |
36 class BlacklistManager : public base::RefCountedThreadSafe<BlacklistManager>, | 37 class BlacklistManager : public base::RefCountedThreadSafe<BlacklistManager>, |
37 public NotificationObserver, | 38 public NotificationObserver, |
38 public NonThreadSafe { | 39 public NonThreadSafe { |
39 public: | 40 public: |
40 // You must create and destroy BlacklistManager on the same thread. | 41 // You must create and destroy BlacklistManager on the same thread. |
41 BlacklistManager(Profile* profile, base::Thread* backend_thread); | 42 BlacklistManager(Profile* profile, |
42 | 43 BlacklistPathProvider* path_provider, |
43 void RegisterBlacklistPathProvider(BlacklistPathProvider* provider); | 44 base::Thread* backend_thread); |
44 void UnregisterBlacklistPathProvider(BlacklistPathProvider* provider); | |
45 | 45 |
46 const Blacklist* GetCompiledBlacklist() const { | 46 const Blacklist* GetCompiledBlacklist() const { |
47 return compiled_blacklist_.get(); | 47 return compiled_blacklist_.get(); |
48 } | 48 } |
49 | 49 |
50 // NotificationObserver | 50 // NotificationObserver |
51 virtual void Observe(NotificationType type, | 51 virtual void Observe(NotificationType type, |
52 const NotificationSource& source, | 52 const NotificationSource& source, |
53 const NotificationDetails& details); | 53 const NotificationDetails& details); |
54 | 54 |
55 #ifdef UNIT_TEST | 55 #ifdef UNIT_TEST |
56 const FilePath& compiled_blacklist_path() { return compiled_blacklist_path_; } | 56 const FilePath& compiled_blacklist_path() { return compiled_blacklist_path_; } |
57 #endif // UNIT_TEST | 57 #endif // UNIT_TEST |
58 | 58 |
59 private: | 59 private: |
60 class CompileBlacklistTask; | 60 class CompileBlacklistTask; |
61 class ReadBlacklistTask; | 61 class ReadBlacklistTask; |
62 | 62 |
63 typedef std::set<BlacklistPathProvider*> ProvidersSet; | |
64 | |
65 void CompileBlacklist(); | 63 void CompileBlacklist(); |
66 void ReadBlacklist(); | 64 void ReadBlacklist(); |
67 | 65 |
68 void OnBlacklistCompilationFinished(bool success); | 66 void OnBlacklistCompilationFinished(bool success); |
69 void OnBlacklistReadFinished(Blacklist* blacklist); | 67 void OnBlacklistReadFinished(Blacklist* blacklist); |
70 | 68 |
71 void RunTaskOnBackendThread(Task* task); | 69 void RunTaskOnBackendThread(Task* task); |
72 | 70 |
| 71 // True after the first blacklist read has finished (regardless of success). |
| 72 // Used to avoid an infinite loop. |
| 73 bool first_read_finished_; |
| 74 |
| 75 Profile* profile_; |
| 76 |
73 // Path where we store the compiled blacklist. | 77 // Path where we store the compiled blacklist. |
74 FilePath compiled_blacklist_path_; | 78 FilePath compiled_blacklist_path_; |
75 | 79 |
76 // Keep the compiled blacklist object in memory. | 80 // Keep the compiled blacklist object in memory. |
77 scoped_ptr<Blacklist> compiled_blacklist_; | 81 scoped_ptr<Blacklist> compiled_blacklist_; |
78 | 82 |
79 // If true, then we started compiling a blacklist and haven't yet finished | 83 BlacklistPathProvider* path_provider_; |
80 // successfully. This helps prevent an infinite loop in case of multiple | |
81 // I/O errors. | |
82 bool compiling_blacklist_; | |
83 | |
84 // Registered blacklist paths providers. | |
85 ProvidersSet providers_; | |
86 | 84 |
87 // Backend thread we will execute I/O operations on (NULL means no separate | 85 // Backend thread we will execute I/O operations on (NULL means no separate |
88 // thread). | 86 // thread). |
89 base::Thread* backend_thread_; | 87 base::Thread* backend_thread_; |
90 | 88 |
91 NotificationRegistrar registrar_; | 89 NotificationRegistrar registrar_; |
92 | 90 |
93 DISALLOW_COPY_AND_ASSIGN(BlacklistManager); | 91 DISALLOW_COPY_AND_ASSIGN(BlacklistManager); |
94 }; | 92 }; |
95 | 93 |
96 #endif // CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_MANAGER_H_ | 94 #endif // CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_MANAGER_H_ |
OLD | NEW |