Home | History | Annotate | Download | only in history
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_HISTORY_VISIT_TRACKER_H__
      6 #define CHROME_BROWSER_HISTORY_VISIT_TRACKER_H__
      7 #pragma once
      8 
      9 #include <map>
     10 #include <vector>
     11 
     12 #include "base/basictypes.h"
     13 #include "chrome/browser/history/history_types.h"
     14 
     15 namespace history {
     16 
     17 // Tracks history transitions between pages. The history backend uses this to
     18 // link up page transitions to form a chain of page visits, and to set the
     19 // transition type properly.
     20 //
     21 // This class is not thread safe.
     22 class VisitTracker {
     23  public:
     24   VisitTracker();
     25   ~VisitTracker();
     26 
     27   // Notifications -------------------------------------------------------------
     28 
     29   void AddVisit(const void* host,
     30                 int32 page_id,
     31                 const GURL& url,
     32                 VisitID visit_id);
     33 
     34   // When a RenderProcessHost is destroyed, we want to clear out our saved
     35   // transitions/visit IDs for it.
     36   void NotifyRenderProcessHostDestruction(const void* host);
     37 
     38   // Querying ------------------------------------------------------------------
     39 
     40   // Returns the visit ID for the transition given information about the visit
     41   // supplied by the renderer. We will return 0 if there is no appropriate
     42   // referring visit.
     43   VisitID GetLastVisit(const void* host, int32 page_id, const GURL& url);
     44 
     45  private:
     46   struct Transition {
     47     GURL url;          // URL that the event happened to.
     48     int32 page_id;     // ID generated by the render process host.
     49     VisitID visit_id;  // Visit ID generated by history.
     50   };
     51   typedef std::vector<Transition> TransitionList;
     52   typedef std::map<const void*, TransitionList*> HostList;
     53 
     54   // Expires oldish items in the given transition list. This keeps the list
     55   // size small by removing items that are unlikely to be needed, which is
     56   // important for GetReferrer which does brute-force searches of this list.
     57   void CleanupTransitionList(TransitionList* transitions);
     58 
     59   // Maps render view hosts to lists of recent transitions.
     60   HostList hosts_;
     61 
     62   DISALLOW_COPY_AND_ASSIGN(VisitTracker);
     63 };
     64 
     65 }  // namespace history
     66 
     67 #endif  // CHROME_BROWSER_HISTORY_VISIT_TRACKER_H__
     68