Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / safe_browsing / incident_reporting / incident_reporting_service.cc
index 7685162..30e5beb 100644 (file)
@@ -25,6 +25,7 @@
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/safe_browsing/database_manager.h"
 #include "chrome/browser/safe_browsing/incident_reporting/binary_integrity_incident_handlers.h"
+#include "chrome/browser/safe_browsing/incident_reporting/blacklist_load_incident_handlers.h"
 #include "chrome/browser/safe_browsing/incident_reporting/environment_data_collection.h"
 #include "chrome/browser/safe_browsing/incident_reporting/incident_report_uploader_impl.h"
 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_delegate.h"
@@ -47,8 +48,9 @@ enum IncidentType {
   // the histogram.
   TRACKED_PREFERENCE = 1,
   BINARY_INTEGRITY = 2,
+  BLACKLIST_LOAD = 3,
   // Values for new incident types go here.
-  NUM_INCIDENT_TYPES
+  NUM_INCIDENT_TYPES = 4
 };
 
 // The action taken for an incident; used for user metrics (see
@@ -85,6 +87,8 @@ size_t CountIncidents(const ClientIncidentReport_IncidentData& incident) {
     ++result;
   if (incident.has_binary_integrity())
     ++result;
+  if (incident.has_blacklist_load())
+    ++result;
   // Add detection for new incident types here.
   return result;
 }
@@ -96,9 +100,11 @@ IncidentType GetIncidentType(
     return TRACKED_PREFERENCE;
   if (incident_data.has_binary_integrity())
     return BINARY_INTEGRITY;
+  if (incident_data.has_blacklist_load())
+    return BLACKLIST_LOAD;
 
   // Add detection for new incident types here.
-  COMPILE_ASSERT(BINARY_INTEGRITY + 1 == NUM_INCIDENT_TYPES,
+  COMPILE_ASSERT(BLACKLIST_LOAD + 1 == NUM_INCIDENT_TYPES,
                  add_support_for_new_types);
   NOTREACHED();
   return NUM_INCIDENT_TYPES;
@@ -131,9 +137,13 @@ PersistentIncidentState ComputeIncidentState(
       state.key = GetBinaryIntegrityIncidentKey(incident);
       state.digest = GetBinaryIntegrityIncidentDigest(incident);
       break;
+    case BLACKLIST_LOAD:
+      state.key = GetBlacklistLoadIncidentKey(incident);
+      state.digest = GetBlacklistLoadIncidentDigest(incident);
+      break;
     // Add handling for new incident types here.
     default:
-      COMPILE_ASSERT(BINARY_INTEGRITY + 1 == NUM_INCIDENT_TYPES,
+      COMPILE_ASSERT(BLACKLIST_LOAD + 1 == NUM_INCIDENT_TYPES,
                      add_support_for_new_types);
       NOTREACHED();
       break;
@@ -428,6 +438,10 @@ scoped_ptr<IncidentReportUploader> IncidentReportingService::StartReportUpload(
              callback, request_context_getter, report).Pass();
 }
 
+bool IncidentReportingService::IsProcessingReport() const {
+  return report_ != NULL;
+}
+
 IncidentReportingService::ProfileContext*
 IncidentReportingService::GetOrCreateProfileContext(Profile* profile) {
   ProfileContextCollection::iterator it =
@@ -670,11 +684,11 @@ bool IncidentReportingService::WaitingForMostRecentDownload() {
   // The next easy case: waiting if the finder is operating.
   if (last_download_finder_)
     return true;
-  // The harder case: waiting if a profile has not yet been added.
+  // The harder case: waiting if a non-NULL profile has not yet been added.
   for (ProfileContextCollection::const_iterator scan = profiles_.begin();
        scan != profiles_.end();
        ++scan) {
-    if (!scan->second->added)
+    if (scan->first && !scan->second->added)
       return true;
   }
   // There is no most recent download and there's nothing more to wait for.
@@ -844,7 +858,7 @@ void IncidentReportingService::UploadIfCollectionComplete() {
 
   scoped_ptr<UploadContext> context(new UploadContext(report.Pass()));
   context->profiles_to_state.swap(profiles_to_state);
-  if (!database_manager_) {
+  if (!database_manager_.get()) {
     // No database manager during testing. Take ownership of the context and
     // continue processing.
     UploadContext* temp_context = context.get();