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 LockExtensions(Profile* profile) { | |
60 ExtensionService* extension_service = | |
61 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
62 extension_service->LockAllExtensions(); | |
noms (inactive)
2014/11/12 19:23:51
Can this ever be NULL?
Mike Lerman
2014/11/12 20:58:42
I don't think so, so long as ENABLE_EXTENSIONS is
| |
63 } | |
64 | |
65 void UnlockExtensions(Profile* profile) { | |
66 ExtensionService* extension_service = | |
67 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
68 extension_service->UnlockAllLockedExtensions(); | |
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 // Determine if there are extensions to unlock, then do so. | |
127 const ProfileInfoCache& cache = | |
128 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
129 int index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | |
130 if (!profile->IsGuestSession() && | |
131 cache.ProfileIsSigninRequiredAtIndex(index)) { | |
noms (inactive)
2014/11/12 19:23:51
I read this as "if this profile is locked, then un
Mike Lerman
2014/11/12 20:58:42
We intentionally don't unset the bit within user_m
| |
132 UnlockExtensions(profile); | |
133 } | |
134 #endif // defined(ENABLE_EXTENSIONS) | |
135 | |
101 // If |always_create| is false, and we have a |callback| to run, check | 136 // 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 | 137 // 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 | 138 // want to rely on the observer listening to OnBrowserSetLastActive in this |
104 // case, as you could manually activate an incorrect browser and trigger | 139 // case, as you could manually activate an incorrect browser and trigger |
105 // a false positive. | 140 // a false positive. |
106 if (!always_create) { | 141 if (!always_create) { |
107 Browser* browser = chrome::FindTabbedBrowser(profile, false, desktop_type); | 142 Browser* browser = chrome::FindTabbedBrowser(profile, false, desktop_type); |
108 if (browser) { | 143 if (browser) { |
109 browser->window()->Activate(); | 144 browser->window()->Activate(); |
110 if (!callback.is_null()) | 145 if (!callback.is_null()) |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 Profile* profile = profile_manager->GetProfileByPath( | 325 Profile* profile = profile_manager->GetProfileByPath( |
291 ProfileManager::GetGuestProfilePath()); | 326 ProfileManager::GetGuestProfilePath()); |
292 | 327 |
293 if (profile) { | 328 if (profile) { |
294 BrowserList::CloseAllBrowsersWithProfile( | 329 BrowserList::CloseAllBrowsersWithProfile( |
295 profile, base::Bind(&GuestBrowserCloseSuccess)); | 330 profile, base::Bind(&GuestBrowserCloseSuccess)); |
296 } | 331 } |
297 } | 332 } |
298 | 333 |
299 void LockBrowserCloseSuccess(const base::FilePath& profile_path) { | 334 void LockBrowserCloseSuccess(const base::FilePath& profile_path) { |
300 ProfileInfoCache* cache = | 335 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
301 &g_browser_process->profile_manager()->GetProfileInfoCache(); | 336 ProfileInfoCache* cache = &profile_manager->GetProfileInfoCache(); |
302 | 337 |
303 cache->SetProfileSigninRequiredAtIndex( | 338 cache->SetProfileSigninRequiredAtIndex( |
304 cache->GetIndexOfProfileWithPath(profile_path), true); | 339 cache->GetIndexOfProfileWithPath(profile_path), true); |
340 | |
341 #if defined(ENABLE_EXTENSIONS) | |
342 LockExtensions(profile_manager->GetProfileByPath(profile_path)); | |
noms (inactive)
2014/11/12 19:23:51
I would either add a comment about how this profil
Mike Lerman
2014/11/12 20:58:42
Comment written.
| |
343 #endif // defined(ENABLE_EXTENSIONS) | |
344 | |
305 chrome::HideTaskManager(); | 345 chrome::HideTaskManager(); |
306 UserManager::Show(profile_path, | 346 UserManager::Show(profile_path, |
307 profiles::USER_MANAGER_NO_TUTORIAL, | 347 profiles::USER_MANAGER_NO_TUTORIAL, |
308 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 348 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
309 } | 349 } |
310 | 350 |
311 void LockProfile(Profile* profile) { | 351 void LockProfile(Profile* profile) { |
312 DCHECK(profile); | 352 DCHECK(profile); |
313 if (profile) { | 353 if (profile) { |
314 BrowserList::CloseAllBrowsersWithProfile( | 354 BrowserList::CloseAllBrowsersWithProfile( |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 case BrowserWindow::AVATAR_BUBBLE_MODE_SHOW_ERROR: | 482 case BrowserWindow::AVATAR_BUBBLE_MODE_SHOW_ERROR: |
443 *bubble_view_mode = BUBBLE_VIEW_MODE_PROFILE_CHOOSER; | 483 *bubble_view_mode = BUBBLE_VIEW_MODE_PROFILE_CHOOSER; |
444 *tutorial_mode = TUTORIAL_MODE_SHOW_ERROR; | 484 *tutorial_mode = TUTORIAL_MODE_SHOW_ERROR; |
445 return; | 485 return; |
446 default: | 486 default: |
447 *bubble_view_mode = profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER; | 487 *bubble_view_mode = profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER; |
448 } | 488 } |
449 } | 489 } |
450 | 490 |
451 } // namespace profiles | 491 } // namespace profiles |
OLD | NEW |