OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 // Represents the browser side of the browser <--> renderer communication | 5 // Represents the browser side of the browser <--> renderer communication |
6 // channel. There will be one RenderProcessHost per renderer process. | 6 // channel. There will be one RenderProcessHost per renderer process. |
7 | 7 |
8 #include "chrome/browser/renderer_host/browser_render_process_host.h" | 8 #include "chrome/browser/renderer_host/browser_render_process_host.h" |
9 | 9 |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 CoUninitialize(); | 116 CoUninitialize(); |
117 #endif | 117 #endif |
118 } | 118 } |
119 | 119 |
120 private: | 120 private: |
121 std::string channel_id_; | 121 std::string channel_id_; |
122 // Deleted in CleanUp() on the renderer thread, so don't use a smart pointer. | 122 // Deleted in CleanUp() on the renderer thread, so don't use a smart pointer. |
123 RenderProcess* render_process_; | 123 RenderProcess* render_process_; |
124 }; | 124 }; |
125 | 125 |
| 126 |
| 127 // Size of the buffer after which individual link updates deemed not warranted |
| 128 // and the overall update should be used instead. |
| 129 static const unsigned kVisitedLinkBufferThreshold = 50; |
| 130 |
| 131 // This class manages buffering and sending visited link hashes (fingerprints) |
| 132 // to renderer based on widget visibility. |
| 133 // As opposed to the VisitedLinkEventListener in profile.cc, which coalesces to |
| 134 // reduce the rate of messages being send to render processes, this class |
| 135 // ensures that the updates occur only when explicitly requested. This is |
| 136 // used by BrowserRenderProcessHost to only send Add/Reset link events to the |
| 137 // renderers when their tabs are visible. |
| 138 class VisitedLinkUpdater { |
| 139 public: |
| 140 VisitedLinkUpdater() : threshold_reached_(false) {} |
| 141 |
| 142 void Buffer(const VisitedLinkCommon::Fingerprints& links) { |
| 143 if (threshold_reached_) |
| 144 return; |
| 145 |
| 146 if (pending_.size() + links.size() > kVisitedLinkBufferThreshold) { |
| 147 threshold_reached_ = true; |
| 148 // Once the threshold is reached, there's no need to store pending visited |
| 149 // links. |
| 150 pending_.clear(); |
| 151 return; |
| 152 } |
| 153 |
| 154 pending_.insert(pending_.end(), links.begin(), links.end()); |
| 155 } |
| 156 |
| 157 void Clear() { |
| 158 pending_.clear(); |
| 159 } |
| 160 |
| 161 void Update(IPC::Channel::Sender* sender) { |
| 162 if (threshold_reached_) { |
| 163 sender->Send(new ViewMsg_VisitedLink_Reset()); |
| 164 threshold_reached_ = false; |
| 165 return; |
| 166 } |
| 167 |
| 168 if (pending_.size() == 0) |
| 169 return; |
| 170 |
| 171 sender->Send(new ViewMsg_VisitedLink_Add(pending_)); |
| 172 |
| 173 pending_.clear(); |
| 174 } |
| 175 |
| 176 private: |
| 177 bool threshold_reached_; |
| 178 VisitedLinkCommon::Fingerprints pending_; |
| 179 }; |
| 180 |
| 181 |
126 // Used for a View_ID where the renderer has not been attached yet | 182 // Used for a View_ID where the renderer has not been attached yet |
127 const int32 kInvalidViewID = -1; | 183 const int32 kInvalidViewID = -1; |
128 | 184 |
129 // Get the path to the renderer executable, which is the same as the | 185 // Get the path to the renderer executable, which is the same as the |
130 // current executable. | 186 // current executable. |
131 bool GetRendererPath(std::wstring* cmd_line) { | 187 bool GetRendererPath(std::wstring* cmd_line) { |
132 return PathService::Get(base::FILE_EXE, cmd_line); | 188 return PathService::Get(base::FILE_EXE, cmd_line); |
133 } | 189 } |
134 | 190 |
135 BrowserRenderProcessHost::BrowserRenderProcessHost(Profile* profile) | 191 BrowserRenderProcessHost::BrowserRenderProcessHost(Profile* profile) |
(...skipping 12 matching lines...) Expand all Loading... |
148 if (run_renderer_in_process()) { | 204 if (run_renderer_in_process()) { |
149 // We need a "renderer pid", but we don't have one when there's no renderer | 205 // We need a "renderer pid", but we don't have one when there's no renderer |
150 // process. So pick a value that won't clash with other child process pids. | 206 // process. So pick a value that won't clash with other child process pids. |
151 // Linux has PID_MAX_LIMIT which is 2^22. Windows always uses pids that are | 207 // Linux has PID_MAX_LIMIT which is 2^22. Windows always uses pids that are |
152 // divisible by 4. So... | 208 // divisible by 4. So... |
153 static int next_pid = 4 * 1024 * 1024; | 209 static int next_pid = 4 * 1024 * 1024; |
154 next_pid += 3; | 210 next_pid += 3; |
155 SetProcessID(next_pid); | 211 SetProcessID(next_pid); |
156 } | 212 } |
157 | 213 |
| 214 visited_link_updater_.reset(new VisitedLinkUpdater()); |
| 215 |
158 // Note: When we create the BrowserRenderProcessHost, it's technically | 216 // Note: When we create the BrowserRenderProcessHost, it's technically |
159 // backgrounded, because it has no visible listeners. But the process | 217 // backgrounded, because it has no visible listeners. But the process |
160 // doesn't actually exist yet, so we'll Background it later, after | 218 // doesn't actually exist yet, so we'll Background it later, after |
161 // creation. | 219 // creation. |
162 } | 220 } |
163 | 221 |
164 BrowserRenderProcessHost::~BrowserRenderProcessHost() { | 222 BrowserRenderProcessHost::~BrowserRenderProcessHost() { |
165 if (pid() >= 0) { | 223 if (pid() >= 0) { |
166 WebCacheManager::GetInstance()->Remove(pid()); | 224 WebCacheManager::GetInstance()->Remove(pid()); |
167 ChildProcessSecurityPolicy::GetInstance()->Remove(pid()); | 225 ChildProcessSecurityPolicy::GetInstance()->Remove(pid()); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 } | 507 } |
450 | 508 |
451 void BrowserRenderProcessHost::ReceivedBadMessage(uint16 msg_type) { | 509 void BrowserRenderProcessHost::ReceivedBadMessage(uint16 msg_type) { |
452 BadMessageTerminateProcess(msg_type, process_.handle()); | 510 BadMessageTerminateProcess(msg_type, process_.handle()); |
453 } | 511 } |
454 | 512 |
455 void BrowserRenderProcessHost::WidgetRestored() { | 513 void BrowserRenderProcessHost::WidgetRestored() { |
456 // Verify we were properly backgrounded. | 514 // Verify we were properly backgrounded. |
457 DCHECK(backgrounded_ == (visible_widgets_ == 0)); | 515 DCHECK(backgrounded_ == (visible_widgets_ == 0)); |
458 visible_widgets_++; | 516 visible_widgets_++; |
| 517 visited_link_updater_->Update(this); |
459 SetBackgrounded(false); | 518 SetBackgrounded(false); |
460 } | 519 } |
461 | 520 |
462 void BrowserRenderProcessHost::WidgetHidden() { | 521 void BrowserRenderProcessHost::WidgetHidden() { |
463 // On startup, the browser will call Hide | 522 // On startup, the browser will call Hide |
464 if (backgrounded_) | 523 if (backgrounded_) |
465 return; | 524 return; |
466 | 525 |
467 DCHECK(backgrounded_ == (visible_widgets_ == 0)); | 526 DCHECK(backgrounded_ == (visible_widgets_ == 0)); |
468 visible_widgets_--; | 527 visible_widgets_--; |
(...skipping 11 matching lines...) Expand all Loading... |
480 NOTIMPLEMENTED(); | 539 NOTIMPLEMENTED(); |
481 #else | 540 #else |
482 base::Thread* io_thread = g_browser_process->io_thread(); | 541 base::Thread* io_thread = g_browser_process->io_thread(); |
483 if (profile()->GetSpellChecker()) { | 542 if (profile()->GetSpellChecker()) { |
484 io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 543 io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
485 profile()->GetSpellChecker(), &SpellChecker::AddWord, word)); | 544 profile()->GetSpellChecker(), &SpellChecker::AddWord, word)); |
486 } | 545 } |
487 #endif // !defined(OS_WIN) | 546 #endif // !defined(OS_WIN) |
488 } | 547 } |
489 | 548 |
| 549 void BrowserRenderProcessHost::AddVisitedLinks( |
| 550 const VisitedLinkCommon::Fingerprints& links) { |
| 551 visited_link_updater_->Buffer(links); |
| 552 if (visible_widgets_ == 0) |
| 553 return; |
| 554 |
| 555 visited_link_updater_->Update(this); |
| 556 } |
| 557 |
| 558 void BrowserRenderProcessHost::ResetVisitedLinks() { |
| 559 visited_link_updater_->Clear(); |
| 560 Send(new ViewMsg_VisitedLink_Reset()); |
| 561 } |
| 562 |
490 base::ProcessHandle BrowserRenderProcessHost::GetRendererProcessHandle() { | 563 base::ProcessHandle BrowserRenderProcessHost::GetRendererProcessHandle() { |
491 if (run_renderer_in_process()) | 564 if (run_renderer_in_process()) |
492 return base::Process::Current().handle(); | 565 return base::Process::Current().handle(); |
493 return process_.handle(); | 566 return process_.handle(); |
494 } | 567 } |
495 | 568 |
496 void BrowserRenderProcessHost::InitVisitedLinks() { | 569 void BrowserRenderProcessHost::InitVisitedLinks() { |
497 VisitedLinkMaster* visitedlink_master = profile()->GetVisitedLinkMaster(); | 570 VisitedLinkMaster* visitedlink_master = profile()->GetVisitedLinkMaster(); |
498 if (!visitedlink_master) { | 571 if (!visitedlink_master) { |
499 return; | 572 return; |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 void BrowserRenderProcessHost::OnExtensionRemoveListener( | 969 void BrowserRenderProcessHost::OnExtensionRemoveListener( |
897 const std::string& event_name) { | 970 const std::string& event_name) { |
898 ExtensionMessageService::GetInstance(profile()->GetRequestContext())-> | 971 ExtensionMessageService::GetInstance(profile()->GetRequestContext())-> |
899 RemoveEventListener(event_name, pid()); | 972 RemoveEventListener(event_name, pid()); |
900 } | 973 } |
901 | 974 |
902 void BrowserRenderProcessHost::OnExtensionCloseChannel(int port_id) { | 975 void BrowserRenderProcessHost::OnExtensionCloseChannel(int port_id) { |
903 ExtensionMessageService::GetInstance(profile()->GetRequestContext())-> | 976 ExtensionMessageService::GetInstance(profile()->GetRequestContext())-> |
904 CloseChannel(port_id); | 977 CloseChannel(port_id); |
905 } | 978 } |
OLD | NEW |