| 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/ui/webui/options/create_profile_handler.h" | 5 #include "chrome/browser/ui/webui/options/create_profile_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/value_conversions.h" | 12 #include "base/value_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/managed_mode/managed_user_registration_utility.h" | 15 #include "chrome/browser/managed_mode/managed_user_registration_utility.h" |
| 16 #include "chrome/browser/managed_mode/managed_user_service.h" | 16 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 17 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | 17 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
| 18 #include "chrome/browser/managed_mode/managed_user_sync_service.h" | 18 #include "chrome/browser/managed_mode/managed_user_sync_service.h" |
| 19 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" | 19 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" |
| 20 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 21 #include "chrome/browser/profiles/profile_metrics.h" | 21 #include "chrome/browser/profiles/profile_metrics.h" |
| 22 #include "chrome/browser/profiles/profiles_state.h" | 22 #include "chrome/browser/profiles/profiles_state.h" |
| 23 #include "chrome/browser/sync/profile_sync_service.h" | 23 #include "chrome/browser/sync/profile_sync_service.h" |
| 24 #include "chrome/browser/sync/profile_sync_service_factory.h" | 24 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 25 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" | 25 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" |
| 26 #include "chrome/common/chrome_switches.h" | |
| 27 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 28 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 30 | 29 |
| 31 namespace options { | 30 namespace options { |
| 32 | 31 |
| 33 CreateProfileHandler::CreateProfileHandler() | 32 CreateProfileHandler::CreateProfileHandler() |
| 34 : profile_creation_type_(NO_CREATION_IN_PROGRESS), | 33 : profile_creation_type_(NO_CREATION_IN_PROGRESS), |
| 35 weak_ptr_factory_(this) { | 34 weak_ptr_factory_(this) { |
| 36 } | 35 } |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 | 404 |
| 406 NOTREACHED(); | 405 NOTREACHED(); |
| 407 return std::string(); | 406 return std::string(); |
| 408 } | 407 } |
| 409 | 408 |
| 410 bool CreateProfileHandler::IsValidExistingManagedUserId( | 409 bool CreateProfileHandler::IsValidExistingManagedUserId( |
| 411 const std::string& existing_managed_user_id) const { | 410 const std::string& existing_managed_user_id) const { |
| 412 if (existing_managed_user_id.empty()) | 411 if (existing_managed_user_id.empty()) |
| 413 return true; | 412 return true; |
| 414 | 413 |
| 415 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 416 switches::kDisableCreateExistingManagedUsers)) { | |
| 417 return false; | |
| 418 } | |
| 419 | |
| 420 Profile* profile = Profile::FromWebUI(web_ui()); | 414 Profile* profile = Profile::FromWebUI(web_ui()); |
| 421 const base::DictionaryValue* dict = | 415 const base::DictionaryValue* dict = |
| 422 ManagedUserSyncServiceFactory::GetForProfile(profile)->GetManagedUsers(); | 416 ManagedUserSyncServiceFactory::GetForProfile(profile)->GetManagedUsers(); |
| 423 if (!dict->HasKey(existing_managed_user_id)) | 417 if (!dict->HasKey(existing_managed_user_id)) |
| 424 return false; | 418 return false; |
| 425 | 419 |
| 426 // Check if this managed user already exists on this machine. | 420 // Check if this managed user already exists on this machine. |
| 427 const ProfileInfoCache& cache = | 421 const ProfileInfoCache& cache = |
| 428 g_browser_process->profile_manager()->GetProfileInfoCache(); | 422 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 429 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 423 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { |
| 430 if (existing_managed_user_id == cache.GetManagedUserIdOfProfileAtIndex(i)) | 424 if (existing_managed_user_id == cache.GetManagedUserIdOfProfileAtIndex(i)) |
| 431 return false; | 425 return false; |
| 432 } | 426 } |
| 433 return true; | 427 return true; |
| 434 } | 428 } |
| 435 | 429 |
| 436 } // namespace options | 430 } // namespace options |
| OLD | NEW |