Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / profiles / profile_manager.cc
index bf18085..b48c2ac 100644 (file)
@@ -10,9 +10,9 @@
 #include "base/command_line.h"
 #include "base/debug/trace_event.h"
 #include "base/deferred_sequenced_task_runner.h"
-#include "base/file_util.h"
 #include "base/files/file_enumerator.h"
 #include "base/files/file_path.h"
+#include "base/files/file_util.h"
 #include "base/metrics/histogram.h"
 #include "base/prefs/pref_service.h"
 #include "base/prefs/scoped_user_pref_update.h"
@@ -36,6 +36,7 @@
 #include "chrome/browser/profiles/startup_task_runner_service.h"
 #include "chrome/browser/profiles/startup_task_runner_service_factory.h"
 #include "chrome/browser/signin/account_reconcilor_factory.h"
+#include "chrome/browser/signin/account_tracker_service_factory.h"
 #include "chrome/browser/sync/profile_sync_service.h"
 #include "chrome/browser/sync/profile_sync_service_factory.h"
 #include "chrome/browser/ui/browser.h"
 #include "chrome/common/logging_chrome.h"
 #include "chrome/common/pref_names.h"
 #include "chrome/common/url_constants.h"
+#include "chrome/grit/generated_resources.h"
 #include "components/bookmarks/browser/bookmark_model.h"
 #include "components/password_manager/core/browser/password_store.h"
 #include "components/signin/core/common/profile_management_switches.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/notification_service.h"
 #include "content/public/browser/user_metrics.h"
-#include "extensions/browser/extension_registry.h"
-#include "extensions/common/extension_set.h"
-#include "extensions/common/manifest.h"
-#include "grit/generated_resources.h"
 #include "net/http/http_transaction_factory.h"
 #include "net/url_request/url_request_context.h"
 #include "net/url_request/url_request_context_getter.h"
 #include "net/url_request/url_request_job.h"
 #include "ui/base/l10n/l10n_util.h"
 
+#if defined(ENABLE_EXTENSIONS)
+#include "chrome/browser/extensions/extension_service.h"
+#include "extensions/browser/extension_registry.h"
+#include "extensions/browser/extension_system.h"
+#include "extensions/common/extension_set.h"
+#include "extensions/common/manifest.h"
+#endif
+
 #if defined(ENABLE_MANAGED_USERS)
 #include "chrome/browser/supervised_user/supervised_user_service.h"
 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
 #endif
 
 #if !defined(OS_IOS)
-#include "chrome/browser/extensions/extension_service.h"
 #include "chrome/browser/sessions/session_service_factory.h"
 #include "chrome/browser/ui/browser_list.h"
-#include "extensions/browser/extension_system.h"
 #endif  // !defined (OS_IOS)
 
 #if defined(OS_WIN)
@@ -83,7 +87,6 @@
 #if defined(OS_CHROMEOS)
 #include "chrome/browser/browser_process_platform_part_chromeos.h"
 #include "chrome/browser/chromeos/profiles/profile_helper.h"
-#include "chrome/browser/profiles/profiles_state.h"
 #include "chromeos/chromeos_switches.h"
 #include "chromeos/dbus/cryptohome_client.h"
 #include "chromeos/dbus/dbus_thread_manager.h"
@@ -218,7 +221,7 @@ size_t GetEnabledAppCount(Profile* profile) {
 
 #endif  // ENABLE_EXTENSIONS
 
-} // namespace
+}  // namespace
 
 ProfileManager::ProfileManager(const base::FilePath& user_data_dir)
     : user_data_dir_(user_data_dir),
@@ -331,6 +334,9 @@ Profile* ProfileManager::GetPrimaryUserProfile() {
 Profile* ProfileManager::GetActiveUserProfile() {
   ProfileManager* profile_manager = g_browser_process->profile_manager();
 #if defined(OS_CHROMEOS)
+  if (!profile_manager)
+    return NULL;
+
   if (!profile_manager->IsLoggedIn() ||
       !user_manager::UserManager::IsInitialized()) {
     return profile_manager->GetActiveUserOrOffTheRecordProfileFromPath(
@@ -461,35 +467,14 @@ bool ProfileManager::IsValidProfile(Profile* profile) {
 }
 
 base::FilePath ProfileManager::GetInitialProfileDir() {
-  base::FilePath relative_profile_dir;
 #if defined(OS_CHROMEOS)
-  const CommandLine& command_line = *CommandLine::ForCurrentProcess();
   if (logged_in_) {
-    base::FilePath profile_dir;
-    // If the user has logged in, pick up the new profile.
-    if (command_line.HasSwitch(chromeos::switches::kLoginProfile)) {
-      // TODO(nkostylev): Remove this code completely once we eliminate
-      // legacy --login-profile=user switch and enable multi-profiles on CrOS
-      // by default. http://crbug.com/294628
-      profile_dir = chromeos::ProfileHelper::
-          GetProfileDirByLegacyLoginProfileSwitch();
-    }
-    // In case of multi-profiles ignore --login-profile switch.
-    // TODO(nkostylev): Some cases like Guest mode will have empty username_hash
-    // so default kLoginProfile dir will be used.
-    std::string user_id_hash =
-        chromeos::ProfileHelper::Get()->active_user_id_hash();
-    if (!user_id_hash.empty())
-      profile_dir = chromeos::ProfileHelper::Get()->GetActiveUserProfileDir();
-
-    relative_profile_dir = relative_profile_dir.Append(profile_dir);
-    return relative_profile_dir;
+    return chromeos::ProfileHelper::Get()->GetActiveUserProfileDir();
   }
 #endif
+  base::FilePath relative_profile_dir;
   // TODO(mirandac): should not automatically be default profile.
-  relative_profile_dir =
-      relative_profile_dir.AppendASCII(chrome::kInitialProfile);
-  return relative_profile_dir;
+  return relative_profile_dir.AppendASCII(chrome::kInitialProfile);
 }
 
 Profile* ProfileManager::GetLastUsedProfile(
@@ -1002,8 +987,8 @@ void ProfileManager::DoFinalInitForServices(Profile* profile,
   // During tests, when |profile| is an instance of TestingProfile,
   // ExtensionSystem might not create an ExtensionService.
   if (extensions::ExtensionSystem::Get(profile)->extension_service()) {
-    profile->GetHostContentSettingsMap()->RegisterExtensionService(
-        extensions::ExtensionSystem::Get(profile)->extension_service());
+    extensions::ExtensionSystem::Get(profile)->extension_service()->
+        RegisterContentSettings(profile->GetHostContentSettingsMap());
   }
 #endif
 #if defined(ENABLE_MANAGED_USERS) && !defined(OS_ANDROID)
@@ -1016,6 +1001,7 @@ void ProfileManager::DoFinalInitForServices(Profile* profile,
   StartupTaskRunnerServiceFactory::GetForProfile(profile)->
       StartDeferredTaskRunners();
 
+  AccountTrackerServiceFactory::GetForProfile(profile);
   AccountReconcilorFactory::GetForProfile(profile);
 }
 
@@ -1133,7 +1119,7 @@ void ProfileManager::FinishDeletingProfile(const base::FilePath& profile_dir) {
     scoped_refptr<password_manager::PasswordStore> password_store =
         PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS)
             .get();
-    if (password_store) {
+    if (password_store.get()) {
       password_store->RemoveLoginsCreatedBetween(base::Time(),
                                                  base::Time::Max());
     }
@@ -1198,8 +1184,8 @@ void ProfileManager::AddProfileToCache(Profile* profile) {
 void ProfileManager::SetGuestProfilePrefs(Profile* profile) {
   PrefService* prefs = profile->GetPrefs();
   prefs->SetBoolean(prefs::kSigninAllowed, false);
-  prefs->SetBoolean(prefs::kEditBookmarksEnabled, false);
-  prefs->SetBoolean(prefs::kShowBookmarkBar, false);
+  prefs->SetBoolean(bookmarks::prefs::kEditBookmarksEnabled, false);
+  prefs->SetBoolean(bookmarks::prefs::kShowBookmarkBar, false);
   // This can be removed in the future but needs to be present through
   // a release (or two) so that any existing installs get switched to
   // the new state and away from the previous "forced" state.
@@ -1208,10 +1194,7 @@ void ProfileManager::SetGuestProfilePrefs(Profile* profile) {
 
 bool ProfileManager::ShouldGoOffTheRecord(Profile* profile) {
 #if defined(OS_CHROMEOS)
-  const CommandLine& command_line = *CommandLine::ForCurrentProcess();
-  if (profile->GetPath().BaseName().value() == chrome::kInitialProfile &&
-      (!command_line.HasSwitch(switches::kTestType) ||
-       command_line.HasSwitch(chromeos::switches::kLoginProfile))) {
+  if (profile->GetPath().BaseName().value() == chrome::kInitialProfile) {
     return true;
   }
 #endif
@@ -1237,6 +1220,22 @@ ProfileManager::ProfileInfo::~ProfileInfo() {
 }
 
 #if !defined(OS_ANDROID) && !defined(OS_IOS)
+void ProfileManager::UpdateLastUser(Profile* last_active) {
+  PrefService* local_state = g_browser_process->local_state();
+  DCHECK(local_state);
+  // Only keep track of profiles that we are managing; tests may create others.
+  if (profiles_info_.find(last_active->GetPath()) != profiles_info_.end()) {
+    local_state->SetString(prefs::kProfileLastUsed,
+                           last_active->GetPath().BaseName().MaybeAsASCII());
+
+    ProfileInfoCache& cache = GetProfileInfoCache();
+    size_t profile_index =
+        cache.GetIndexOfProfileWithPath(last_active->GetPath());
+    if (profile_index != std::string::npos)
+      cache.SetProfileActiveTimeAtIndex(profile_index);
+  }
+}
+
 ProfileManager::BrowserListObserver::BrowserListObserver(
     ProfileManager* manager)
     : profile_manager_(manager) {
@@ -1285,20 +1284,7 @@ void ProfileManager::BrowserListObserver::OnBrowserSetLastActive(
   if (last_active->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles))
     return;
 
-  PrefService* local_state = g_browser_process->local_state();
-  DCHECK(local_state);
-  // Only keep track of profiles that we are managing; tests may create others.
-  if (profile_manager_->profiles_info_.find(
-      last_active->GetPath()) != profile_manager_->profiles_info_.end()) {
-    local_state->SetString(prefs::kProfileLastUsed,
-                           last_active->GetPath().BaseName().MaybeAsASCII());
-
-    ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache();
-    size_t profile_index =
-        cache.GetIndexOfProfileWithPath(last_active->GetPath());
-    if (profile_index != std::string::npos)
-      cache.SetProfileActiveTimeAtIndex(profile_index);
-  }
+  profile_manager_->UpdateLastUser(last_active);
 }
 #endif  // !defined(OS_ANDROID) && !defined(OS_IOS)