OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/incident_reporting/incident_reporting_ser
vice.h" | 5 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser
vice.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
14 #include "base/prefs/scoped_user_pref_update.h" | 14 #include "base/prefs/scoped_user_pref_update.h" |
15 #include "base/process/process_info.h" | 15 #include "base/process/process_info.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
20 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
21 #include "base/values.h" | 21 #include "base/values.h" |
22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
23 #include "chrome/browser/chrome_notification_types.h" | 23 #include "chrome/browser/chrome_notification_types.h" |
24 #include "chrome/browser/prefs/tracked/tracked_preference_validation_delegate.h" | 24 #include "chrome/browser/prefs/tracked/tracked_preference_validation_delegate.h" |
25 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/browser/safe_browsing/database_manager.h" | 26 #include "chrome/browser/safe_browsing/database_manager.h" |
27 #include "chrome/browser/safe_browsing/incident_reporting/environment_data_colle
ction.h" | 27 #include "chrome/browser/safe_browsing/incident_reporting/environment_data_colle
ction.h" |
28 #include "chrome/browser/safe_browsing/incident_reporting/incident.h" | 28 #include "chrome/browser/safe_browsing/incident_reporting/incident.h" |
29 #include "chrome/browser/safe_browsing/incident_reporting/incident_report_upload
er_impl.h" | 29 #include "chrome/browser/safe_browsing/incident_reporting/incident_report_upload
er_impl.h" |
30 #include "chrome/browser/safe_browsing/incident_reporting/omnibox_watcher.h" | |
31 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_
delegate.h" | 30 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_
delegate.h" |
32 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 31 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
33 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
34 #include "chrome/common/safe_browsing/csd.pb.h" | 33 #include "chrome/common/safe_browsing/csd.pb.h" |
35 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
36 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
37 #include "net/url_request/url_request_context_getter.h" | 36 #include "net/url_request/url_request_context_getter.h" |
38 | 37 |
39 namespace safe_browsing { | 38 namespace safe_browsing { |
40 | 39 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } // namespace | 148 } // namespace |
150 | 149 |
151 struct IncidentReportingService::ProfileContext { | 150 struct IncidentReportingService::ProfileContext { |
152 ProfileContext(); | 151 ProfileContext(); |
153 ~ProfileContext(); | 152 ~ProfileContext(); |
154 | 153 |
155 // The incidents collected for this profile pending creation and/or upload. | 154 // The incidents collected for this profile pending creation and/or upload. |
156 // Will contain null values for pruned incidents. | 155 // Will contain null values for pruned incidents. |
157 ScopedVector<Incident> incidents; | 156 ScopedVector<Incident> incidents; |
158 | 157 |
159 // Watches for suspicious omnibox interactions on this profile. | |
160 scoped_ptr<OmniboxWatcher> omnibox_watcher; | |
161 | |
162 // False until PROFILE_ADDED notification is received. | 158 // False until PROFILE_ADDED notification is received. |
163 bool added; | 159 bool added; |
164 | 160 |
165 private: | 161 private: |
166 DISALLOW_COPY_AND_ASSIGN(ProfileContext); | 162 DISALLOW_COPY_AND_ASSIGN(ProfileContext); |
167 }; | 163 }; |
168 | 164 |
169 class IncidentReportingService::UploadContext { | 165 class IncidentReportingService::UploadContext { |
170 public: | 166 public: |
171 typedef std::map<Profile*, std::vector<PersistentIncidentState> > | 167 typedef std::map<Profile*, std::vector<PersistentIncidentState> > |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 } | 353 } |
358 } | 354 } |
359 | 355 |
360 void IncidentReportingService::OnProfileAdded(Profile* profile) { | 356 void IncidentReportingService::OnProfileAdded(Profile* profile) { |
361 DCHECK(thread_checker_.CalledOnValidThread()); | 357 DCHECK(thread_checker_.CalledOnValidThread()); |
362 | 358 |
363 // Track the addition of all profiles even when no report is being assembled | 359 // Track the addition of all profiles even when no report is being assembled |
364 // so that the service can determine whether or not it can evaluate a | 360 // so that the service can determine whether or not it can evaluate a |
365 // profile's preferences at the time of incident addition. | 361 // profile's preferences at the time of incident addition. |
366 ProfileContext* context = GetOrCreateProfileContext(profile); | 362 ProfileContext* context = GetOrCreateProfileContext(profile); |
367 // Start watching the profile now if necessary. | |
368 if (!context->omnibox_watcher) { | |
369 context->omnibox_watcher.reset( | |
370 new OmniboxWatcher(profile, GetAddIncidentCallback(profile))); | |
371 } | |
372 context->added = true; | 363 context->added = true; |
373 | 364 |
374 const bool safe_browsing_enabled = | 365 const bool safe_browsing_enabled = |
375 profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled); | 366 profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled); |
376 | 367 |
377 // Start processing delayed analysis callbacks if this new profile | 368 // Start processing delayed analysis callbacks if this new profile |
378 // participates in safe browsing. Start is idempotent, so this is safe even if | 369 // participates in safe browsing. Start is idempotent, so this is safe even if |
379 // they're already running. | 370 // they're already running. |
380 if (safe_browsing_enabled) | 371 if (safe_browsing_enabled) |
381 delayed_analysis_callbacks_.Start(); | 372 delayed_analysis_callbacks_.Start(); |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 if (!profile->IsOffTheRecord()) | 922 if (!profile->IsOffTheRecord()) |
932 OnProfileDestroyed(profile); | 923 OnProfileDestroyed(profile); |
933 break; | 924 break; |
934 } | 925 } |
935 default: | 926 default: |
936 break; | 927 break; |
937 } | 928 } |
938 } | 929 } |
939 | 930 |
940 } // namespace safe_browsing | 931 } // namespace safe_browsing |
OLD | NEW |