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

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

Issue 371063: Integrate BlacklistManager with Profile. (Closed)
Patch Set: trybot fixes Created 11 years 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/ref_counted.h" 12 #include "base/ref_counted.h"
13 #include "base/scoped_ptr.h" 13 #include "base/scoped_ptr.h"
14 #include "chrome/browser/chrome_thread.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 Profile; 18 class Profile;
19 19
20 class BlacklistPathProvider { 20 class BlacklistPathProvider {
21 public: 21 public:
22 // Returns true if the provider is ready (has loaded the blacklist paths
23 // and we can query them). Called on UI thread.
24 virtual bool AreBlacklistPathsReady() const = 0;
25
26 // Returns paths that will still be there after browser shutdown
27 // (installed extensions). Called on UI thread.
28 virtual std::vector<FilePath> GetPersistentBlacklistPaths() = 0;
29
30 // Returns paths that will disappear after browser shutdown
31 // (unpacked extensions). Called on UI thread.
32 virtual std::vector<FilePath> GetTransientBlacklistPaths() = 0;
33
34 protected:
22 virtual ~BlacklistPathProvider(); 35 virtual ~BlacklistPathProvider();
23
24 // The methods below will be invoked on the UI thread.
25 virtual std::vector<FilePath> GetPersistentBlacklistPaths() = 0;
26 virtual std::vector<FilePath> GetTransientBlacklistPaths() = 0;
27 }; 36 };
28 37
29 // Updates one compiled binary blacklist based on a list of plaintext 38 // Updates one compiled binary blacklist based on a list of plaintext
30 // blacklists. 39 // blacklists.
31 class BlacklistManager 40 class BlacklistManager
32 : public NotificationObserver, 41 : public NotificationObserver,
33 public base::RefCountedThreadSafe<BlacklistManager, 42 public base::RefCountedThreadSafe<BlacklistManager,
34 ChromeThread::DeleteOnUIThread> { 43 ChromeThread::DeleteOnUIThread> {
35 public: 44 public:
36 BlacklistManager(); 45 // Create BlacklistManager (must be done on UI thread).
37 void Initialize(Profile* profile, BlacklistPathProvider* path_provider); 46 BlacklistManager(Profile* profile, BlacklistPathProvider* path_provider);
38 47
39 const Blacklist* GetCompiledBlacklist() const { 48 // Initialize the BlacklistManager (on UI thread).
40 // TODO(phajdan.jr): Determine on which thread this should be invoked (IO?). 49 void Initialize();
41 return compiled_blacklist_.get(); 50
42 } 51 // Returns compiled blacklist, or NULL if not ready. Only valid to call on IO
52 // thread.
53 const Blacklist* GetCompiledBlacklist() const;
43 54
44 // NotificationObserver 55 // NotificationObserver
45 virtual void Observe(NotificationType type, 56 virtual void Observe(NotificationType type,
46 const NotificationSource& source, 57 const NotificationSource& source,
47 const NotificationDetails& details); 58 const NotificationDetails& details);
48 59
49 #ifdef UNIT_TEST 60 #ifdef UNIT_TEST
50 const FilePath& compiled_blacklist_path() { return compiled_blacklist_path_; } 61 const FilePath& compiled_blacklist_path() { return compiled_blacklist_path_; }
51 #endif // UNIT_TEST 62 #endif // UNIT_TEST
52 63
53 private: 64 private:
54 friend class ChromeThread; 65 friend class ChromeThread;
55 friend class DeleteTask<BlacklistManager>; 66 friend class DeleteTask<BlacklistManager>;
56 67
57 ~BlacklistManager() {} 68 virtual ~BlacklistManager();
58 69
59 // Compile all persistent blacklists to one binary blacklist stored on disk. 70 // Compile all persistent blacklists to one binary blacklist stored on disk.
60 void CompileBlacklist(); 71 void CompileBlacklist();
61 void DoCompileBlacklist(const std::vector<FilePath>& source_blacklists); 72 void DoCompileBlacklist(const std::vector<FilePath>& source_blacklists);
62 void OnBlacklistCompilationFinished(bool success); 73 void OnBlacklistCompilationFinished(bool success);
63 74
64 // Read all blacklists from disk (the compiled one and also the transient 75 // Read all blacklists from disk (the compiled one and also the transient
65 // blacklists). 76 // blacklists). In case of failure, if we haven't loaded any blacklist yet,
77 // we'll compile the blacklist and try to read it again.
66 void ReadBlacklist(); 78 void ReadBlacklist();
67 void DoReadBlacklist(const std::vector<FilePath>& transient_blacklists); 79 void DoReadBlacklist(const std::vector<FilePath>& transient_blacklists);
68 void ReportBlacklistReadResult(Blacklist* blacklist); 80 void UpdatePublishedCompiledBlacklist(Blacklist* blacklist);
69 void OnBlacklistReadFinished(Blacklist* blacklist); 81 void OnBlacklistReadFinished(bool success);
70 82
71 // True after the first blacklist read has finished (regardless of success). 83 // True after the first blacklist read has finished (regardless of success).
72 // Used to avoid an infinite loop. 84 // Used to avoid an infinite loop.
73 bool first_read_finished_; 85 bool first_read_finished_;
74 86
75 Profile* profile_; 87 Profile* profile_;
76 88
77 // Path where we store the compiled blacklist. 89 // Path where we store the compiled blacklist.
78 FilePath compiled_blacklist_path_; 90 FilePath compiled_blacklist_path_;
79 91
80 // Keep the compiled blacklist object in memory. 92 // Keep the compiled blacklist object in memory.
81 scoped_ptr<Blacklist> compiled_blacklist_; 93 scoped_ptr<Blacklist> compiled_blacklist_;
82 94
83 BlacklistPathProvider* path_provider_; 95 BlacklistPathProvider* path_provider_;
84 96
85 NotificationRegistrar registrar_; 97 NotificationRegistrar registrar_;
86 98
87 DISALLOW_COPY_AND_ASSIGN(BlacklistManager); 99 DISALLOW_COPY_AND_ASSIGN(BlacklistManager);
88 }; 100 };
89 101
90 #endif // CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_MANAGER_H_ 102 #endif // CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_url_request_context.cc ('k') | chrome/browser/privacy_blacklist/blacklist_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698