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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_service.cc

Issue 9310020: Add SafeBrowsingURLRequestContext which stores cookies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review changes, fix DownloadProtectionServiceTest Created 8 years, 10 months 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
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 5 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/debug/leak_tracker.h"
11 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
12 #include "base/path_service.h" 13 #include "base/path_service.h"
13 #include "base/stl_util.h" 14 #include "base/stl_util.h"
14 #include "base/string_util.h" 15 #include "base/string_util.h"
15 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
16 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
17 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/metrics/metrics_service.h" 19 #include "chrome/browser/metrics/metrics_service.h"
20 #include "chrome/browser/net/sqlite_persistent_cookie_store.h"
19 #include "chrome/browser/prefs/pref_change_registrar.h" 21 #include "chrome/browser/prefs/pref_change_registrar.h"
20 #include "chrome/browser/prefs/pref_service.h" 22 #include "chrome/browser/prefs/pref_service.h"
21 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/profiles/profile_manager.h" 24 #include "chrome/browser/profiles/profile_manager.h"
23 #include "chrome/browser/safe_browsing/client_side_detection_service.h" 25 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
24 #include "chrome/browser/safe_browsing/download_protection_service.h" 26 #include "chrome/browser/safe_browsing/download_protection_service.h"
25 #include "chrome/browser/safe_browsing/malware_details.h" 27 #include "chrome/browser/safe_browsing/malware_details.h"
26 #include "chrome/browser/safe_browsing/protocol_manager.h" 28 #include "chrome/browser/safe_browsing/protocol_manager.h"
27 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" 29 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
28 #include "chrome/browser/safe_browsing/safe_browsing_database.h" 30 #include "chrome/browser/safe_browsing/safe_browsing_database.h"
29 #include "chrome/browser/tab_contents/tab_util.h" 31 #include "chrome/browser/tab_contents/tab_util.h"
30 #include "chrome/common/chrome_constants.h" 32 #include "chrome/common/chrome_constants.h"
31 #include "chrome/common/chrome_notification_types.h" 33 #include "chrome/common/chrome_notification_types.h"
32 #include "chrome/common/chrome_paths.h" 34 #include "chrome/common/chrome_paths.h"
33 #include "chrome/common/chrome_switches.h" 35 #include "chrome/common/chrome_switches.h"
34 #include "chrome/common/pref_names.h" 36 #include "chrome/common/pref_names.h"
35 #include "chrome/common/url_constants.h" 37 #include "chrome/common/url_constants.h"
36 #include "content/public/browser/browser_thread.h" 38 #include "content/public/browser/browser_thread.h"
37 #include "content/public/browser/navigation_entry.h" 39 #include "content/public/browser/navigation_entry.h"
38 #include "content/public/browser/notification_service.h" 40 #include "content/public/browser/notification_service.h"
39 #include "content/public/browser/notification_types.h" 41 #include "content/public/browser/notification_types.h"
40 #include "content/public/browser/web_contents.h" 42 #include "content/public/browser/web_contents.h"
43 #include "content/public/common/content_client.h"
44 #include "net/base/cookie_monster.h"
41 #include "net/base/registry_controlled_domain.h" 45 #include "net/base/registry_controlled_domain.h"
46 #include "net/url_request/url_request_context.h"
42 #include "net/url_request/url_request_context_getter.h" 47 #include "net/url_request/url_request_context_getter.h"
43 48
44 #if defined(OS_WIN) 49 #if defined(OS_WIN)
45 #include "chrome/installer/util/browser_distribution.h" 50 #include "chrome/installer/util/browser_distribution.h"
46 #endif 51 #endif
47 52
48 using content::BrowserThread; 53 using content::BrowserThread;
49 using content::NavigationEntry; 54 using content::NavigationEntry;
50 using content::WebContents; 55 using content::WebContents;
51 56
52 namespace { 57 namespace {
53 58
59 // Filename suffix for the cookie database.
60 const FilePath::CharType kCookiesFile[] = FILE_PATH_LITERAL(" Cookies");
61
54 // The default URL prefix where browser fetches chunk updates, hashes, 62 // The default URL prefix where browser fetches chunk updates, hashes,
55 // and reports safe browsing hits. 63 // and reports safe browsing hits.
56 const char* const kSbDefaultInfoURLPrefix = 64 const char* const kSbDefaultInfoURLPrefix =
57 "http://safebrowsing.clients.google.com/safebrowsing"; 65 "http://safebrowsing.clients.google.com/safebrowsing";
58 66
59 // The default URL prefix where browser fetches MAC client key and reports 67 // The default URL prefix where browser fetches MAC client key and reports
60 // malware details. 68 // malware details.
61 const char* const kSbDefaultMacKeyURLPrefix = 69 const char* const kSbDefaultMacKeyURLPrefix =
62 "https://sb-ssl.google.com/safebrowsing"; 70 "https://sb-ssl.google.com/safebrowsing";
63 71
(...skipping 14 matching lines...) Expand all
78 if (full_hashes.empty()) { 86 if (full_hashes.empty()) {
79 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_EMPTY; 87 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_EMPTY;
80 } else if (hit) { 88 } else if (hit) {
81 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_HIT; 89 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_HIT;
82 } else { 90 } else {
83 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_MISS; 91 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_MISS;
84 } 92 }
85 SafeBrowsingProtocolManager::RecordGetHashResult(is_download, result); 93 SafeBrowsingProtocolManager::RecordGetHashResult(is_download, result);
86 } 94 }
87 95
96 FilePath BaseFilename() {
97 FilePath path;
98 bool result = PathService::Get(chrome::DIR_USER_DATA, &path);
99 DCHECK(result);
100 return path.Append(chrome::kSafeBrowsingBaseFilename);
101 }
102
88 } // namespace 103 } // namespace
89 104
105 // Custom URLRequestContext used by SafeBrowsing requests, which are not
106 // associated with a particular profile. We need to use a subclass of
107 // URLRequestContext in order to provide the correct User-Agent.
108 class SafeBrowsingURLRequestContext : public net::URLRequestContext {
109 public:
110 virtual const std::string& GetUserAgent(
111 const GURL& url) const OVERRIDE {
112 return content::GetUserAgent(url);
113 }
114
115 private:
116 base::debug::LeakTracker<SafeBrowsingURLRequestContext> leak_tracker_;
117 };
118
119 class SafeBrowsingURLRequestContextGetter
120 : public net::URLRequestContextGetter {
121 public:
122 explicit SafeBrowsingURLRequestContextGetter(
123 SafeBrowsingService* sb_service_);
124 virtual ~SafeBrowsingURLRequestContextGetter();
125
126 // Implementation for net::UrlRequestContextGetter.
127 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
128 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const
129 OVERRIDE;
130
131 private:
132 SafeBrowsingService* const sb_service_; // Owned by BrowserProcess.
133 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
134
135 base::debug::LeakTracker<SafeBrowsingURLRequestContextGetter> leak_tracker_;
136 };
137
138 SafeBrowsingURLRequestContextGetter::SafeBrowsingURLRequestContextGetter(
139 SafeBrowsingService* sb_service)
140 : sb_service_(sb_service),
141 io_message_loop_proxy_(
142 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) {
143 }
144
145 SafeBrowsingURLRequestContextGetter::~SafeBrowsingURLRequestContextGetter() {}
146
147 net::URLRequestContext*
148 SafeBrowsingURLRequestContextGetter::GetURLRequestContext() {
149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
150 DCHECK(sb_service_->url_request_context_);
151
152 return sb_service_->url_request_context_;
153 }
154
155 scoped_refptr<base::MessageLoopProxy>
156 SafeBrowsingURLRequestContextGetter::GetIOMessageLoopProxy() const {
157 return io_message_loop_proxy_;
158 }
159
90 // static 160 // static
91 SafeBrowsingServiceFactory* SafeBrowsingService::factory_ = NULL; 161 SafeBrowsingServiceFactory* SafeBrowsingService::factory_ = NULL;
92 162
93 // The default SafeBrowsingServiceFactory. Global, made a singleton so we 163 // The default SafeBrowsingServiceFactory. Global, made a singleton so we
94 // don't leak it. 164 // don't leak it.
95 class SafeBrowsingServiceFactoryImpl : public SafeBrowsingServiceFactory { 165 class SafeBrowsingServiceFactoryImpl : public SafeBrowsingServiceFactory {
96 public: 166 public:
97 virtual SafeBrowsingService* CreateSafeBrowsingService() { 167 virtual SafeBrowsingService* CreateSafeBrowsingService() {
98 return new SafeBrowsingService(); 168 return new SafeBrowsingService();
99 } 169 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 protocol_manager_(NULL), 238 protocol_manager_(NULL),
169 enabled_(false), 239 enabled_(false),
170 enable_download_protection_(false), 240 enable_download_protection_(false),
171 enable_csd_whitelist_(false), 241 enable_csd_whitelist_(false),
172 enable_download_whitelist_(false), 242 enable_download_whitelist_(false),
173 update_in_progress_(false), 243 update_in_progress_(false),
174 database_update_in_progress_(false), 244 database_update_in_progress_(false),
175 closing_database_(false), 245 closing_database_(false),
176 download_urlcheck_timeout_ms_(kDownloadUrlCheckTimeoutMs), 246 download_urlcheck_timeout_ms_(kDownloadUrlCheckTimeoutMs),
177 download_hashcheck_timeout_ms_(kDownloadHashCheckTimeoutMs) { 247 download_hashcheck_timeout_ms_(kDownloadHashCheckTimeoutMs) {
178 #if !defined(OS_CHROMEOS)
179 if (!CommandLine::ForCurrentProcess()->HasSwitch(
180 switches::kDisableClientSidePhishingDetection)) {
181 csd_service_.reset(
182 safe_browsing::ClientSideDetectionService::Create(
183 g_browser_process->system_request_context()));
184 }
185 download_service_.reset(new safe_browsing::DownloadProtectionService(
186 this,
187 g_browser_process->system_request_context()));
188 #endif
189 } 248 }
190 249
191 SafeBrowsingService::~SafeBrowsingService() { 250 SafeBrowsingService::~SafeBrowsingService() {
192 // Deletes the PrefChangeRegistrars, whose dtors also unregister |this| as an 251 // Deletes the PrefChangeRegistrars, whose dtors also unregister |this| as an
193 // observer of the preferences. 252 // observer of the preferences.
194 STLDeleteValues(&prefs_map_); 253 STLDeleteValues(&prefs_map_);
195 254
196 // We should have already been shut down. If we're still enabled, then the 255 // We should have already been shut down. If we're still enabled, then the
197 // database isn't going to be closed properly, which could lead to corruption. 256 // database isn't going to be closed properly, which could lead to corruption.
198 DCHECK(!enabled_); 257 DCHECK(!enabled_);
199 } 258 }
200 259
201 void SafeBrowsingService::Initialize() { 260 void SafeBrowsingService::Initialize() {
261 url_request_context_getter_ =
262 new SafeBrowsingURLRequestContextGetter(this);
263 BrowserThread::PostTask(
264 BrowserThread::IO, FROM_HERE,
265 base::Bind(
266 &SafeBrowsingService::InitURLRequestContextOnIOThread, this,
267 make_scoped_refptr(g_browser_process->system_request_context())));
268 #if !defined(OS_CHROMEOS)
269 if (!CommandLine::ForCurrentProcess()->HasSwitch(
270 switches::kDisableClientSidePhishingDetection)) {
271 csd_service_.reset(
272 safe_browsing::ClientSideDetectionService::Create(
273 url_request_context_getter_));
274 }
275 download_service_.reset(new safe_browsing::DownloadProtectionService(
276 this,
277 url_request_context_getter_));
278 #endif
279
202 // Track the safe browsing preference of existing profiles. 280 // Track the safe browsing preference of existing profiles.
203 // The SafeBrowsingService will be started if any existing profile has the 281 // The SafeBrowsingService will be started if any existing profile has the
204 // preference enabled. It will also listen for updates to the preferences. 282 // preference enabled. It will also listen for updates to the preferences.
205 ProfileManager* profile_manager = g_browser_process->profile_manager(); 283 ProfileManager* profile_manager = g_browser_process->profile_manager();
206 if (profile_manager) { 284 if (profile_manager) {
207 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); 285 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles();
208 for (size_t i = 0; i < profiles.size(); ++i) { 286 for (size_t i = 0; i < profiles.size(); ++i) {
209 if (profiles[i]->IsOffTheRecord()) 287 if (profiles[i]->IsOffTheRecord())
210 continue; 288 continue;
211 AddPrefService(profiles[i]->GetPrefs()); 289 AddPrefService(profiles[i]->GetPrefs());
212 } 290 }
213 } 291 }
214 292
215 // Track profile creation and destruction. 293 // Track profile creation and destruction.
216 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, 294 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED,
217 content::NotificationService::AllSources()); 295 content::NotificationService::AllSources());
218 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, 296 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
219 content::NotificationService::AllSources()); 297 content::NotificationService::AllSources());
220 } 298 }
221 299
222 void SafeBrowsingService::ShutDown() { 300 void SafeBrowsingService::ShutDown() {
223 Stop(); 301 Stop();
224 // The IO thread is going away, so make sure the ClientSideDetectionService 302 // The IO thread is going away, so make sure the ClientSideDetectionService
225 // dtor executes now since it may call the dtor of URLFetcher which relies 303 // dtor executes now since it may call the dtor of URLFetcher which relies
226 // on it. 304 // on it.
227 csd_service_.reset(); 305 csd_service_.reset();
228 download_service_.reset(); 306 download_service_.reset();
307
308 url_request_context_getter_ = NULL;
309 BrowserThread::PostTask(
willchan no longer on Chromium 2012/02/09 19:41:30 I think this is right, but I just want to point ou
mattm 2012/02/09 22:40:09 I think this works out in practice, since BrowserP
310 BrowserThread::IO, FROM_HERE,
311 base::Bind(&SafeBrowsingService::DestroyURLRequestContextOnIOThread,
312 this));
229 } 313 }
230 314
231 bool SafeBrowsingService::CanCheckUrl(const GURL& url) const { 315 bool SafeBrowsingService::CanCheckUrl(const GURL& url) const {
232 return url.SchemeIs(chrome::kFtpScheme) || 316 return url.SchemeIs(chrome::kFtpScheme) ||
233 url.SchemeIs(chrome::kHttpScheme) || 317 url.SchemeIs(chrome::kHttpScheme) ||
234 url.SchemeIs(chrome::kHttpsScheme); 318 url.SchemeIs(chrome::kHttpsScheme);
235 } 319 }
236 320
237 // Only report SafeBrowsing related stats when UMA is enabled. User must also 321 // Only report SafeBrowsing related stats when UMA is enabled. User must also
238 // ensure that safe browsing is enabled from the calling profile. 322 // ensure that safe browsing is enabled from the calling profile.
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 604 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
521 DCHECK(enabled_); 605 DCHECK(enabled_);
522 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( 606 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind(
523 &SafeBrowsingService::OnResetDatabase, this)); 607 &SafeBrowsingService::OnResetDatabase, this));
524 } 608 }
525 609
526 void SafeBrowsingService::LogPauseDelay(base::TimeDelta time) { 610 void SafeBrowsingService::LogPauseDelay(base::TimeDelta time) {
527 UMA_HISTOGRAM_LONG_TIMES("SB2.Delay", time); 611 UMA_HISTOGRAM_LONG_TIMES("SB2.Delay", time);
528 } 612 }
529 613
530 void SafeBrowsingService::OnIOInitialize( 614 void SafeBrowsingService::InitURLRequestContextOnIOThread(
615 net::URLRequestContextGetter* system_url_request_context_getter) {
616 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
617 DCHECK(!url_request_context_.get());
618
619 scoped_refptr<net::CookieStore> cookie_store = new net::CookieMonster(
620 new SQLitePersistentCookieStore(
621 FilePath(BaseFilename().value() + kCookiesFile), false),
622 NULL);
623
624 url_request_context_ = new SafeBrowsingURLRequestContext;
625 // |system_url_request_context_getter| may be NULL during tests.
626 if (system_url_request_context_getter)
mattm 2012/02/07 01:28:01 Had to update DownloadProtectionServiceTest to cal
627 url_request_context_->CopyFrom(
628 system_url_request_context_getter->GetURLRequestContext());
629 url_request_context_->set_cookie_store(cookie_store);
630 }
631
632 void SafeBrowsingService::DestroyURLRequestContextOnIOThread() {
633 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
634
635 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where
636 // url_request_context_getter_ is cleared, since the URLRequestContextGetter
637 // will PostTask to IOTread to delete itself.
638 using base::debug::LeakTracker;
639 LeakTracker<SafeBrowsingURLRequestContextGetter>::CheckForLeaks();
640
641 DCHECK(url_request_context_.get());
642 url_request_context_ = NULL;
643 }
644
645 void SafeBrowsingService::StartOnIOThread(
531 const std::string& client_key, 646 const std::string& client_key,
532 const std::string& wrapped_key, 647 const std::string& wrapped_key) {
533 net::URLRequestContextGetter* request_context_getter) {
534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 648 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
535 if (enabled_) 649 if (enabled_)
536 return; 650 return;
537 DCHECK(!safe_browsing_thread_.get()); 651 DCHECK(!safe_browsing_thread_.get());
538 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); 652 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread"));
539 if (!safe_browsing_thread_->Start()) 653 if (!safe_browsing_thread_->Start())
540 return; 654 return;
541 enabled_ = true; 655 enabled_ = true;
542 656
543 registrar_.reset(new content::NotificationRegistrar); 657 registrar_.reset(new content::NotificationRegistrar);
(...skipping 27 matching lines...) Expand all
571 cmdline->HasSwitch(switches::kSbMacKeyURLPrefix) ? 685 cmdline->HasSwitch(switches::kSbMacKeyURLPrefix) ?
572 cmdline->GetSwitchValueASCII(switches::kSbMacKeyURLPrefix) : 686 cmdline->GetSwitchValueASCII(switches::kSbMacKeyURLPrefix) :
573 kSbDefaultMacKeyURLPrefix; 687 kSbDefaultMacKeyURLPrefix;
574 688
575 DCHECK(!protocol_manager_); 689 DCHECK(!protocol_manager_);
576 protocol_manager_ = 690 protocol_manager_ =
577 SafeBrowsingProtocolManager::Create(this, 691 SafeBrowsingProtocolManager::Create(this,
578 client_name, 692 client_name,
579 client_key, 693 client_key,
580 wrapped_key, 694 wrapped_key,
581 request_context_getter, 695 url_request_context_getter_,
582 info_url_prefix, 696 info_url_prefix,
583 mackey_url_prefix, 697 mackey_url_prefix,
584 disable_auto_update); 698 disable_auto_update);
585 699
586 protocol_manager_->Initialize(); 700 protocol_manager_->Initialize();
587 } 701 }
588 702
589 void SafeBrowsingService::OnIOShutdown() { 703 void SafeBrowsingService::StopOnIOThread() {
590 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 704 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
591 if (!enabled_) 705 if (!enabled_)
592 return; 706 return;
593 707
594 enabled_ = false; 708 enabled_ = false;
595 709
596 registrar_.reset(); 710 registrar_.reset();
597 711
598 // This cancels all in-flight GetHash requests. 712 // This cancels all in-flight GetHash requests.
599 delete protocol_manager_; 713 delete protocol_manager_;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 if (safe_browsing_thread_.get()) { 806 if (safe_browsing_thread_.get()) {
693 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, 807 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE,
694 base::Bind(&SafeBrowsingService::OnCloseDatabase, this)); 808 base::Bind(&SafeBrowsingService::OnCloseDatabase, this));
695 } 809 }
696 } 810 }
697 811
698 SafeBrowsingDatabase* SafeBrowsingService::GetDatabase() { 812 SafeBrowsingDatabase* SafeBrowsingService::GetDatabase() {
699 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop()); 813 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop());
700 if (database_) 814 if (database_)
701 return database_; 815 return database_;
702
703 FilePath path;
704 bool result = PathService::Get(chrome::DIR_USER_DATA, &path);
705 DCHECK(result);
706 path = path.Append(chrome::kSafeBrowsingBaseFilename);
707
708 const base::TimeTicks before = base::TimeTicks::Now(); 816 const base::TimeTicks before = base::TimeTicks::Now();
709 817
710 SafeBrowsingDatabase* database = 818 SafeBrowsingDatabase* database =
711 SafeBrowsingDatabase::Create(enable_download_protection_, 819 SafeBrowsingDatabase::Create(enable_download_protection_,
712 enable_csd_whitelist_, 820 enable_csd_whitelist_,
713 enable_download_whitelist_); 821 enable_download_whitelist_);
714 822
715 database->Init(path); 823 database->Init(BaseFilename());
716 { 824 {
717 // Acquiring the lock here guarantees correct ordering between the writes to 825 // Acquiring the lock here guarantees correct ordering between the writes to
718 // the new database object above, and the setting of |databse_| below. 826 // the new database object above, and the setting of |databse_| below.
719 base::AutoLock lock(database_lock_); 827 base::AutoLock lock(database_lock_);
720 database_ = database; 828 database_ = database;
721 } 829 }
722 830
723 BrowserThread::PostTask( 831 BrowserThread::PostTask(
724 BrowserThread::IO, FROM_HERE, 832 BrowserThread::IO, FROM_HERE,
725 base::Bind(&SafeBrowsingService::DatabaseLoadComplete, this)); 833 base::Bind(&SafeBrowsingService::DatabaseLoadComplete, this));
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 PrefService* local_state = g_browser_process->local_state(); 1000 PrefService* local_state = g_browser_process->local_state();
893 DCHECK(local_state); 1001 DCHECK(local_state);
894 std::string client_key, wrapped_key; 1002 std::string client_key, wrapped_key;
895 if (local_state) { 1003 if (local_state) {
896 client_key = 1004 client_key =
897 local_state->GetString(prefs::kSafeBrowsingClientKey); 1005 local_state->GetString(prefs::kSafeBrowsingClientKey);
898 wrapped_key = 1006 wrapped_key =
899 local_state->GetString(prefs::kSafeBrowsingWrappedKey); 1007 local_state->GetString(prefs::kSafeBrowsingWrappedKey);
900 } 1008 }
901 1009
902 // We will issue network fetches using the system request context.
903 scoped_refptr<net::URLRequestContextGetter> request_context_getter(
904 g_browser_process->system_request_context());
905
906 CommandLine* cmdline = CommandLine::ForCurrentProcess(); 1010 CommandLine* cmdline = CommandLine::ForCurrentProcess();
907 enable_download_protection_ = 1011 enable_download_protection_ =
908 !cmdline->HasSwitch(switches::kSbDisableDownloadProtection); 1012 !cmdline->HasSwitch(switches::kSbDisableDownloadProtection);
909 1013
910 // We only download the csd-whitelist if client-side phishing detection is 1014 // We only download the csd-whitelist if client-side phishing detection is
911 // enabled. 1015 // enabled.
912 #ifdef OS_CHROMEOS 1016 #ifdef OS_CHROMEOS
913 // Client-side detection is disabled on ChromeOS for now, so don't bother 1017 // Client-side detection is disabled on ChromeOS for now, so don't bother
914 // downloading the whitelist. 1018 // downloading the whitelist.
915 enable_csd_whitelist_ = false; 1019 enable_csd_whitelist_ = false;
916 #else 1020 #else
917 enable_csd_whitelist_ = 1021 enable_csd_whitelist_ =
918 !cmdline->HasSwitch(switches::kDisableClientSidePhishingDetection); 1022 !cmdline->HasSwitch(switches::kDisableClientSidePhishingDetection);
919 #endif 1023 #endif
920 1024
921 // TODO(noelutz): remove this boolean variable since it should always be true 1025 // TODO(noelutz): remove this boolean variable since it should always be true
922 // if SafeBrowsing is enabled. Unfortunately, we have no test data for this 1026 // if SafeBrowsing is enabled. Unfortunately, we have no test data for this
923 // list right now. This means that we need to be able to disable this list 1027 // list right now. This means that we need to be able to disable this list
924 // for the SafeBrowsing test to pass. 1028 // for the SafeBrowsing test to pass.
925 enable_download_whitelist_ = enable_csd_whitelist_; 1029 enable_download_whitelist_ = enable_csd_whitelist_;
926 1030
927 BrowserThread::PostTask( 1031 BrowserThread::PostTask(
928 BrowserThread::IO, FROM_HERE, 1032 BrowserThread::IO, FROM_HERE,
929 base::Bind(&SafeBrowsingService::OnIOInitialize, 1033 base::Bind(&SafeBrowsingService::StartOnIOThread,
930 this, client_key, wrapped_key, request_context_getter)); 1034 this, client_key, wrapped_key));
931 } 1035 }
932 1036
933 void SafeBrowsingService::Stop() { 1037 void SafeBrowsingService::Stop() {
934 BrowserThread::PostTask( 1038 BrowserThread::PostTask(
935 BrowserThread::IO, FROM_HERE, 1039 BrowserThread::IO, FROM_HERE,
936 base::Bind(&SafeBrowsingService::OnIOShutdown, this)); 1040 base::Bind(&SafeBrowsingService::StopOnIOThread, this));
937 } 1041 }
938 1042
939 void SafeBrowsingService::OnCloseDatabase() { 1043 void SafeBrowsingService::OnCloseDatabase() {
940 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop()); 1044 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop());
941 DCHECK(closing_database_); 1045 DCHECK(closing_database_);
942 1046
943 // Because |closing_database_| is true, nothing on the IO thread will be 1047 // Because |closing_database_| is true, nothing on the IO thread will be
944 // accessing the database, so it's safe to delete and then NULL the pointer. 1048 // accessing the database, so it's safe to delete and then NULL the pointer.
945 delete database_; 1049 delete database_;
946 database_ = NULL; 1050 database_ = NULL;
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 Stop(); 1455 Stop();
1352 1456
1353 if (csd_service_.get()) 1457 if (csd_service_.get())
1354 csd_service_->SetEnabledAndRefreshState(enable); 1458 csd_service_->SetEnabledAndRefreshState(enable);
1355 if (download_service_.get()) { 1459 if (download_service_.get()) {
1356 download_service_->SetEnabled( 1460 download_service_->SetEnabled(
1357 enable && !CommandLine::ForCurrentProcess()->HasSwitch( 1461 enable && !CommandLine::ForCurrentProcess()->HasSwitch(
1358 switches::kDisableImprovedDownloadProtection)); 1462 switches::kDisableImprovedDownloadProtection));
1359 } 1463 }
1360 } 1464 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698