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

Side by Side Diff: chrome/browser/ui/startup/startup_browser_creator_impl.cc

Issue 10700145: chromeos: Fix StartupBrowserCreatorImpl::Launch crash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ui/startup/startup_browser_creator_impl.h" 5 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 #include "chrome/common/chrome_notification_types.h" 64 #include "chrome/common/chrome_notification_types.h"
65 #include "chrome/common/chrome_paths.h" 65 #include "chrome/common/chrome_paths.h"
66 #include "chrome/common/chrome_result_codes.h" 66 #include "chrome/common/chrome_result_codes.h"
67 #include "chrome/common/chrome_switches.h" 67 #include "chrome/common/chrome_switches.h"
68 #include "chrome/common/chrome_version_info.h" 68 #include "chrome/common/chrome_version_info.h"
69 #include "chrome/common/extensions/extension_constants.h" 69 #include "chrome/common/extensions/extension_constants.h"
70 #include "chrome/common/pref_names.h" 70 #include "chrome/common/pref_names.h"
71 #include "chrome/common/url_constants.h" 71 #include "chrome/common/url_constants.h"
72 #include "chrome/installer/util/browser_distribution.h" 72 #include "chrome/installer/util/browser_distribution.h"
73 #include "content/public/browser/child_process_security_policy.h" 73 #include "content/public/browser/child_process_security_policy.h"
74 #include "content/public/browser/notification_observer.h"
75 #include "content/public/browser/notification_registrar.h"
74 #include "content/public/browser/web_contents.h" 76 #include "content/public/browser/web_contents.h"
75 #include "content/public/browser/web_contents_view.h" 77 #include "content/public/browser/web_contents_view.h"
76 #include "grit/locale_settings.h" 78 #include "grit/locale_settings.h"
77 #include "ui/base/l10n/l10n_util.h" 79 #include "ui/base/l10n/l10n_util.h"
78 #include "ui/base/resource/resource_bundle.h" 80 #include "ui/base/resource/resource_bundle.h"
79 81
80 #if defined(OS_MACOSX) 82 #if defined(OS_MACOSX)
81 #include "base/mac/mac_util.h" 83 #include "base/mac/mac_util.h"
82 #include "chrome/browser/ui/cocoa/keystone_infobar_delegate.h" 84 #include "chrome/browser/ui/cocoa/keystone_infobar_delegate.h"
83 #endif 85 #endif
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 219 }
218 } 220 }
219 for (size_t i = 0; i < autolaunch_tabs.size(); ++i) { 221 for (size_t i = 0; i < autolaunch_tabs.size(); ++i) {
220 if (extension_service->IsInstalledApp(autolaunch_tabs.at(i).url)) { 222 if (extension_service->IsInstalledApp(autolaunch_tabs.at(i).url)) {
221 AppLauncherHandler::RecordAppLaunchType( 223 AppLauncherHandler::RecordAppLaunchType(
222 extension_misc::APP_LAUNCH_AUTOLAUNCH); 224 extension_misc::APP_LAUNCH_AUTOLAUNCH);
223 } 225 }
224 } 226 }
225 } 227 }
226 228
229 class WebContentsCloseObserver : public content::NotificationObserver {
230 public:
231 WebContentsCloseObserver() : contents_(NULL) {}
232 virtual ~WebContentsCloseObserver() {}
233
234 void SetContents(content::WebContents* contents) {
235 DCHECK(!contents);
Ben Goodger (Google) 2012/07/10 21:13:22 DCHECK(!contents_)?
xiyuan 2012/07/10 21:21:04 Oops. Fixed now. :p
236 contents_ = contents;
237
238 registrar_.Add(this,
239 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
240 content::Source<content::WebContents>(contents_));
241 }
242
243 content::WebContents* contents() { return contents_; }
244
245 private:
246 // content::NotificationObserver overrides:
247 virtual void Observe(int type,
248 const content::NotificationSource& source,
249 const content::NotificationDetails& details) OVERRIDE {
250 DCHECK_EQ(type, content::NOTIFICATION_WEB_CONTENTS_DESTROYED);
251 contents_ = NULL;
252 }
253
254 content::WebContents* contents_;
255 content::NotificationRegistrar registrar_;
256
257 DISALLOW_COPY_AND_ASSIGN(WebContentsCloseObserver);
258 };
259
227 } // namespace 260 } // namespace
228 261
229 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( 262 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl(
230 const FilePath& cur_dir, 263 const FilePath& cur_dir,
231 const CommandLine& command_line, 264 const CommandLine& command_line,
232 chrome::startup::IsFirstRun is_first_run) 265 chrome::startup::IsFirstRun is_first_run)
233 : cur_dir_(cur_dir), 266 : cur_dir_(cur_dir),
234 command_line_(command_line), 267 command_line_(command_line),
235 profile_(NULL), 268 profile_(NULL),
236 browser_creator_(NULL), 269 browser_creator_(NULL),
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 !browser_defaults::kAppRestoreSession) { 333 !browser_defaults::kAppRestoreSession) {
301 RecordLaunchModeHistogram(LM_AS_WEBAPP); 334 RecordLaunchModeHistogram(LM_AS_WEBAPP);
302 } else { 335 } else {
303 RecordLaunchModeHistogram(urls_to_open.empty() ? 336 RecordLaunchModeHistogram(urls_to_open.empty() ?
304 LM_TO_BE_DECIDED : LM_WITH_URLS); 337 LM_TO_BE_DECIDED : LM_WITH_URLS);
305 338
306 // Notify user if the Preferences backup is invalid or changes to settings 339 // Notify user if the Preferences backup is invalid or changes to settings
307 // affecting browser startup have been detected. 340 // affecting browser startup have been detected.
308 CheckPreferencesBackup(profile); 341 CheckPreferencesBackup(profile);
309 342
343 // Watch for |app_contents| closing since ProcessLaunchURLs might run a
344 // synchronous session restore which has a nested message loop and could
345 // close |app_contents|.
346 WebContentsCloseObserver app_contents_observer;
347 if (browser_defaults::kAppRestoreSession && app_contents)
348 app_contents_observer.SetContents(app_contents);
349
310 ProcessLaunchURLs(process_startup, urls_to_open); 350 ProcessLaunchURLs(process_startup, urls_to_open);
311 351
312 // If this is an app launch, but we didn't open an app window, it may 352 // If this is an app launch, but we didn't open an app window, it may
313 // be an app tab. 353 // be an app tab.
314 OpenApplicationTab(profile); 354 OpenApplicationTab(profile);
315 355
316 // In case of app mode + session restore we want to focus that app. 356 // In case of app mode + session restore we want to focus that app.
317 if (browser_defaults::kAppRestoreSession && app_contents) 357 if (app_contents_observer.contents())
318 app_contents->GetView()->SetInitialFocus(); 358 app_contents_observer.contents()->GetView()->SetInitialFocus();
319 359
320 if (process_startup) { 360 if (process_startup) {
321 if (browser_defaults::kOSSupportsOtherBrowsers && 361 if (browser_defaults::kOSSupportsOtherBrowsers &&
322 !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) { 362 !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) {
323 if (!chrome::ShowAutolaunchPrompt(profile)) 363 if (!chrome::ShowAutolaunchPrompt(profile))
324 chrome::ShowDefaultBrowserPrompt(profile); 364 chrome::ShowDefaultBrowserPrompt(profile);
325 } 365 }
326 #if defined(OS_MACOSX) 366 #if defined(OS_MACOSX)
327 // Check whether the auto-update system needs to be promoted from user 367 // Check whether the auto-update system needs to be promoted from user
328 // to system. 368 // to system.
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 // New: 900 // New:
861 prefs->GetString(prefs::kHomePage), 901 prefs->GetString(prefs::kHomePage),
862 prefs->GetBoolean(prefs::kHomePageIsNewTabPage), 902 prefs->GetBoolean(prefs::kHomePageIsNewTabPage),
863 prefs->GetBoolean(prefs::kShowHomeButton), 903 prefs->GetBoolean(prefs::kShowHomeButton),
864 // Backup: 904 // Backup:
865 backup_homepage, 905 backup_homepage,
866 backup_homepage_is_ntp, 906 backup_homepage_is_ntp,
867 backup_show_home_button)); 907 backup_show_home_button));
868 } 908 }
869 } 909 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698