Remove prerender cookie store, part 2.

This removes cookie-based prerender histograms which are no longer necessary.
It reverts:

https://codereview.chromium.org/203783002
https://codereview.chromium.org/145063002
https://codereview.chromium.org/133913003

BUG=457344

Review URL: https://codereview.chromium.org/1007943002

Cr-Commit-Position: refs/heads/master@{#320620}
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index 5f9137e..0bb15bbd 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -1613,7 +1613,7 @@
   BrowserThread::PostTask(
       BrowserThread::UI, FROM_HERE,
       base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
-                 render_frame_id, url, first_party, cookie_list, !allow, true));
+                 render_frame_id, url, first_party, cookie_list, !allow));
   return allow;
 }
 
diff --git a/chrome/browser/content_settings/tab_specific_content_settings.cc b/chrome/browser/content_settings/tab_specific_content_settings.cc
index f41deb05..e1d8a63 100644
--- a/chrome/browser/content_settings/tab_specific_content_settings.cc
+++ b/chrome/browser/content_settings/tab_specific_content_settings.cc
@@ -21,8 +21,8 @@
 #include "chrome/browser/browsing_data/cookies_tree_model.h"
 #include "chrome/browser/chrome_notification_types.h"
 #include "chrome/browser/content_settings/chrome_content_settings_utils.h"
+#include "chrome/browser/media/media_capture_devices_dispatcher.h"
 #include "chrome/browser/media/media_stream_capture_indicator.h"
-#include "chrome/browser/prerender/prerender_manager.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/common/chrome_switches.h"
 #include "chrome/common/pref_names.h"
@@ -155,8 +155,7 @@
                                              const GURL& url,
                                              const GURL& frame_url,
                                              const net::CookieList& cookie_list,
-                                             bool blocked_by_policy,
-                                             bool is_for_blocking_resource) {
+                                             bool blocked_by_policy) {
   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
   TabSpecificContentSettings* settings =
       GetForFrame(render_process_id, render_frame_id);
@@ -164,14 +163,6 @@
     settings->OnCookiesRead(url, frame_url, cookie_list,
                             blocked_by_policy);
   }
-  prerender::PrerenderManager::RecordCookieEvent(
-      render_process_id,
-      render_frame_id,
-      url,
-      frame_url,
-      is_for_blocking_resource,
-      prerender::PrerenderContents::COOKIE_EVENT_SEND,
-      &cookie_list);
 }
 
 // static
@@ -189,14 +180,6 @@
   if (settings)
     settings->OnCookieChanged(url, frame_url, cookie_line, options,
                               blocked_by_policy);
-  prerender::PrerenderManager::RecordCookieEvent(
-      render_process_id,
-      render_frame_id,
-      url,
-      frame_url,
-      false /*is_critical_request*/,
-      prerender::PrerenderContents::COOKIE_EVENT_CHANGE,
-      NULL);
 }
 
 // static
diff --git a/chrome/browser/content_settings/tab_specific_content_settings.h b/chrome/browser/content_settings/tab_specific_content_settings.h
index cc2e2001..2a6705b 100644
--- a/chrome/browser/content_settings/tab_specific_content_settings.h
+++ b/chrome/browser/content_settings/tab_specific_content_settings.h
@@ -92,17 +92,12 @@
   // current page or while loading it. |blocked_by_policy| should be true, if
   // reading cookies was blocked due to the user's content settings. In that
   // case, this function should invoke OnContentBlocked.
-  // |is_for_blocking_resource| indicates whether the cookies read were for a
-  // blocking resource (eg script, css). It is only temporarily added for
-  // diagnostic purposes, per bug 353678. Will be removed again once data
-  // collection is finished.
   static void CookiesRead(int render_process_id,
                           int render_frame_id,
                           const GURL& url,
                           const GURL& first_party_url,
                           const net::CookieList& cookie_list,
-                          bool blocked_by_policy,
-                          bool is_for_blocking_resource);
+                          bool blocked_by_policy);
 
   // Called when a specific cookie in the current page was changed.
   // |blocked_by_policy| should be true, if the cookie was blocked due to the
diff --git a/chrome/browser/net/chrome_network_delegate.cc b/chrome/browser/net/chrome_network_delegate.cc
index eaa1595a..fbc7d30 100644
--- a/chrome/browser/net/chrome_network_delegate.cc
+++ b/chrome/browser/net/chrome_network_delegate.cc
@@ -568,19 +568,6 @@
 
   int render_process_id = -1;
   int render_frame_id = -1;
-
-  // |is_for_blocking_resource| indicates whether the cookies read were for a
-  // blocking resource (eg script, css). It is only temporarily added for
-  // diagnostic purposes, per bug 353678. Will be removed again once data
-  // collection is finished.
-  bool is_for_blocking_resource = false;
-  const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(&request);
-  if (info && ((!info->IsAsync()) ||
-               info->GetResourceType() == content::RESOURCE_TYPE_STYLESHEET ||
-               info->GetResourceType() == content::RESOURCE_TYPE_SCRIPT)) {
-    is_for_blocking_resource = true;
-  }
-
   if (content::ResourceRequestInfo::GetRenderFrameForRequest(
           &request, &render_process_id, &render_frame_id)) {
     BrowserThread::PostTask(
@@ -588,7 +575,7 @@
         base::Bind(&TabSpecificContentSettings::CookiesRead,
                    render_process_id, render_frame_id,
                    request.url(), request.first_party_for_cookies(),
-                   cookie_list, !allow, is_for_blocking_resource));
+                   cookie_list, !allow));
   }
 
   return allow;
diff --git a/chrome/browser/prerender/prerender_contents.cc b/chrome/browser/prerender/prerender_contents.cc
index 8ee8ed8..4795fa6 100644
--- a/chrome/browser/prerender/prerender_contents.cc
+++ b/chrome/browser/prerender/prerender_contents.cc
@@ -53,31 +53,6 @@
 
 namespace {
 
-// Internal cookie event.
-// Whenever a prerender interacts with the cookie store, either sending
-// existing cookies that existed before the prerender started, or when a cookie
-// is changed, we record these events for histogramming purposes.
-enum InternalCookieEvent {
-  INTERNAL_COOKIE_EVENT_MAIN_FRAME_SEND = 0,
-  INTERNAL_COOKIE_EVENT_MAIN_FRAME_CHANGE = 1,
-  INTERNAL_COOKIE_EVENT_OTHER_SEND = 2,
-  INTERNAL_COOKIE_EVENT_OTHER_CHANGE = 3,
-  INTERNAL_COOKIE_EVENT_MAX
-};
-
-// Indicates whether existing cookies were sent, and if they were third party
-// cookies, and whether they were for blocking resources.
-// Each value may be inclusive of previous values. We only care about the
-// value with the highest index that has ever occurred in the course of a
-// prerender.
-enum CookieSendType {
-  COOKIE_SEND_TYPE_NONE = 0,
-  COOKIE_SEND_TYPE_FIRST_PARTY = 1,
-  COOKIE_SEND_TYPE_THIRD_PARTY = 2,
-  COOKIE_SEND_TYPE_THIRD_PARTY_BLOCKING_RESOURCE = 3,
-  COOKIE_SEND_TYPE_MAX
-};
-
 void ResumeThrottles(
     std::vector<base::WeakPtr<PrerenderResourceThrottle> > throttles) {
   for (size_t i = 0; i < throttles.size(); i++) {
@@ -88,13 +63,6 @@
 
 }  // namespace
 
-// static
-const int PrerenderContents::kNumCookieStatuses =
-    (1 << INTERNAL_COOKIE_EVENT_MAX);
-
-// static
-const int PrerenderContents::kNumCookieSendTypes = COOKIE_SEND_TYPE_MAX;
-
 class PrerenderContentsFactoryImpl : public PrerenderContents::Factory {
  public:
   PrerenderContents* CreatePrerenderContents(
@@ -239,8 +207,6 @@
       route_id_(-1),
       origin_(origin),
       experiment_id_(experiment_id),
-      cookie_status_(0),
-      cookie_send_type_(COOKIE_SEND_TYPE_NONE),
       network_bytes_(0) {
   DCHECK(prerender_manager != NULL);
 }
@@ -304,7 +270,6 @@
 
   DCHECK(load_start_time_.is_null());
   load_start_time_ = base::TimeTicks::Now();
-  start_time_ = base::Time::Now();
 
   // Everything after this point sets up the WebContents object and associated
   // RenderView for the prerender page. Don't do this for members of the
@@ -401,15 +366,7 @@
   DCHECK(
       prerendering_has_been_cancelled() || final_status() == FINAL_STATUS_USED);
   DCHECK_NE(ORIGIN_MAX, origin());
-  // Since a lot of prerenders terminate before any meaningful cookie action
-  // would have happened, only record the cookie status for prerenders who
-  // were used, cancelled, or timed out.
-  if (prerendering_has_started_ && final_status() == FINAL_STATUS_USED) {
-    prerender_manager_->RecordCookieStatus(origin(), experiment_id(),
-                                           cookie_status_);
-    prerender_manager_->RecordCookieSendType(origin(), experiment_id(),
-                                             cookie_send_type_);
-  }
+
   prerender_manager_->RecordFinalStatusWithMatchCompleteStatus(
       origin(), experiment_id(), match_complete_status(), final_status());
 
@@ -789,74 +746,13 @@
   Destroy(FINAL_STATUS_WINDOW_PRINT);
 }
 
-void PrerenderContents::RecordCookieEvent(CookieEvent event,
-                                          bool is_main_frame_http_request,
-                                          bool is_third_party_cookie,
-                                          bool is_for_blocking_resource,
-                                          base::Time earliest_create_date) {
-  // We don't care about sent cookies that were created after this prerender
-  // started.
-  // The reason is that for the purpose of the histograms emitted, we only care
-  // about cookies that existed before the prerender was started, but not
-  // about cookies that were created as part of the prerender. Using the
-  // earliest creation timestamp of all cookies provided by the cookie monster
-  // is a heuristic that yields the desired result pretty closely.
-  // In particular, we pretend no other WebContents make changes to the cookies
-  // relevant to the prerender, which may not actually always be the case, but
-  // hopefully most of the times.
-  if (event == COOKIE_EVENT_SEND && earliest_create_date > start_time_)
-    return;
-
-  InternalCookieEvent internal_event = INTERNAL_COOKIE_EVENT_MAX;
-
-  if (is_main_frame_http_request) {
-    if (event == COOKIE_EVENT_SEND) {
-      internal_event = INTERNAL_COOKIE_EVENT_MAIN_FRAME_SEND;
-    } else {
-      internal_event = INTERNAL_COOKIE_EVENT_MAIN_FRAME_CHANGE;
-    }
-  } else {
-    if (event == COOKIE_EVENT_SEND) {
-      internal_event = INTERNAL_COOKIE_EVENT_OTHER_SEND;
-    } else {
-      internal_event = INTERNAL_COOKIE_EVENT_OTHER_CHANGE;
-    }
-  }
-
-  DCHECK_GE(internal_event, 0);
-  DCHECK_LT(internal_event, INTERNAL_COOKIE_EVENT_MAX);
-
-  cookie_status_ |= (1 << internal_event);
-
-  DCHECK_GE(cookie_status_, 0);
-  DCHECK_LT(cookie_status_, kNumCookieStatuses);
-
-  CookieSendType send_type = COOKIE_SEND_TYPE_NONE;
-  if (event == COOKIE_EVENT_SEND) {
-    if (!is_third_party_cookie) {
-      send_type = COOKIE_SEND_TYPE_FIRST_PARTY;
-    } else {
-      if (is_for_blocking_resource) {
-        send_type = COOKIE_SEND_TYPE_THIRD_PARTY_BLOCKING_RESOURCE;
-      } else {
-        send_type = COOKIE_SEND_TYPE_THIRD_PARTY;
-      }
-    }
-  }
-  DCHECK_GE(send_type, 0);
-  DCHECK_LT(send_type, COOKIE_SEND_TYPE_MAX);
-
-  if (cookie_send_type_ < send_type)
-    cookie_send_type_ = send_type;
+void PrerenderContents::AddResourceThrottle(
+    const base::WeakPtr<PrerenderResourceThrottle>& throttle) {
+  resource_throttles_.push_back(throttle);
 }
 
- void PrerenderContents::AddResourceThrottle(
-     const base::WeakPtr<PrerenderResourceThrottle>& throttle) {
-   resource_throttles_.push_back(throttle);
- }
-
- void PrerenderContents::AddNetworkBytes(int64 bytes) {
-   network_bytes_ += bytes;
- }
+void PrerenderContents::AddNetworkBytes(int64 bytes) {
+  network_bytes_ += bytes;
+}
 
 }  // namespace prerender
diff --git a/chrome/browser/prerender/prerender_contents.h b/chrome/browser/prerender/prerender_contents.h
index e8fe6244..a5ea93d7 100644
--- a/chrome/browser/prerender/prerender_contents.h
+++ b/chrome/browser/prerender/prerender_contents.h
@@ -259,25 +259,6 @@
   // Marks prerender as used and releases any throttled resource requests.
   void PrepareForUse();
 
-  // Cookie events
-  enum CookieEvent {
-    COOKIE_EVENT_SEND = 0,
-    COOKIE_EVENT_CHANGE = 1,
-    COOKIE_EVENT_MAX
-  };
-
-  // Record a cookie transaction for this prerender contents.
-  // In the event of cookies being sent, |earliest_create_date| contains
-  // the time that the earliest of the cookies sent was created.
-  void RecordCookieEvent(CookieEvent event,
-                         bool is_main_frame_http_request,
-                         bool is_third_party_cookie,
-                         bool is_for_blocking_resource,
-                         base::Time earliest_create_date);
-
-  static const int kNumCookieStatuses;
-  static const int kNumCookieSendTypes;
-
   // Called when a PrerenderResourceThrottle defers a request. If the prerender
   // is used it'll be resumed on the IO thread, otherwise they will get
   // cancelled automatically if prerendering is cancelled.
@@ -340,10 +321,6 @@
   // we won't have a RenderViewHost.
   int64 session_storage_namespace_id_;
 
-  // The time at which we started prerendering, for the purpose of comparing
-  // cookie creation times.
-  base::Time start_time_;
-
  private:
   class WebContentsDelegateImpl;
 
@@ -425,15 +402,6 @@
   // Caches pages to be added to the history.
   AddPageVector add_page_vector_;
 
-  // Indicates what internal cookie events (see prerender_contents.cc) have
-  // occurred, using 1 bit for each possible InternalCookieEvent.
-  int cookie_status_;
-
-  // Indicates whether existing cookies were sent for this prerender, and
-  // whether they were third-party cookies, and whether they were for blocking
-  // resources. See the enum CookieSendType in prerender_contents.cc
-  int cookie_send_type_;
-
   // Resources that are throttled, pending a prerender use. Can only access a
   // throttle on the IO thread.
   std::vector<base::WeakPtr<PrerenderResourceThrottle> > resource_throttles_;
diff --git a/chrome/browser/prerender/prerender_histograms.cc b/chrome/browser/prerender/prerender_histograms.cc
index a45c835..616592be 100644
--- a/chrome/browser/prerender/prerender_histograms.cc
+++ b/chrome/browser/prerender/prerender_histograms.cc
@@ -398,29 +398,6 @@
   }
 }
 
-void PrerenderHistograms::RecordCookieStatus(Origin origin,
-                                             uint8 experiment_id,
-                                             int cookie_status) const {
-  DCHECK_GE(cookie_status, 0);
-  DCHECK_LT(cookie_status, PrerenderContents::kNumCookieStatuses);
-  PREFIXED_HISTOGRAM_ORIGIN_EXPERIMENT(
-      "CookieStatus", origin, experiment_id,
-      UMA_HISTOGRAM_ENUMERATION(name, cookie_status,
-                                PrerenderContents::kNumCookieStatuses));
-}
-
-void PrerenderHistograms::RecordCookieSendType(
-    Origin origin,
-    uint8 experiment_id,
-    int cookie_send_type) const {
-  DCHECK_GE(cookie_send_type, 0);
-  DCHECK_LT(cookie_send_type, PrerenderContents::kNumCookieSendTypes);
-  PREFIXED_HISTOGRAM_ORIGIN_EXPERIMENT(
-      "CookieSendType", origin, experiment_id,
-      UMA_HISTOGRAM_ENUMERATION(name, cookie_send_type,
-                                PrerenderContents::kNumCookieSendTypes));
-}
-
 void PrerenderHistograms::RecordPrerenderPageVisitedStatus(
     Origin origin,
     uint8 experiment_id,
diff --git a/chrome/browser/prerender/prerender_histograms.h b/chrome/browser/prerender/prerender_histograms.h
index 9e08bb9b..889cdbd 100644
--- a/chrome/browser/prerender/prerender_histograms.h
+++ b/chrome/browser/prerender/prerender_histograms.h
@@ -99,18 +99,6 @@
   void RecordTimeSinceLastRecentVisit(Origin origin,
                                       base::TimeDelta time) const;
 
-  // Record a prerender cookie status bitmap. Must be in the range
-  // [0, PrerenderContents::kNumCookieStatuses).
-  void RecordCookieStatus(Origin origin,
-                          uint8 experiment_id,
-                          int cookie_status) const;
-
-  // Record a prerender cookie send type. Must be in the range
-  // [0, PrerenderContents::kNumCookieSendTypes).
-  void RecordCookieSendType(Origin origin,
-                            uint8 experiment_id,
-                            int cookie_send_type) const;
-
   void RecordPrerenderPageVisitedStatus(Origin origin,
                                         uint8 experiment_id,
                                         bool visited_before) const;
diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc
index 65d828e..4feae2be1 100644
--- a/chrome/browser/prerender/prerender_manager.cc
+++ b/chrome/browser/prerender/prerender_manager.cc
@@ -60,13 +60,11 @@
 #include "content/public/browser/web_contents_delegate.h"
 #include "content/public/common/url_constants.h"
 #include "extensions/common/constants.h"
-#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
 #include "net/url_request/url_request_context.h"
 #include "net/url_request/url_request_context_getter.h"
 
 using content::BrowserThread;
 using content::RenderViewHost;
-using content::RenderFrameHost;
 using content::SessionStorageNamespace;
 using content::WebContents;
 using predictors::LoggedInPredictorTable;
@@ -1477,64 +1475,6 @@
   logged_in_state_.swap(new_map);
 }
 
-// static
-void PrerenderManager::RecordCookieEvent(int process_id,
-                                         int frame_id,
-                                         const GURL& url,
-                                         const GURL& frame_url,
-                                         bool is_for_blocking_resource,
-                                         PrerenderContents::CookieEvent event,
-                                         const net::CookieList* cookie_list) {
-  RenderFrameHost* rfh = RenderFrameHost::FromID(process_id, frame_id);
-  WebContents* web_contents = WebContents::FromRenderFrameHost(rfh);
-  if (!web_contents)
-    return;
-
-  bool is_main_frame = (rfh == web_contents->GetMainFrame());
-
-  bool is_third_party_cookie =
-    (!frame_url.is_empty() &&
-     !net::registry_controlled_domains::SameDomainOrHost(
-         url, frame_url,
-         net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
-
-  PrerenderContents* prerender_contents =
-      PrerenderContents::FromWebContents(web_contents);
-
-  if (!prerender_contents)
-    return;
-
-  base::Time earliest_create_date;
-  if (event == PrerenderContents::COOKIE_EVENT_SEND) {
-    if (!cookie_list || cookie_list->empty())
-      return;
-    for (size_t i = 0; i < cookie_list->size(); i++) {
-      if (earliest_create_date.is_null() ||
-          (*cookie_list)[i].CreationDate() < earliest_create_date) {
-        earliest_create_date = (*cookie_list)[i].CreationDate();
-      }
-    }
-  }
-
-  prerender_contents->RecordCookieEvent(event,
-                                        is_main_frame && url == frame_url,
-                                        is_third_party_cookie,
-                                        is_for_blocking_resource,
-                                        earliest_create_date);
-}
-
-void PrerenderManager::RecordCookieStatus(Origin origin,
-                                          uint8 experiment_id,
-                                          int cookie_status) const {
-  histograms_->RecordCookieStatus(origin, experiment_id, cookie_status);
-}
-
-void PrerenderManager::RecordCookieSendType(Origin origin,
-                                            uint8 experiment_id,
-                                            int cookie_send_type) const {
-  histograms_->RecordCookieSendType(origin, experiment_id, cookie_send_type);
-}
-
 void PrerenderManager::OnHistoryServiceDidQueryURL(
     Origin origin,
     uint8 experiment_id,
diff --git a/chrome/browser/prerender/prerender_manager.h b/chrome/browser/prerender/prerender_manager.h
index 5dd1c08..f1a0c7ed 100644
--- a/chrome/browser/prerender/prerender_manager.h
+++ b/chrome/browser/prerender/prerender_manager.h
@@ -29,7 +29,6 @@
 #include "content/public/browser/notification_observer.h"
 #include "content/public/browser/notification_registrar.h"
 #include "content/public/browser/render_process_host_observer.h"
-#include "net/cookies/canonical_cookie.h"
 #include "net/cookies/cookie_monster.h"
 #include "url/gurl.h"
 
@@ -258,16 +257,6 @@
       PrerenderContents::MatchCompleteStatus mc_status,
       FinalStatus final_status) const;
 
-  // Record a cookie status histogram (see prerender_histograms.h).
-  void RecordCookieStatus(Origin origin,
-                          uint8 experiment_id,
-                          int cookie_status) const;
-
-  // Record a cookie send type histogram (see prerender_histograms.h).
-  void RecordCookieSendType(Origin origin,
-                            uint8 experiment_id,
-                            int cookie_send_type) const;
-
   // content::NotificationObserver
   void Observe(int type,
                const content::NotificationSource& source,
@@ -318,17 +307,6 @@
     return local_predictor_.get();
   }
 
-  // Notification that a cookie event happened on a render frame. Will record a
-  // cookie event for a given render frame, if it is being prerendered.
-  // If cookies were sent, all cookies must be supplied in |cookie_list|.
-  static void RecordCookieEvent(int process_id,
-                                int frame_id,
-                                const GURL& url,
-                                const GURL& frame_url,
-                                bool is_for_blocking_resource,
-                                PrerenderContents::CookieEvent event,
-                                const net::CookieList* cookie_list);
-
   // Notification that a prerender has completed and its bytes should be
   // recorded.
   void RecordNetworkBytes(Origin origin, bool used, int64 prerender_bytes);
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index 853473c..612cfe7 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -27911,6 +27911,9 @@
 </histogram>
 
 <histogram name="Prerender.CookieSendType" enum="PrerenderCookieSendType">
+  <obsolete>
+    Deprecated March 13 2015.
+  </obsolete>
   <owner>[email protected]</owner>
   <summary>
     Enumeration of what types of cookies were sent for a prerender.
@@ -27918,6 +27921,9 @@
 </histogram>
 
 <histogram name="Prerender.CookieStatus" enum="PrerenderCookieStatus">
+  <obsolete>
+    Deprecated March 13 2015.
+  </obsolete>
   <owner>[email protected]</owner>
   <summary>Enumeration of what cookie actions a prerender caused.</summary>
 </histogram>