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

Side by Side Diff: chrome/browser/extensions/extension_host.cc

Issue 11117011: Keep browser process alive while there are platform apps with background pages running. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/extension_host.h" 5 #include "chrome/browser/extensions/extension_host.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/browser_shutdown.h" 16 #include "chrome/browser/browser_shutdown.h"
17 #include "chrome/browser/extensions/event_router.h" 17 #include "chrome/browser/extensions/event_router.h"
18 #include "chrome/browser/extensions/extension_process_manager.h" 18 #include "chrome/browser/extensions/extension_process_manager.h"
19 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/extensions/extension_system.h" 20 #include "chrome/browser/extensions/extension_system.h"
21 #include "chrome/browser/extensions/extension_tab_util.h" 21 #include "chrome/browser/extensions/extension_tab_util.h"
22 #include "chrome/browser/extensions/window_controller.h" 22 #include "chrome/browser/extensions/window_controller.h"
23 #include "chrome/browser/file_select_helper.h" 23 #include "chrome/browser/file_select_helper.h"
24 #include "chrome/browser/lifetime/application_lifetime.h"
24 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h" 26 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h"
26 #include "chrome/browser/ui/browser.h" 27 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_finder.h" 28 #include "chrome/browser/ui/browser_finder.h"
28 #include "chrome/browser/ui/browser_list.h" 29 #include "chrome/browser/ui/browser_list.h"
29 #include "chrome/browser/ui/browser_window.h" 30 #include "chrome/browser/ui/browser_window.h"
30 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" 31 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
31 #include "chrome/browser/ui/tab_contents/tab_contents.h" 32 #include "chrome/browser/ui/tab_contents/tab_contents.h"
32 #include "chrome/browser/view_type_utils.h" 33 #include "chrome/browser/view_type_utils.h"
33 #include "chrome/common/chrome_constants.h" 34 #include "chrome/common/chrome_constants.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 SiteInstance* site_instance, 135 SiteInstance* site_instance,
135 const GURL& url, 136 const GURL& url,
136 chrome::ViewType host_type) 137 chrome::ViewType host_type)
137 : extension_(extension), 138 : extension_(extension),
138 extension_id_(extension->id()), 139 extension_id_(extension->id()),
139 profile_(Profile::FromBrowserContext( 140 profile_(Profile::FromBrowserContext(
140 site_instance->GetBrowserContext())), 141 site_instance->GetBrowserContext())),
141 render_view_host_(NULL), 142 render_view_host_(NULL),
142 did_stop_loading_(false), 143 did_stop_loading_(false),
143 document_element_available_(false), 144 document_element_available_(false),
145 keeping_browser_process_alive_(false),
144 initial_url_(url), 146 initial_url_(url),
145 ALLOW_THIS_IN_INITIALIZER_LIST( 147 ALLOW_THIS_IN_INITIALIZER_LIST(
146 extension_function_dispatcher_(profile_, this)), 148 extension_function_dispatcher_(profile_, this)),
147 extension_host_type_(host_type), 149 extension_host_type_(host_type),
148 associated_web_contents_(NULL) { 150 associated_web_contents_(NULL) {
149 host_contents_.reset(WebContents::Create( 151 host_contents_.reset(WebContents::Create(
150 profile_, site_instance, MSG_ROUTING_NONE, NULL)); 152 profile_, site_instance, MSG_ROUTING_NONE, NULL));
151 content::WebContentsObserver::Observe(host_contents_.get()); 153 content::WebContentsObserver::Observe(host_contents_.get());
152 host_contents_->SetDelegate(this); 154 host_contents_->SetDelegate(this);
153 chrome::SetViewType(host_contents_.get(), host_type); 155 chrome::SetViewType(host_contents_.get(), host_type);
(...skipping 12 matching lines...) Expand all
166 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE && 168 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE &&
167 extension_ && extension_->has_lazy_background_page()) { 169 extension_ && extension_->has_lazy_background_page()) {
168 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime", 170 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime",
169 since_created_.Elapsed()); 171 since_created_.Elapsed());
170 } 172 }
171 content::NotificationService::current()->Notify( 173 content::NotificationService::current()->Notify(
172 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, 174 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
173 content::Source<Profile>(profile_), 175 content::Source<Profile>(profile_),
174 content::Details<ExtensionHost>(this)); 176 content::Details<ExtensionHost>(this));
175 ProcessCreationQueue::GetInstance()->Remove(this); 177 ProcessCreationQueue::GetInstance()->Remove(this);
178
179 if (keeping_browser_process_alive_)
180 browser::EndKeepAlive();
176 } 181 }
177 182
178 void ExtensionHost::CreateView(Browser* browser) { 183 void ExtensionHost::CreateView(Browser* browser) {
179 #if defined(TOOLKIT_VIEWS) 184 #if defined(TOOLKIT_VIEWS)
180 view_.reset(new ExtensionViewViews(this, browser)); 185 view_.reset(new ExtensionViewViews(this, browser));
181 // We own |view_|, so don't auto delete when it's removed from the view 186 // We own |view_|, so don't auto delete when it's removed from the view
182 // hierarchy. 187 // hierarchy.
183 view_->set_owned_by_client(); 188 view_->set_owned_by_client();
184 #elif defined(OS_MACOSX) 189 #elif defined(OS_MACOSX)
185 view_.reset(new ExtensionViewMac(this, browser)); 190 view_.reset(new ExtensionViewMac(this, browser));
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 pm->IncrementLazyKeepaliveCount(extension()); 467 pm->IncrementLazyKeepaliveCount(extension());
463 } 468 }
464 469
465 void ExtensionHost::DidCloseJavaScriptDialog() { 470 void ExtensionHost::DidCloseJavaScriptDialog() {
466 ExtensionProcessManager* pm = 471 ExtensionProcessManager* pm =
467 ExtensionSystem::Get(profile_)->process_manager(); 472 ExtensionSystem::Get(profile_)->process_manager();
468 if (pm) 473 if (pm)
469 pm->DecrementLazyKeepaliveCount(extension()); 474 pm->DecrementLazyKeepaliveCount(extension());
470 } 475 }
471 476
477 void ExtensionHost::KeepBrowserProcessAlive() {
Aaron Boodman 2012/10/31 07:31:22 Nit: I think SetKeepsBrowserProcessAlive() would b
benwells 2012/10/31 08:08:22 Done.
478 if (keeping_browser_process_alive_)
479 return;
480
481 keeping_browser_process_alive_ = true;
482 browser::StartKeepAlive();
483 }
484
472 WebContents* ExtensionHost::OpenURLFromTab(WebContents* source, 485 WebContents* ExtensionHost::OpenURLFromTab(WebContents* source,
473 const OpenURLParams& params) { 486 const OpenURLParams& params) {
474 // Whitelist the dispositions we will allow to be opened. 487 // Whitelist the dispositions we will allow to be opened.
475 switch (params.disposition) { 488 switch (params.disposition) {
476 case SINGLETON_TAB: 489 case SINGLETON_TAB:
477 case NEW_FOREGROUND_TAB: 490 case NEW_FOREGROUND_TAB:
478 case NEW_BACKGROUND_TAB: 491 case NEW_BACKGROUND_TAB:
479 case NEW_POPUP: 492 case NEW_POPUP:
480 case NEW_WINDOW: 493 case NEW_WINDOW:
481 case SAVE_TO_DISK: 494 case SAVE_TO_DISK:
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 void ExtensionHost::RequestMediaAccessPermission( 670 void ExtensionHost::RequestMediaAccessPermission(
658 content::WebContents* web_contents, 671 content::WebContents* web_contents,
659 const content::MediaStreamRequest* request, 672 const content::MediaStreamRequest* request,
660 const content::MediaResponseCallback& callback) { 673 const content::MediaResponseCallback& callback) {
661 // For tab capture device, we require the tabCapture permission. 674 // For tab capture device, we require the tabCapture permission.
662 RequestMediaAccessPermissionHelper::AuthorizeRequest( 675 RequestMediaAccessPermissionHelper::AuthorizeRequest(
663 request, callback, extension(), false); 676 request, callback, extension(), false);
664 } 677 }
665 678
666 } // namespace extensions 679 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698