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

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: And another test Created 8 years 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/intents/web_intents_util.h" 24 #include "chrome/browser/intents/web_intents_util.h"
25 #include "chrome/browser/lifetime/application_lifetime.h"
25 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h" 27 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h"
27 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/browser_finder.h" 29 #include "chrome/browser/ui/browser_finder.h"
29 #include "chrome/browser/ui/browser_list.h" 30 #include "chrome/browser/ui/browser_list.h"
30 #include "chrome/browser/ui/browser_window.h" 31 #include "chrome/browser/ui/browser_window.h"
31 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" 32 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
32 #include "chrome/browser/ui/tab_contents/tab_contents.h" 33 #include "chrome/browser/ui/tab_contents/tab_contents.h"
33 #include "chrome/browser/view_type_utils.h" 34 #include "chrome/browser/view_type_utils.h"
34 #include "chrome/common/chrome_constants.h" 35 #include "chrome/common/chrome_constants.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 SiteInstance* site_instance, 131 SiteInstance* site_instance,
131 const GURL& url, 132 const GURL& url,
132 chrome::ViewType host_type) 133 chrome::ViewType host_type)
133 : extension_(extension), 134 : extension_(extension),
134 extension_id_(extension->id()), 135 extension_id_(extension->id()),
135 profile_(Profile::FromBrowserContext( 136 profile_(Profile::FromBrowserContext(
136 site_instance->GetBrowserContext())), 137 site_instance->GetBrowserContext())),
137 render_view_host_(NULL), 138 render_view_host_(NULL),
138 did_stop_loading_(false), 139 did_stop_loading_(false),
139 document_element_available_(false), 140 document_element_available_(false),
141 keeping_browser_process_alive_(false),
140 initial_url_(url), 142 initial_url_(url),
141 ALLOW_THIS_IN_INITIALIZER_LIST( 143 ALLOW_THIS_IN_INITIALIZER_LIST(
142 extension_function_dispatcher_(profile_, this)), 144 extension_function_dispatcher_(profile_, this)),
143 extension_host_type_(host_type), 145 extension_host_type_(host_type),
144 associated_web_contents_(NULL) { 146 associated_web_contents_(NULL) {
145 host_contents_.reset(WebContents::Create( 147 host_contents_.reset(WebContents::Create(
146 profile_, site_instance, MSG_ROUTING_NONE, NULL)); 148 profile_, site_instance, MSG_ROUTING_NONE, NULL));
147 content::WebContentsObserver::Observe(host_contents_.get()); 149 content::WebContentsObserver::Observe(host_contents_.get());
148 host_contents_->SetDelegate(this); 150 host_contents_->SetDelegate(this);
149 chrome::SetViewType(host_contents_.get(), host_type); 151 chrome::SetViewType(host_contents_.get(), host_type);
(...skipping 12 matching lines...) Expand all
162 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE && 164 if (extension_host_type_ == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE &&
163 extension_ && extension_->has_lazy_background_page()) { 165 extension_ && extension_->has_lazy_background_page()) {
164 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime", 166 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime",
165 since_created_.Elapsed()); 167 since_created_.Elapsed());
166 } 168 }
167 content::NotificationService::current()->Notify( 169 content::NotificationService::current()->Notify(
168 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, 170 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
169 content::Source<Profile>(profile_), 171 content::Source<Profile>(profile_),
170 content::Details<ExtensionHost>(this)); 172 content::Details<ExtensionHost>(this));
171 ProcessCreationQueue::GetInstance()->Remove(this); 173 ProcessCreationQueue::GetInstance()->Remove(this);
174
175 #if !defined(OS_ANDROID)
176 if (keeping_browser_process_alive_)
177 browser::EndKeepAlive();
178 #endif
172 } 179 }
173 180
174 void ExtensionHost::CreateView(Browser* browser) { 181 void ExtensionHost::CreateView(Browser* browser) {
175 #if defined(TOOLKIT_VIEWS) 182 #if defined(TOOLKIT_VIEWS)
176 view_.reset(new ExtensionViewViews(this, browser)); 183 view_.reset(new ExtensionViewViews(this, browser));
177 // We own |view_|, so don't auto delete when it's removed from the view 184 // We own |view_|, so don't auto delete when it's removed from the view
178 // hierarchy. 185 // hierarchy.
179 view_->set_owned_by_client(); 186 view_->set_owned_by_client();
180 #elif defined(OS_MACOSX) 187 #elif defined(OS_MACOSX)
181 view_.reset(new ExtensionViewMac(this, browser)); 188 view_.reset(new ExtensionViewMac(this, browser));
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 pm->IncrementLazyKeepaliveCount(extension()); 460 pm->IncrementLazyKeepaliveCount(extension());
454 } 461 }
455 462
456 void ExtensionHost::DidCloseJavaScriptDialog() { 463 void ExtensionHost::DidCloseJavaScriptDialog() {
457 ExtensionProcessManager* pm = 464 ExtensionProcessManager* pm =
458 ExtensionSystem::Get(profile_)->process_manager(); 465 ExtensionSystem::Get(profile_)->process_manager();
459 if (pm) 466 if (pm)
460 pm->DecrementLazyKeepaliveCount(extension()); 467 pm->DecrementLazyKeepaliveCount(extension());
461 } 468 }
462 469
470 void ExtensionHost::SetKeepsBrowserProcessAlive() {
471 if (keeping_browser_process_alive_)
472 return;
473
474 #if !defined(OS_ANDROID)
475 keeping_browser_process_alive_ = true;
476 browser::StartKeepAlive();
477 #endif
478 }
479
463 WebContents* ExtensionHost::OpenURLFromTab(WebContents* source, 480 WebContents* ExtensionHost::OpenURLFromTab(WebContents* source,
464 const OpenURLParams& params) { 481 const OpenURLParams& params) {
465 // Whitelist the dispositions we will allow to be opened. 482 // Whitelist the dispositions we will allow to be opened.
466 switch (params.disposition) { 483 switch (params.disposition) {
467 case SINGLETON_TAB: 484 case SINGLETON_TAB:
468 case NEW_FOREGROUND_TAB: 485 case NEW_FOREGROUND_TAB:
469 case NEW_BACKGROUND_TAB: 486 case NEW_BACKGROUND_TAB:
470 case NEW_POPUP: 487 case NEW_POPUP:
471 case NEW_WINDOW: 488 case NEW_WINDOW:
472 case SAVE_TO_DISK: 489 case SAVE_TO_DISK:
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 void ExtensionHost::RequestMediaAccessPermission( 666 void ExtensionHost::RequestMediaAccessPermission(
650 content::WebContents* web_contents, 667 content::WebContents* web_contents,
651 const content::MediaStreamRequest* request, 668 const content::MediaStreamRequest* request,
652 const content::MediaResponseCallback& callback) { 669 const content::MediaResponseCallback& callback) {
653 // For tab capture device, we require the tabCapture permission. 670 // For tab capture device, we require the tabCapture permission.
654 RequestMediaAccessPermissionHelper::AuthorizeRequest( 671 RequestMediaAccessPermissionHelper::AuthorizeRequest(
655 request, callback, extension(), false); 672 request, callback, extension(), false);
656 } 673 }
657 674
658 } // namespace extensions 675 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_host.h ('k') | chrome/browser/extensions/platform_app_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698