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

Side by Side Diff: chrome/browser/privacy_blacklist/blacklist_manager.h

Issue 361030: Fix threading issues in BlacklistManager, using new ChromeThread. (Closed)
Patch Set: fix compile after the dtor has been made private Created 11 years, 1 month 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 unified diff | Download patch
OLDNEW
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 <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/non_thread_safe.h"
13 #include "base/ref_counted.h" 12 #include "base/ref_counted.h"
14 #include "base/scoped_ptr.h" 13 #include "base/scoped_ptr.h"
14 #include "chrome/browser/chrome_thread.h"
15 #include "chrome/common/notification_registrar.h" 15 #include "chrome/common/notification_registrar.h"
16 16
17 class Blacklist; 17 class Blacklist;
18 class MessageLoop;
19 class Profile; 18 class Profile;
20 class Task;
21
22 namespace base {
23 class Thread;
24 }
25 19
26 class BlacklistPathProvider { 20 class BlacklistPathProvider {
27 public: 21 public:
28 virtual ~BlacklistPathProvider(); 22 virtual ~BlacklistPathProvider();
29 23
24 // The methods below will be invoked on the UI thread.
30 virtual std::vector<FilePath> GetPersistentBlacklistPaths() = 0; 25 virtual std::vector<FilePath> GetPersistentBlacklistPaths() = 0;
31
32 virtual std::vector<FilePath> GetTransientBlacklistPaths() = 0; 26 virtual std::vector<FilePath> GetTransientBlacklistPaths() = 0;
33 }; 27 };
34 28
35 // Updates one compiled binary blacklist based on a list of plaintext 29 // Updates one compiled binary blacklist based on a list of plaintext
36 // blacklists. 30 // blacklists.
37 class BlacklistManager : public base::RefCountedThreadSafe<BlacklistManager>, 31 class BlacklistManager
38 public NotificationObserver, 32 : public NotificationObserver,
39 public NonThreadSafe { 33 public base::RefCountedThreadSafe<BlacklistManager,
34 ChromeThread::DeleteOnUIThread> {
40 public: 35 public:
41 // You must create and destroy BlacklistManager on the same thread. 36 BlacklistManager(Profile* profile, BlacklistPathProvider* path_provider);
42 BlacklistManager(Profile* profile,
43 BlacklistPathProvider* path_provider,
44 base::Thread* backend_thread);
45 37
46 const Blacklist* GetCompiledBlacklist() const { 38 const Blacklist* GetCompiledBlacklist() const {
39 // TODO(phajdan.jr): Determine on which thread this should be invoked (IO?).
47 return compiled_blacklist_.get(); 40 return compiled_blacklist_.get();
48 } 41 }
49 42
50 // NotificationObserver 43 // NotificationObserver
51 virtual void Observe(NotificationType type, 44 virtual void Observe(NotificationType type,
52 const NotificationSource& source, 45 const NotificationSource& source,
53 const NotificationDetails& details); 46 const NotificationDetails& details);
54 47
55 #ifdef UNIT_TEST 48 #ifdef UNIT_TEST
56 const FilePath& compiled_blacklist_path() { return compiled_blacklist_path_; } 49 const FilePath& compiled_blacklist_path() { return compiled_blacklist_path_; }
57 #endif // UNIT_TEST 50 #endif // UNIT_TEST
58 51
59 private: 52 private:
60 class CompileBlacklistTask; 53 friend class ChromeThread;
61 class ReadBlacklistTask; 54 friend class DeleteTask<BlacklistManager>;
62
63 friend class base::RefCountedThreadSafe<BlacklistManager>;
64 55
65 ~BlacklistManager() {} 56 ~BlacklistManager() {}
66 57
58 // Compile all persistent blacklists to one binary blacklist stored on disk.
67 void CompileBlacklist(); 59 void CompileBlacklist();
60 void DoCompileBlacklist(const std::vector<FilePath>& source_blacklists);
61 void OnBlacklistCompilationFinished(bool success);
62
63 // Read all blacklists from disk (the compiled one and also the transient
64 // blacklists).
68 void ReadBlacklist(); 65 void ReadBlacklist();
69 66 void DoReadBlacklist(const std::vector<FilePath>& transient_blacklists);
70 void OnBlacklistCompilationFinished(bool success); 67 void ReportBlacklistReadResult(Blacklist* blacklist);
71 void OnBlacklistReadFinished(Blacklist* blacklist); 68 void OnBlacklistReadFinished(Blacklist* blacklist);
72 69
73 void RunTaskOnBackendThread(Task* task);
74
75 // True after the first blacklist read has finished (regardless of success). 70 // True after the first blacklist read has finished (regardless of success).
76 // Used to avoid an infinite loop. 71 // Used to avoid an infinite loop.
77 bool first_read_finished_; 72 bool first_read_finished_;
78 73
79 Profile* profile_; 74 Profile* profile_;
80 75
81 // Path where we store the compiled blacklist. 76 // Path where we store the compiled blacklist.
82 FilePath compiled_blacklist_path_; 77 FilePath compiled_blacklist_path_;
83 78
84 // Keep the compiled blacklist object in memory. 79 // Keep the compiled blacklist object in memory.
85 scoped_ptr<Blacklist> compiled_blacklist_; 80 scoped_ptr<Blacklist> compiled_blacklist_;
86 81
87 BlacklistPathProvider* path_provider_; 82 BlacklistPathProvider* path_provider_;
88 83
89 // Backend thread we will execute I/O operations on (NULL means no separate
90 // thread).
91 base::Thread* backend_thread_;
92
93 NotificationRegistrar registrar_; 84 NotificationRegistrar registrar_;
94 85
95 DISALLOW_COPY_AND_ASSIGN(BlacklistManager); 86 DISALLOW_COPY_AND_ASSIGN(BlacklistManager);
96 }; 87 };
97 88
98 #endif // CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_MANAGER_H_ 89 #endif // CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extensions_service.cc ('k') | chrome/browser/privacy_blacklist/blacklist_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698