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

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: Update new sync tests 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 pm->IncrementLazyKeepaliveCount(extension()); 457 pm->IncrementLazyKeepaliveCount(extension());
451 } 458 }
452 459
453 void ExtensionHost::DidCloseJavaScriptDialog() { 460 void ExtensionHost::DidCloseJavaScriptDialog() {
454 ExtensionProcessManager* pm = 461 ExtensionProcessManager* pm =
455 ExtensionSystem::Get(profile_)->process_manager(); 462 ExtensionSystem::Get(profile_)->process_manager();
456 if (pm) 463 if (pm)
457 pm->DecrementLazyKeepaliveCount(extension()); 464 pm->DecrementLazyKeepaliveCount(extension());
458 } 465 }
459 466
467 void ExtensionHost::SetKeepsBrowserProcessAlive() {
468 if (keeping_browser_process_alive_)
469 return;
470
471 #if !defined(OS_ANDROID)
472 keeping_browser_process_alive_ = true;
473 browser::StartKeepAlive();
474 #endif
475 }
476
460 WebContents* ExtensionHost::OpenURLFromTab(WebContents* source, 477 WebContents* ExtensionHost::OpenURLFromTab(WebContents* source,
461 const OpenURLParams& params) { 478 const OpenURLParams& params) {
462 // Whitelist the dispositions we will allow to be opened. 479 // Whitelist the dispositions we will allow to be opened.
463 switch (params.disposition) { 480 switch (params.disposition) {
464 case SINGLETON_TAB: 481 case SINGLETON_TAB:
465 case NEW_FOREGROUND_TAB: 482 case NEW_FOREGROUND_TAB:
466 case NEW_BACKGROUND_TAB: 483 case NEW_BACKGROUND_TAB:
467 case NEW_POPUP: 484 case NEW_POPUP:
468 case NEW_WINDOW: 485 case NEW_WINDOW:
469 case SAVE_TO_DISK: 486 case SAVE_TO_DISK:
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 void ExtensionHost::RequestMediaAccessPermission( 663 void ExtensionHost::RequestMediaAccessPermission(
647 content::WebContents* web_contents, 664 content::WebContents* web_contents,
648 const content::MediaStreamRequest* request, 665 const content::MediaStreamRequest* request,
649 const content::MediaResponseCallback& callback) { 666 const content::MediaResponseCallback& callback) {
650 // For tab capture device, we require the tabCapture permission. 667 // For tab capture device, we require the tabCapture permission.
651 RequestMediaAccessPermissionHelper::AuthorizeRequest( 668 RequestMediaAccessPermissionHelper::AuthorizeRequest(
652 request, callback, extension(), false); 669 request, callback, extension(), false);
653 } 670 }
654 671
655 } // namespace extensions 672 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698