OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/profiles/profile_window.h" | 5 #include "chrome/browser/profiles/profile_window.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/about_flags.h" | 12 #include "chrome/browser/about_flags.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/lifetime/application_lifetime.h" | 14 #include "chrome/browser/lifetime/application_lifetime.h" |
15 #include "chrome/browser/pref_service_flags_storage.h" | 15 #include "chrome/browser/pref_service_flags_storage.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 17 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/browser/signin/account_reconcilor_factory.h" | 19 #include "chrome/browser/signin/account_reconcilor_factory.h" |
| 20 #include "chrome/browser/sync/profile_sync_service.h" |
| 21 #include "chrome/browser/sync/profile_sync_service_factory.h" |
20 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/browser_dialogs.h" | 23 #include "chrome/browser/ui/browser_dialogs.h" |
22 #include "chrome/browser/ui/profile_chooser_constants.h" | 24 #include "chrome/browser/ui/profile_chooser_constants.h" |
23 #include "chrome/browser/ui/user_manager.h" | 25 #include "chrome/browser/ui/user_manager.h" |
24 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
26 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
27 #include "components/signin/core/browser/account_reconcilor.h" | 29 #include "components/signin/core/browser/account_reconcilor.h" |
28 #include "components/signin/core/common/profile_management_switches.h" | 30 #include "components/signin/core/common/profile_management_switches.h" |
29 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
30 #include "content/public/browser/user_metrics.h" | 32 #include "content/public/browser/user_metrics.h" |
31 | 33 |
| 34 #if defined(ENABLE_EXTENSIONS) |
| 35 #include "chrome/browser/extensions/extension_service.h" |
| 36 #include "extensions/browser/extension_prefs.h" |
| 37 #include "extensions/browser/extension_registry.h" |
| 38 #include "extensions/browser/extension_registry_factory.h" |
| 39 #include "extensions/browser/extension_system.h" |
| 40 #endif // defined(ENABLE_EXTENSIONS) |
| 41 |
32 #if !defined(OS_IOS) | 42 #if !defined(OS_IOS) |
33 #include "chrome/browser/ui/browser_finder.h" | 43 #include "chrome/browser/ui/browser_finder.h" |
34 #include "chrome/browser/ui/browser_list.h" | 44 #include "chrome/browser/ui/browser_list.h" |
35 #include "chrome/browser/ui/browser_list_observer.h" | 45 #include "chrome/browser/ui/browser_list_observer.h" |
36 #include "chrome/browser/ui/browser_window.h" | 46 #include "chrome/browser/ui/browser_window.h" |
37 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 47 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
38 #endif // !defined (OS_IOS) | 48 #endif // !defined (OS_IOS) |
39 | 49 |
40 using base::UserMetricsAction; | 50 using base::UserMetricsAction; |
41 using content::BrowserThread; | 51 using content::BrowserThread; |
42 | 52 |
43 namespace { | 53 namespace { |
44 | 54 |
45 const char kNewProfileManagementExperimentInternalName[] = | 55 const char kNewProfileManagementExperimentInternalName[] = |
46 "enable-new-profile-management"; | 56 "enable-new-profile-management"; |
47 | 57 |
| 58 #if defined(ENABLE_EXTENSIONS) |
| 59 void BlockExtensions(Profile* profile) { |
| 60 ExtensionService* extension_service = |
| 61 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 62 extension_service->BlockAllExtensions(); |
| 63 } |
| 64 |
| 65 void UnblockExtensions(Profile* profile) { |
| 66 ExtensionService* extension_service = |
| 67 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 68 extension_service->UnblockAllExtensions(); |
| 69 } |
| 70 #endif // defined(ENABLE_EXTENSIONS) |
| 71 |
48 // Handles running a callback when a new Browser for the given profile | 72 // Handles running a callback when a new Browser for the given profile |
49 // has been completely created. | 73 // has been completely created. |
50 class BrowserAddedForProfileObserver : public chrome::BrowserListObserver { | 74 class BrowserAddedForProfileObserver : public chrome::BrowserListObserver { |
51 public: | 75 public: |
52 BrowserAddedForProfileObserver( | 76 BrowserAddedForProfileObserver( |
53 Profile* profile, | 77 Profile* profile, |
54 ProfileManager::CreateCallback callback) | 78 ProfileManager::CreateCallback callback) |
55 : profile_(profile), | 79 : profile_(profile), |
56 callback_(callback) { | 80 callback_(callback) { |
57 DCHECK(!callback_.is_null()); | 81 DCHECK(!callback_.is_null()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 chrome::startup::IsProcessStartup is_process_startup = | 115 chrome::startup::IsProcessStartup is_process_startup = |
92 chrome::startup::IS_NOT_PROCESS_STARTUP; | 116 chrome::startup::IS_NOT_PROCESS_STARTUP; |
93 chrome::startup::IsFirstRun is_first_run = chrome::startup::IS_NOT_FIRST_RUN; | 117 chrome::startup::IsFirstRun is_first_run = chrome::startup::IS_NOT_FIRST_RUN; |
94 | 118 |
95 // If this is a brand new profile, then start a first run window. | 119 // If this is a brand new profile, then start a first run window. |
96 if (is_new_profile) { | 120 if (is_new_profile) { |
97 is_process_startup = chrome::startup::IS_PROCESS_STARTUP; | 121 is_process_startup = chrome::startup::IS_PROCESS_STARTUP; |
98 is_first_run = chrome::startup::IS_FIRST_RUN; | 122 is_first_run = chrome::startup::IS_FIRST_RUN; |
99 } | 123 } |
100 | 124 |
| 125 #if defined(ENABLE_EXTENSIONS) |
| 126 // The signin bit will still be set if the profile is being unlocked and the |
| 127 // browser window for it is opening. As part of this unlock process, unblock |
| 128 // all the extensions. |
| 129 const ProfileInfoCache& cache = |
| 130 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 131 int index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 132 if (!profile->IsGuestSession() && |
| 133 cache.ProfileIsSigninRequiredAtIndex(index)) { |
| 134 UnblockExtensions(profile); |
| 135 } |
| 136 #endif // defined(ENABLE_EXTENSIONS) |
| 137 |
101 // If |always_create| is false, and we have a |callback| to run, check | 138 // If |always_create| is false, and we have a |callback| to run, check |
102 // whether a browser already exists so that we can run the callback. We don't | 139 // whether a browser already exists so that we can run the callback. We don't |
103 // want to rely on the observer listening to OnBrowserSetLastActive in this | 140 // want to rely on the observer listening to OnBrowserSetLastActive in this |
104 // case, as you could manually activate an incorrect browser and trigger | 141 // case, as you could manually activate an incorrect browser and trigger |
105 // a false positive. | 142 // a false positive. |
106 if (!always_create) { | 143 if (!always_create) { |
107 Browser* browser = chrome::FindTabbedBrowser(profile, false, desktop_type); | 144 Browser* browser = chrome::FindTabbedBrowser(profile, false, desktop_type); |
108 if (browser) { | 145 if (browser) { |
109 browser->window()->Activate(); | 146 browser->window()->Activate(); |
110 if (!callback.is_null()) | 147 if (!callback.is_null()) |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 Profile* profile = profile_manager->GetProfileByPath( | 327 Profile* profile = profile_manager->GetProfileByPath( |
291 ProfileManager::GetGuestProfilePath()); | 328 ProfileManager::GetGuestProfilePath()); |
292 | 329 |
293 if (profile) { | 330 if (profile) { |
294 BrowserList::CloseAllBrowsersWithProfile( | 331 BrowserList::CloseAllBrowsersWithProfile( |
295 profile, base::Bind(&GuestBrowserCloseSuccess)); | 332 profile, base::Bind(&GuestBrowserCloseSuccess)); |
296 } | 333 } |
297 } | 334 } |
298 | 335 |
299 void LockBrowserCloseSuccess(const base::FilePath& profile_path) { | 336 void LockBrowserCloseSuccess(const base::FilePath& profile_path) { |
300 ProfileInfoCache* cache = | 337 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
301 &g_browser_process->profile_manager()->GetProfileInfoCache(); | 338 ProfileInfoCache* cache = &profile_manager->GetProfileInfoCache(); |
302 | 339 |
303 cache->SetProfileSigninRequiredAtIndex( | 340 cache->SetProfileSigninRequiredAtIndex( |
304 cache->GetIndexOfProfileWithPath(profile_path), true); | 341 cache->GetIndexOfProfileWithPath(profile_path), true); |
| 342 |
| 343 #if defined(ENABLE_EXTENSIONS) |
| 344 // Profile guaranteed to exist for it to have been locked. |
| 345 BlockExtensions(profile_manager->GetProfileByPath(profile_path)); |
| 346 #endif // defined(ENABLE_EXTENSIONS) |
| 347 |
305 chrome::HideTaskManager(); | 348 chrome::HideTaskManager(); |
306 UserManager::Show(profile_path, | 349 UserManager::Show(profile_path, |
307 profiles::USER_MANAGER_NO_TUTORIAL, | 350 profiles::USER_MANAGER_NO_TUTORIAL, |
308 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 351 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
309 } | 352 } |
310 | 353 |
311 void LockProfile(Profile* profile) { | 354 void LockProfile(Profile* profile) { |
312 DCHECK(profile); | 355 DCHECK(profile); |
313 if (profile) { | 356 if (profile) { |
314 BrowserList::CloseAllBrowsersWithProfile( | 357 BrowserList::CloseAllBrowsersWithProfile( |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 case BrowserWindow::AVATAR_BUBBLE_MODE_SHOW_ERROR: | 485 case BrowserWindow::AVATAR_BUBBLE_MODE_SHOW_ERROR: |
443 *bubble_view_mode = BUBBLE_VIEW_MODE_PROFILE_CHOOSER; | 486 *bubble_view_mode = BUBBLE_VIEW_MODE_PROFILE_CHOOSER; |
444 *tutorial_mode = TUTORIAL_MODE_SHOW_ERROR; | 487 *tutorial_mode = TUTORIAL_MODE_SHOW_ERROR; |
445 return; | 488 return; |
446 default: | 489 default: |
447 *bubble_view_mode = profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER; | 490 *bubble_view_mode = profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER; |
448 } | 491 } |
449 } | 492 } |
450 | 493 |
451 } // namespace profiles | 494 } // namespace profiles |
OLD | NEW |