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 #include "chrome/common/render_messages.h" |
| 10 |
| 11 using base::Time; |
| 12 using base::TimeDelta; |
| 13 |
| 14 // The amount of time we wait to accumulate visited link additions. |
| 15 static const int kCommitIntervalMs = 100; |
| 16 |
| 17 void VisitedLinkEventListener::NewTable(base::SharedMemory* table_memory) { |
| 18 if (!table_memory) |
| 19 return; |
| 20 |
| 21 // Send to all RenderProcessHosts. |
| 22 for (RenderProcessHost::iterator i = RenderProcessHost::begin(); |
| 23 i != RenderProcessHost::end(); ++i) { |
| 24 if (!i->second->HasConnection()) |
| 25 continue; |
| 26 |
| 27 base::SharedMemoryHandle new_table; |
| 28 base::ProcessHandle process = i->second->process().handle(); |
| 29 if (!process) { |
| 30 // process can be null if it's started with the --single-process flag. |
| 31 process = base::Process::Current().handle(); |
| 32 } |
| 33 |
| 34 table_memory->ShareToProcess(process, &new_table); |
| 35 i->second->Send(new ViewMsg_VisitedLink_NewTable(new_table)); |
| 36 } |
| 37 } |
| 38 |
| 39 void VisitedLinkEventListener::Add(VisitedLinkMaster::Fingerprint fingerprint) { |
| 40 pending_visited_links_.push_back(fingerprint); |
| 41 |
| 42 if (!coalesce_timer_.IsRunning()) { |
| 43 coalesce_timer_.Start( |
| 44 TimeDelta::FromMilliseconds(kCommitIntervalMs), this, |
| 45 &VisitedLinkEventListener::CommitVisitedLinks); |
| 46 } |
| 47 } |
| 48 |
| 49 void VisitedLinkEventListener::Reset() { |
| 50 pending_visited_links_.clear(); |
| 51 coalesce_timer_.Stop(); |
| 52 |
| 53 // Send to all RenderProcessHosts. |
| 54 for (RenderProcessHost::iterator i = RenderProcessHost::begin(); |
| 55 i != RenderProcessHost::end(); ++i) { |
| 56 i->second->ResetVisitedLinks(); |
| 57 } |
| 58 } |
| 59 |
| 60 void VisitedLinkEventListener::CommitVisitedLinks() { |
| 61 // Send to all RenderProcessHosts. |
| 62 for (RenderProcessHost::iterator i = RenderProcessHost::begin(); |
| 63 i != RenderProcessHost::end(); ++i) { |
| 64 i->second->AddVisitedLinks(pending_visited_links_); |
| 65 } |
| 66 |
| 67 pending_visited_links_.clear(); |
| 68 } |
OLD | NEW |