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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_database.h

Issue 5544008: Add a browser test for safebrowsing service.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/lock.h" 13 #include "base/lock.h"
14 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
15 #include "base/task.h" 15 #include "base/task.h"
16 #include "chrome/browser/safe_browsing/safe_browsing_store.h" 16 #include "chrome/browser/safe_browsing/safe_browsing_store.h"
17 #include "chrome/browser/safe_browsing/safe_browsing_util.h" 17 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
18 #include "testing/gtest/include/gtest/gtest_prod.h" 18 #include "testing/gtest/include/gtest/gtest_prod.h"
19 19
20 namespace base { 20 namespace base {
21 class Time; 21 class Time;
22 } 22 }
23 23
24 class BloomFilter; 24 class BloomFilter;
25 class GURL; 25 class GURL;
26 class MessageLoop; 26 class MessageLoop;
27 class SafeBrowsingDatabase;
28
29 // Factory for creating SafeBrowsingDatabase. Tests implement this factory
30 // to create fake Databases for testing.
31 class SafeBrowsingDatabaseFactory {
32 public:
33 SafeBrowsingDatabaseFactory() { }
34 virtual ~SafeBrowsingDatabaseFactory() { }
35 virtual SafeBrowsingDatabase* CreateSafeBrowsingDatabase() = 0;
36 private:
37 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactory);
38 };
27 39
28 // Encapsulates the database that stores information about phishing 40 // Encapsulates the database that stores information about phishing
29 // and malware sites. There is one on-disk database for all profiles, 41 // and malware sites. There is one on-disk database for all profiles,
30 // as it doesn't contain user-specific data. This object is not 42 // as it doesn't contain user-specific data. This object is not
31 // thread-safe, i.e. all its methods should be used on the same thread 43 // thread-safe, i.e. all its methods should be used on the same thread
32 // that it was created on. 44 // that it was created on.
33 45
34 class SafeBrowsingDatabase { 46 class SafeBrowsingDatabase {
35 public: 47 public:
36 // Factory method for obtaining a SafeBrowsingDatabase implementation. 48 // Factory method for obtaining a SafeBrowsingDatabase implementation.
49 // It is not thread safe.
37 static SafeBrowsingDatabase* Create(); 50 static SafeBrowsingDatabase* Create();
51
52 // Makes the passed |factory| the factory used to instantiate
53 // a SafeBrowsingDatabase. This is used for tests.
54 static void RegisterFactory(SafeBrowsingDatabaseFactory* factory) {
55 factory_ = factory;
56 }
57
38 virtual ~SafeBrowsingDatabase(); 58 virtual ~SafeBrowsingDatabase();
39 59
40 // Initializes the database with the given filename. 60 // Initializes the database with the given filename.
41 virtual void Init(const FilePath& filename) = 0; 61 virtual void Init(const FilePath& filename) = 0;
42 62
43 // Deletes the current database and creates a new one. 63 // Deletes the current database and creates a new one.
44 virtual bool ResetDatabase() = 0; 64 virtual bool ResetDatabase() = 0;
45 65
46 // Returns false if |url| is not in the database. If it returns 66 // Returns false if |url| is not in the database. If it returns
47 // true, then either |matching_list| is the name of the matching 67 // true, then either |matching_list| is the name of the matching
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 FAILURE_DATABASE_FILTER_DELETE, 125 FAILURE_DATABASE_FILTER_DELETE,
106 FAILURE_DATABASE_STORE_MISSING, 126 FAILURE_DATABASE_STORE_MISSING,
107 FAILURE_DATABASE_STORE_DELETE, 127 FAILURE_DATABASE_STORE_DELETE,
108 128
109 // Memory space for histograms is determined by the max. ALWAYS 129 // Memory space for histograms is determined by the max. ALWAYS
110 // ADD NEW VALUES BEFORE THIS ONE. 130 // ADD NEW VALUES BEFORE THIS ONE.
111 FAILURE_DATABASE_MAX 131 FAILURE_DATABASE_MAX
112 }; 132 };
113 133
114 static void RecordFailure(FailureType failure_type); 134 static void RecordFailure(FailureType failure_type);
135
136 private:
137 // The factory used to instantiate a SafeBrowsingDatabase object.
138 // Useful for tests, so they can provide their own implementation of
139 // SafeBrowsingDatabase.
140 static SafeBrowsingDatabaseFactory* factory_;
115 }; 141 };
116 142
117 class SafeBrowsingDatabaseNew : public SafeBrowsingDatabase { 143 class SafeBrowsingDatabaseNew : public SafeBrowsingDatabase {
118 public: 144 public:
119 // Create a database on the given store. Takes ownership of 145 // Create a database on the given store. Takes ownership of
120 // |store|. This method is temporary for 146 // |store|. This method is temporary for
121 // SafeBrowsingDatabase::Create(), do not use it otherwise. 147 // SafeBrowsingDatabase::Create(), do not use it otherwise.
122 explicit SafeBrowsingDatabaseNew(SafeBrowsingStore* store); 148 explicit SafeBrowsingDatabaseNew(SafeBrowsingStore* store);
123 149
124 // Create a database with a default store. 150 // Create a database with a default store.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 // Used to schedule resetting the database because of corruption. 229 // Used to schedule resetting the database because of corruption.
204 ScopedRunnableMethodFactory<SafeBrowsingDatabaseNew> reset_factory_; 230 ScopedRunnableMethodFactory<SafeBrowsingDatabaseNew> reset_factory_;
205 231
206 // Set if corruption is detected during the course of an update. 232 // Set if corruption is detected during the course of an update.
207 // Causes the update functions to fail with no side effects, until 233 // Causes the update functions to fail with no side effects, until
208 // the next call to |UpdateStarted()|. 234 // the next call to |UpdateStarted()|.
209 bool corruption_detected_; 235 bool corruption_detected_;
210 }; 236 };
211 237
212 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ 238 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/protocol_manager.cc ('k') | chrome/browser/safe_browsing/safe_browsing_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698