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

Side by Side Diff: chrome/browser/ui/apps/chrome_app_delegate.cc

Issue 1708343002: Add ScopedKeepAlive to c/b/lifetime (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address PS7 comments, replace strings by a struct ptr, chromeappdelegate ctor takes a boolean Created 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/ui/apps/chrome_app_delegate.h" 5 #include "chrome/browser/ui/apps/chrome_app_delegate.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "chrome/browser/app_mode/app_mode_utils.h" 12 #include "chrome/browser/app_mode/app_mode_utils.h"
13 #include "chrome/browser/apps/scoped_keep_alive.h"
14 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" 14 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
16 #include "chrome/browser/favicon/favicon_utils.h" 15 #include "chrome/browser/favicon/favicon_utils.h"
17 #include "chrome/browser/file_select_helper.h" 16 #include "chrome/browser/file_select_helper.h"
17 #include "chrome/browser/lifetime/keep_alive_options.h"
18 #include "chrome/browser/lifetime/scoped_keep_alive.h"
18 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 19 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
19 #include "chrome/browser/platform_util.h" 20 #include "chrome/browser/platform_util.h"
20 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/shell_integration.h" 22 #include "chrome/browser/shell_integration.h"
22 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_dialogs.h" 24 #include "chrome/browser/ui/browser_dialogs.h"
24 #include "chrome/browser/ui/browser_navigator_params.h" 25 #include "chrome/browser/ui/browser_navigator_params.h"
25 #include "chrome/browser/ui/browser_tabstrip.h" 26 #include "chrome/browser/ui/browser_tabstrip.h"
26 #include "chrome/browser/ui/browser_window.h" 27 #include "chrome/browser/ui/browser_window.h"
27 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 28 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
(...skipping 22 matching lines...) Expand all
50 #endif // defined(ENABLE_PRINT_PREVIEW) 51 #endif // defined(ENABLE_PRINT_PREVIEW)
51 #endif // defined(ENABLE_PRINTING) 52 #endif // defined(ENABLE_PRINTING)
52 53
53 namespace { 54 namespace {
54 55
55 // Time to wait for an app window to show before allowing Chrome to quit. 56 // Time to wait for an app window to show before allowing Chrome to quit.
56 int kAppWindowFirstShowTimeoutSeconds = 10; 57 int kAppWindowFirstShowTimeoutSeconds = 10;
57 58
58 bool disable_external_open_for_testing_ = false; 59 bool disable_external_open_for_testing_ = false;
59 60
61 static const KeepAliveOptions g_keep_alive_options = {"ChromeAppDelegate"};
62
60 // Opens a URL with Chromium (not external browser) with the right profile. 63 // Opens a URL with Chromium (not external browser) with the right profile.
61 content::WebContents* OpenURLFromTabInternal( 64 content::WebContents* OpenURLFromTabInternal(
62 content::BrowserContext* context, 65 content::BrowserContext* context,
63 const content::OpenURLParams& params) { 66 const content::OpenURLParams& params) {
64 // Force all links to open in a new tab, even if they were trying to open a 67 // Force all links to open in a new tab, even if they were trying to open a
65 // window. 68 // window.
66 chrome::NavigateParams new_tab_params( 69 chrome::NavigateParams new_tab_params(
67 static_cast<Browser*>(NULL), params.url, params.transition); 70 static_cast<Browser*>(NULL), params.url, params.transition);
68 if (params.disposition == NEW_BACKGROUND_TAB) { 71 if (params.disposition == NEW_BACKGROUND_TAB) {
69 new_tab_params.disposition = NEW_BACKGROUND_TAB; 72 new_tab_params.disposition = NEW_BACKGROUND_TAB;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 /*delete_observer=*/true); 163 /*delete_observer=*/true);
161 // Object lifetime notes: The OpenURLFromTabBasedOnBrowserDefault is owned 164 // Object lifetime notes: The OpenURLFromTabBasedOnBrowserDefault is owned
162 // by check_if_default_browser_worker. StartCheckIsDefault() takes lifetime 165 // by check_if_default_browser_worker. StartCheckIsDefault() takes lifetime
163 // ownership of check_if_default_browser_worker and will clean up after 166 // ownership of check_if_default_browser_worker and will clean up after
164 // the asynchronous tasks. 167 // the asynchronous tasks.
165 check_if_default_browser_worker->StartCheckIsDefault(); 168 check_if_default_browser_worker->StartCheckIsDefault();
166 } 169 }
167 return NULL; 170 return NULL;
168 } 171 }
169 172
170 ChromeAppDelegate::ChromeAppDelegate(scoped_ptr<ScopedKeepAlive> keep_alive) 173 ChromeAppDelegate::ChromeAppDelegate(bool keep_alive)
171 : has_been_shown_(false), 174 : has_been_shown_(false),
172 is_hidden_(true), 175 is_hidden_(true),
173 keep_alive_(std::move(keep_alive)),
174 new_window_contents_delegate_(new NewWindowContentsDelegate()), 176 new_window_contents_delegate_(new NewWindowContentsDelegate()),
175 weak_factory_(this) { 177 weak_factory_(this) {
178 if (keep_alive)
179 keep_alive_.reset(new ScopedKeepAlive(&g_keep_alive_options));
176 registrar_.Add(this, 180 registrar_.Add(this,
177 chrome::NOTIFICATION_APP_TERMINATING, 181 chrome::NOTIFICATION_APP_TERMINATING,
178 content::NotificationService::AllSources()); 182 content::NotificationService::AllSources());
179 } 183 }
180 184
181 ChromeAppDelegate::~ChromeAppDelegate() { 185 ChromeAppDelegate::~ChromeAppDelegate() {
182 // Unregister now to prevent getting notified if |keep_alive_| is the last. 186 // Unregister now to prevent getting notified if |keep_alive_| is the last.
183 terminating_callback_.Reset(); 187 terminating_callback_.Reset();
184 } 188 }
185 189
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 content::BrowserThread::PostDelayedTask( 342 content::BrowserThread::PostDelayedTask(
339 content::BrowserThread::UI, FROM_HERE, 343 content::BrowserThread::UI, FROM_HERE,
340 base::Bind(&ChromeAppDelegate::RelinquishKeepAliveAfterTimeout, 344 base::Bind(&ChromeAppDelegate::RelinquishKeepAliveAfterTimeout,
341 weak_factory_.GetWeakPtr()), 345 weak_factory_.GetWeakPtr()),
342 base::TimeDelta::FromSeconds(kAppWindowFirstShowTimeoutSeconds)); 346 base::TimeDelta::FromSeconds(kAppWindowFirstShowTimeoutSeconds));
343 } 347 }
344 348
345 void ChromeAppDelegate::OnShow() { 349 void ChromeAppDelegate::OnShow() {
346 has_been_shown_ = true; 350 has_been_shown_ = true;
347 is_hidden_ = false; 351 is_hidden_ = false;
348 keep_alive_.reset(new ScopedKeepAlive); 352 keep_alive_.reset(new ScopedKeepAlive(&g_keep_alive_options));
349 } 353 }
350 354
351 void ChromeAppDelegate::Observe(int type, 355 void ChromeAppDelegate::Observe(int type,
352 const content::NotificationSource& source, 356 const content::NotificationSource& source,
353 const content::NotificationDetails& details) { 357 const content::NotificationDetails& details) {
354 switch (type) { 358 switch (type) {
355 case chrome::NOTIFICATION_APP_TERMINATING: 359 case chrome::NOTIFICATION_APP_TERMINATING:
356 if (!terminating_callback_.is_null()) 360 if (!terminating_callback_.is_null())
357 terminating_callback_.Run(); 361 terminating_callback_.Run();
358 break; 362 break;
359 default: 363 default:
360 NOTREACHED() << "Received unexpected notification"; 364 NOTREACHED() << "Received unexpected notification";
361 } 365 }
362 } 366 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698