• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "apps/shell_window.h"
6 #include "apps/shell_window_registry.h"
7 #include "base/bind.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/profiles/profile_metrics.h"
11 #include "chrome/browser/profiles/profile_window.h"
12 #include "chrome/browser/profiles/profiles_state.h"
13 #include "chrome/browser/ui/browser_finder.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_ui.h"
16 
17 namespace options {
18 namespace helper {
19 
GetDesktopType(content::WebUI * web_ui)20 chrome::HostDesktopType GetDesktopType(content::WebUI* web_ui) {
21   DCHECK(web_ui);
22   content::WebContents* web_contents = web_ui->GetWebContents();
23   Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
24   if (browser)
25     return browser->host_desktop_type();
26 
27   apps::ShellWindow* shell_window =
28       apps::ShellWindowRegistry::Get(Profile::FromWebUI(web_ui))->
29           GetShellWindowForRenderViewHost(web_contents->GetRenderViewHost());
30   if (shell_window) {
31     return chrome::GetHostDesktopTypeForNativeWindow(
32         shell_window->GetNativeWindow());
33   }
34 
35   return chrome::GetActiveDesktop();
36 }
37 
OpenNewWindowForProfile(chrome::HostDesktopType desktop_type,Profile * profile,Profile::CreateStatus status)38 void OpenNewWindowForProfile(chrome::HostDesktopType desktop_type,
39                              Profile* profile,
40                              Profile::CreateStatus status) {
41   if (status != Profile::CREATE_STATUS_INITIALIZED)
42     return;
43 
44   profiles::FindOrCreateNewWindowForProfile(
45     profile,
46     chrome::startup::IS_PROCESS_STARTUP,
47     chrome::startup::IS_FIRST_RUN,
48     desktop_type,
49     false);
50 }
51 
DeleteProfileAtPath(base::FilePath file_path,content::WebUI * web_ui)52 void DeleteProfileAtPath(base::FilePath file_path, content::WebUI* web_ui) {
53   DCHECK(web_ui);
54   // This handler could have been called in managed mode, for example because
55   // the user fiddled with the web inspector. Silently return in this case.
56   if (Profile::FromWebUI(web_ui)->IsManaged())
57     return;
58 
59   if (!profiles::IsMultipleProfilesEnabled())
60     return;
61 
62   ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED);
63 
64   g_browser_process->profile_manager()->ScheduleProfileForDeletion(
65       file_path,
66       base::Bind(&OpenNewWindowForProfile, GetDesktopType(web_ui)));
67 }
68 
69 }  // namespace helper
70 }  // namespace options
71 
72 
73