Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: chrome/browser/renderer_host/browser_render_process_host.cc

Issue 21485: Bitmap transport (Closed)
Patch Set: Fix some mac crashes Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 //------------------------------------------------------------------------------ 121 //------------------------------------------------------------------------------
122 122
123 // static 123 // static
124 void BrowserRenderProcessHost::RegisterPrefs(PrefService* prefs) { 124 void BrowserRenderProcessHost::RegisterPrefs(PrefService* prefs) {
125 prefs->RegisterBooleanPref(prefs::kStartRenderersManually, false); 125 prefs->RegisterBooleanPref(prefs::kStartRenderersManually, false);
126 } 126 }
127 127
128 BrowserRenderProcessHost::BrowserRenderProcessHost(Profile* profile) 128 BrowserRenderProcessHost::BrowserRenderProcessHost(Profile* profile)
129 : RenderProcessHost(profile), 129 : RenderProcessHost(profile),
130 visible_widgets_(0), 130 visible_widgets_(0),
131 backgrounded_(true) { 131 backgrounded_(true),
132 ALLOW_THIS_IN_INITIALIZER_LIST(cached_dibs_cleaner_(
133 base::TimeDelta::FromSeconds(5),
134 this, &BrowserRenderProcessHost::ClearTransportDIBCache)) {
132 DCHECK(host_id() >= 0); // We use a negative host_id_ in destruction. 135 DCHECK(host_id() >= 0); // We use a negative host_id_ in destruction.
133 widget_helper_ = new RenderWidgetHelper(host_id()); 136 widget_helper_ = new RenderWidgetHelper(host_id());
134 137
135 CacheManagerHost::GetInstance()->Add(host_id()); 138 CacheManagerHost::GetInstance()->Add(host_id());
136 RendererSecurityPolicy::GetInstance()->Add(host_id()); 139 RendererSecurityPolicy::GetInstance()->Add(host_id());
137 140
138 PrefService* prefs = profile->GetPrefs(); 141 PrefService* prefs = profile->GetPrefs();
139 prefs->AddPrefObserver(prefs::kBlockPopups, this); 142 prefs->AddPrefObserver(prefs::kBlockPopups, this);
140 widget_helper_->set_block_popups( 143 widget_helper_->set_block_popups(
141 profile->GetPrefs()->GetBoolean(prefs::kBlockPopups)); 144 profile->GetPrefs()->GetBoolean(prefs::kBlockPopups));
(...skipping 21 matching lines...) Expand all
163 audio_renderer_host_->Destroy(); 166 audio_renderer_host_->Destroy();
164 167
165 if (process_.handle() && !run_renderer_in_process()) { 168 if (process_.handle() && !run_renderer_in_process()) {
166 ProcessWatcher::EnsureProcessTerminated(process_.handle()); 169 ProcessWatcher::EnsureProcessTerminated(process_.handle());
167 } 170 }
168 171
169 profile()->GetPrefs()->RemovePrefObserver(prefs::kBlockPopups, this); 172 profile()->GetPrefs()->RemovePrefObserver(prefs::kBlockPopups, this);
170 173
171 NotificationService::current()->RemoveObserver(this, 174 NotificationService::current()->RemoveObserver(this,
172 NotificationType::USER_SCRIPTS_LOADED, NotificationService::AllSources()); 175 NotificationType::USER_SCRIPTS_LOADED, NotificationService::AllSources());
176
177 ClearTransportDIBCache();
173 } 178 }
174 179
175 // When we're started with the --start-renderers-manually flag, we pop up a 180 // When we're started with the --start-renderers-manually flag, we pop up a
176 // modal dialog requesting the user manually start up a renderer. 181 // modal dialog requesting the user manually start up a renderer.
177 // |cmd_line| is the command line to start the renderer with. 182 // |cmd_line| is the command line to start the renderer with.
178 static void RunStartRenderersManuallyDialog(const CommandLine& cmd_line) { 183 static void RunStartRenderersManuallyDialog(const CommandLine& cmd_line) {
179 #if defined(OS_WIN) 184 #if defined(OS_WIN)
180 std::wstring message = 185 std::wstring message =
181 L"Please start a renderer process using:\n" + 186 L"Please start a renderer process using:\n" +
182 cmd_line.command_line_string(); 187 cmd_line.command_line_string();
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 NOTIMPLEMENTED(); 603 NOTIMPLEMENTED();
599 #endif 604 #endif
600 605
601 // Otherwise, we're allowed to just terminate the process. Using exit code 0 606 // Otherwise, we're allowed to just terminate the process. Using exit code 0
602 // means that UMA won't treat this as a renderer crash. 607 // means that UMA won't treat this as a renderer crash.
603 process_.Terminate(ResultCodes::NORMAL_EXIT); 608 process_.Terminate(ResultCodes::NORMAL_EXIT);
604 process_.Close(); 609 process_.Close();
605 return true; 610 return true;
606 } 611 }
607 612
613 // This is a platform specific function for mapping a transport DIB given its id
614 TransportDIB* BrowserRenderProcessHost::MapTransportDIB(
615 TransportDIB::Id dib_id) {
616 #if defined(OS_WIN)
617 // On Windows we need to duplicate the handle from the remote process
618 HANDLE section = win_util::GetSectionFromProcess(
619 dib_id.handle, GetRendererProcessHandle(), false /* read write */);
620 return TransportDIB::Map(section);
621 #elif defined(OS_MACOSX)
622 // On OSX, the browser allocates all DIBs and keeps a file descriptor around
623 // for each.
624 return widget_helper_->MapTransportDIB(dib_id);
625 #elif defined(OS_LINUX)
626 return TransportDIB::Map(dib_id);
627 #endif // defined(OS_LINUX)
628 }
629
630 TransportDIB* BrowserRenderProcessHost::GetTransportDIB(
631 TransportDIB::Id dib_id) {
632 const std::map<TransportDIB::Id, TransportDIB*>::iterator
633 i = cached_dibs_.find(dib_id);
634 if (i != cached_dibs_.end()) {
635 cached_dibs_cleaner_.Reset();
636 return i->second;
637 }
638
639 TransportDIB* dib = MapTransportDIB(dib_id);
640 if (!dib)
641 return NULL;
642
643 if (cached_dibs_.size() >= MAX_MAPPED_TRANSPORT_DIBS) {
644 // Clean a single entry from the cache
645 std::map<TransportDIB::Id, TransportDIB*>::iterator smallest_iterator;
646 size_t smallest_size = std::numeric_limits<size_t>::max();
647
648 for (std::map<TransportDIB::Id, TransportDIB*>::iterator
649 i = cached_dibs_.begin(); i != cached_dibs_.end(); ++i) {
650 if (i->second->size() <= smallest_size)
651 smallest_iterator = i;
652 }
653
654 delete smallest_iterator->second;
655 cached_dibs_.erase(smallest_iterator);
656 }
657
658 cached_dibs_[dib_id] = dib;
659 cached_dibs_cleaner_.Reset();
660 return dib;
661 }
662
663 void BrowserRenderProcessHost::ClearTransportDIBCache() {
664 for (std::map<TransportDIB::Id, TransportDIB*>::iterator
665 i = cached_dibs_.begin(); i != cached_dibs_.end(); ++i) {
666 delete i->second;
667 }
668
669 cached_dibs_.clear();
670 }
671
608 bool BrowserRenderProcessHost::Send(IPC::Message* msg) { 672 bool BrowserRenderProcessHost::Send(IPC::Message* msg) {
609 if (!channel_.get()) { 673 if (!channel_.get()) {
610 delete msg; 674 delete msg;
611 return false; 675 return false;
612 } 676 }
613 return channel_->Send(msg); 677 return channel_->Send(msg);
614 } 678 }
615 679
616 void BrowserRenderProcessHost::OnMessageReceived(const IPC::Message& msg) { 680 void BrowserRenderProcessHost::OnMessageReceived(const IPC::Message& msg) {
617 if (msg.routing_id() == MSG_ROUTING_CONTROL) { 681 if (msg.routing_id() == MSG_ROUTING_CONTROL) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 SendUserScriptsUpdate(shared_memory); 872 SendUserScriptsUpdate(shared_memory);
809 } 873 }
810 break; 874 break;
811 } 875 }
812 default: { 876 default: {
813 NOTREACHED(); 877 NOTREACHED();
814 break; 878 break;
815 } 879 }
816 } 880 }
817 } 881 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698