1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "chrome/browser/browser_process.h"
7 #include "chrome/browser/profiles/profile_manager.h"
8 #include "chrome/browser/profiles/profile_metrics.h"
9 #include "chrome/browser/profiles/profile_window.h"
10 #include "chrome/browser/profiles/profiles_state.h"
11 #include "chrome/browser/ui/browser_finder.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_ui.h"
14 #include "extensions/browser/app_window/app_window.h"
15 #include "extensions/browser/app_window/app_window_registry.h"
20 chrome::HostDesktopType
GetDesktopType(content::WebUI
* web_ui
) {
22 content::WebContents
* web_contents
= web_ui
->GetWebContents();
23 Browser
* browser
= chrome::FindBrowserWithWebContents(web_contents
);
25 return browser
->host_desktop_type();
27 extensions::AppWindow
* app_window
=
28 extensions::AppWindowRegistry::Get(Profile::FromWebUI(web_ui
))
29 ->GetAppWindowForWebContents(web_contents
);
31 return chrome::GetHostDesktopTypeForNativeWindow(
32 app_window
->GetNativeWindow());
35 return chrome::GetActiveDesktop();
38 void OpenNewWindowForProfile(chrome::HostDesktopType desktop_type
,
40 Profile::CreateStatus status
) {
41 if (status
!= Profile::CREATE_STATUS_INITIALIZED
)
44 profiles::FindOrCreateNewWindowForProfile(
46 chrome::startup::IS_PROCESS_STARTUP
,
47 chrome::startup::IS_FIRST_RUN
,
52 void DeleteProfileAtPath(base::FilePath file_path
, content::WebUI
* web_ui
) {
55 if (!profiles::IsMultipleProfilesEnabled())
58 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::DELETE_PROFILE_SETTINGS
);
60 g_browser_process
->profile_manager()->ScheduleProfileForDeletion(
62 base::Bind(&OpenNewWindowForProfile
, GetDesktopType(web_ui
)));
66 } // namespace options