OLD | NEW |
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_types.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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 /*delete_observer=*/true); | 161 /*delete_observer=*/true); |
161 // Object lifetime notes: The OpenURLFromTabBasedOnBrowserDefault is owned | 162 // Object lifetime notes: The OpenURLFromTabBasedOnBrowserDefault is owned |
162 // by check_if_default_browser_worker. StartCheckIsDefault() takes lifetime | 163 // by check_if_default_browser_worker. StartCheckIsDefault() takes lifetime |
163 // ownership of check_if_default_browser_worker and will clean up after | 164 // ownership of check_if_default_browser_worker and will clean up after |
164 // the asynchronous tasks. | 165 // the asynchronous tasks. |
165 check_if_default_browser_worker->StartCheckIsDefault(); | 166 check_if_default_browser_worker->StartCheckIsDefault(); |
166 } | 167 } |
167 return NULL; | 168 return NULL; |
168 } | 169 } |
169 | 170 |
170 ChromeAppDelegate::ChromeAppDelegate(scoped_ptr<ScopedKeepAlive> keep_alive) | 171 ChromeAppDelegate::ChromeAppDelegate(bool keep_alive) |
171 : has_been_shown_(false), | 172 : has_been_shown_(false), |
172 is_hidden_(true), | 173 is_hidden_(true), |
173 keep_alive_(std::move(keep_alive)), | |
174 new_window_contents_delegate_(new NewWindowContentsDelegate()), | 174 new_window_contents_delegate_(new NewWindowContentsDelegate()), |
175 weak_factory_(this) { | 175 weak_factory_(this) { |
| 176 if (keep_alive) { |
| 177 keep_alive_.reset( |
| 178 new ScopedKeepAlive(KeepAliveOrigin::CHROME_APP_DELEGATE)); |
| 179 } |
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 Loading... |
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(KeepAliveOrigin::CHROME_APP_DELEGATE)); |
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 } |
OLD | NEW |