OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/visitedlink_event_listener.h" | 5 #include "chrome/browser/visitedlink_event_listener.h" |
6 | 6 |
7 #include "base/shared_memory.h" | 7 #include "base/shared_memory.h" |
8 #include "chrome/browser/renderer_host/render_process_host.h" | 8 #include "chrome/browser/renderer_host/render_process_host.h" |
9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
10 | 10 |
11 using base::Time; | 11 using base::Time; |
12 using base::TimeDelta; | 12 using base::TimeDelta; |
13 | 13 |
14 // The amount of time we wait to accumulate visited link additions. | 14 // The amount of time we wait to accumulate visited link additions. |
15 static const int kCommitIntervalMs = 100; | 15 static const int kCommitIntervalMs = 100; |
16 | 16 |
17 void VisitedLinkEventListener::NewTable(base::SharedMemory* table_memory) { | 17 void VisitedLinkEventListener::NewTable(base::SharedMemory* table_memory) { |
18 if (!table_memory) | 18 if (!table_memory) |
19 return; | 19 return; |
20 | 20 |
21 // Send to all RenderProcessHosts. | 21 // Send to all RenderProcessHosts. |
22 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 22 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
23 !i.IsAtEnd(); i.Advance()) { | 23 !i.IsAtEnd(); i.Advance()) { |
24 if (!i.GetCurrentValue()->HasConnection()) | 24 if (!i.GetCurrentValue()->HasConnection()) |
25 continue; | 25 continue; |
26 | 26 |
27 base::SharedMemoryHandle new_table; | 27 i.GetCurrentValue()->SendVisitedLinkTable(table_memory); |
28 base::ProcessHandle process = i.GetCurrentValue()->GetHandle(); | |
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.GetCurrentValue()->Send(new ViewMsg_VisitedLink_NewTable(new_table)); | |
36 } | 28 } |
37 } | 29 } |
38 | 30 |
39 void VisitedLinkEventListener::Add(VisitedLinkMaster::Fingerprint fingerprint) { | 31 void VisitedLinkEventListener::Add(VisitedLinkMaster::Fingerprint fingerprint) { |
40 pending_visited_links_.push_back(fingerprint); | 32 pending_visited_links_.push_back(fingerprint); |
41 | 33 |
42 if (!coalesce_timer_.IsRunning()) { | 34 if (!coalesce_timer_.IsRunning()) { |
43 coalesce_timer_.Start( | 35 coalesce_timer_.Start( |
44 TimeDelta::FromMilliseconds(kCommitIntervalMs), this, | 36 TimeDelta::FromMilliseconds(kCommitIntervalMs), this, |
45 &VisitedLinkEventListener::CommitVisitedLinks); | 37 &VisitedLinkEventListener::CommitVisitedLinks); |
(...skipping 13 matching lines...) Expand all Loading... |
59 | 51 |
60 void VisitedLinkEventListener::CommitVisitedLinks() { | 52 void VisitedLinkEventListener::CommitVisitedLinks() { |
61 // Send to all RenderProcessHosts. | 53 // Send to all RenderProcessHosts. |
62 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 54 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
63 !i.IsAtEnd(); i.Advance()) { | 55 !i.IsAtEnd(); i.Advance()) { |
64 i.GetCurrentValue()->AddVisitedLinks(pending_visited_links_); | 56 i.GetCurrentValue()->AddVisitedLinks(pending_visited_links_); |
65 } | 57 } |
66 | 58 |
67 pending_visited_links_.clear(); | 59 pending_visited_links_.clear(); |
68 } | 60 } |
OLD | NEW |