| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 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 #include "chrome/browser/visitedlink_event_listener.h" | |
| 6 | |
| 7 #include "base/shared_memory.h" | |
| 8 #include "chrome/browser/renderer_host/render_process_host.h" | |
| 9 | |
| 10 using base::Time; | |
| 11 using base::TimeDelta; | |
| 12 | |
| 13 // The amount of time we wait to accumulate visited link additions. | |
| 14 static const int kCommitIntervalMs = 100; | |
| 15 | |
| 16 VisitedLinkEventListener::VisitedLinkEventListener() { | |
| 17 } | |
| 18 | |
| 19 VisitedLinkEventListener::~VisitedLinkEventListener() { | |
| 20 } | |
| 21 | |
| 22 void VisitedLinkEventListener::NewTable(base::SharedMemory* table_memory) { | |
| 23 if (!table_memory) | |
| 24 return; | |
| 25 | |
| 26 // Send to all RenderProcessHosts. | |
| 27 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | |
| 28 !i.IsAtEnd(); i.Advance()) { | |
| 29 if (!i.GetCurrentValue()->HasConnection()) | |
| 30 continue; | |
| 31 | |
| 32 i.GetCurrentValue()->SendVisitedLinkTable(table_memory); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 void VisitedLinkEventListener::Add(VisitedLinkMaster::Fingerprint fingerprint) { | |
| 37 pending_visited_links_.push_back(fingerprint); | |
| 38 | |
| 39 if (!coalesce_timer_.IsRunning()) { | |
| 40 coalesce_timer_.Start( | |
| 41 TimeDelta::FromMilliseconds(kCommitIntervalMs), this, | |
| 42 &VisitedLinkEventListener::CommitVisitedLinks); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 void VisitedLinkEventListener::Reset() { | |
| 47 pending_visited_links_.clear(); | |
| 48 coalesce_timer_.Stop(); | |
| 49 | |
| 50 // Send to all RenderProcessHosts. | |
| 51 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | |
| 52 !i.IsAtEnd(); i.Advance()) { | |
| 53 i.GetCurrentValue()->ResetVisitedLinks(); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 void VisitedLinkEventListener::CommitVisitedLinks() { | |
| 58 // Send to all RenderProcessHosts. | |
| 59 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | |
| 60 !i.IsAtEnd(); i.Advance()) { | |
| 61 i.GetCurrentValue()->AddVisitedLinks(pending_visited_links_); | |
| 62 } | |
| 63 | |
| 64 pending_visited_links_.clear(); | |
| 65 } | |
| OLD | NEW |