| 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/app_list/app_list_service_impl.h" | 5 #include "chrome/browser/ui/app_list/app_list_service_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 19 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/browser_shutdown.h" | 22 #include "chrome/browser/browser_shutdown.h" |
| 23 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 24 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 23 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 24 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" | 26 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" |
| 25 #include "chrome/browser/ui/app_list/profile_loader.h" | 27 #include "chrome/browser/ui/app_list/profile_loader.h" |
| 26 #include "chrome/browser/ui/app_list/profile_store.h" | 28 #include "chrome/browser/ui/app_list/profile_store.h" |
| 27 #include "chrome/common/chrome_constants.h" | 29 #include "chrome/common/chrome_constants.h" |
| 28 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 29 #include "ui/app_list/app_list_model.h" | 31 #include "ui/app_list/app_list_model.h" |
| 30 #include "ui/app_list/app_list_switches.h" | 32 #include "ui/app_list/app_list_switches.h" |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } | 88 } |
| 87 } | 89 } |
| 88 | 90 |
| 89 class ProfileStoreImpl : public ProfileStore { | 91 class ProfileStoreImpl : public ProfileStore { |
| 90 public: | 92 public: |
| 91 explicit ProfileStoreImpl(ProfileManager* profile_manager) | 93 explicit ProfileStoreImpl(ProfileManager* profile_manager) |
| 92 : profile_manager_(profile_manager), | 94 : profile_manager_(profile_manager), |
| 93 weak_factory_(this) { | 95 weak_factory_(this) { |
| 94 } | 96 } |
| 95 | 97 |
| 96 void AddProfileObserver(ProfileInfoCacheObserver* observer) override { | 98 void AddProfileObserver(ProfileAttributesStorageObserver* observer) override { |
| 97 profile_manager_->GetProfileInfoCache().AddObserver(observer); | 99 profile_manager_->GetProfileAttributesStorage().AddObserver(observer); |
| 98 } | 100 } |
| 99 | 101 |
| 100 void LoadProfileAsync(const base::FilePath& path, | 102 void LoadProfileAsync(const base::FilePath& path, |
| 101 base::Callback<void(Profile*)> callback) override { | 103 base::Callback<void(Profile*)> callback) override { |
| 102 profile_manager_->CreateProfileAsync( | 104 profile_manager_->CreateProfileAsync( |
| 103 path, | 105 path, |
| 104 base::Bind(&ProfileStoreImpl::OnProfileCreated, | 106 base::Bind(&ProfileStoreImpl::OnProfileCreated, |
| 105 weak_factory_.GetWeakPtr(), | 107 weak_factory_.GetWeakPtr(), |
| 106 callback), | 108 callback), |
| 107 base::string16(), | 109 base::string16(), |
| (...skipping 27 matching lines...) Expand all Loading... |
| 135 | 137 |
| 136 base::FilePath GetUserDataDir() override { | 138 base::FilePath GetUserDataDir() override { |
| 137 return profile_manager_->user_data_dir(); | 139 return profile_manager_->user_data_dir(); |
| 138 } | 140 } |
| 139 | 141 |
| 140 std::string GetLastUsedProfileName() override { | 142 std::string GetLastUsedProfileName() override { |
| 141 return profile_manager_->GetLastUsedProfileName(); | 143 return profile_manager_->GetLastUsedProfileName(); |
| 142 } | 144 } |
| 143 | 145 |
| 144 bool IsProfileSupervised(const base::FilePath& profile_path) override { | 146 bool IsProfileSupervised(const base::FilePath& profile_path) override { |
| 145 ProfileInfoCache& profile_info = | 147 ProfileAttributesEntry* entry = nullptr; |
| 146 g_browser_process->profile_manager()->GetProfileInfoCache(); | 148 bool has_entry = g_browser_process->profile_manager()-> |
| 147 size_t profile_index = profile_info.GetIndexOfProfileWithPath(profile_path); | 149 GetProfileAttributesStorage(). |
| 148 return profile_index != std::string::npos && | 150 GetProfileAttributesWithPath(profile_path, &entry); |
| 149 profile_info.ProfileIsSupervisedAtIndex(profile_index); | 151 return has_entry && entry->IsSupervised(); |
| 150 } | 152 } |
| 151 | 153 |
| 152 bool IsProfileLocked(const base::FilePath& profile_path) override { | 154 bool IsProfileLocked(const base::FilePath& profile_path) override { |
| 153 ProfileInfoCache& profile_info = | 155 ProfileAttributesEntry* entry = nullptr; |
| 154 g_browser_process->profile_manager()->GetProfileInfoCache(); | 156 bool has_entry = g_browser_process->profile_manager()-> |
| 155 size_t profile_index = profile_info.GetIndexOfProfileWithPath(profile_path); | 157 GetProfileAttributesStorage(). |
| 156 return profile_index != std::string::npos && | 158 GetProfileAttributesWithPath(profile_path, &entry); |
| 157 profile_info.ProfileIsSigninRequiredAtIndex(profile_index); | 159 return has_entry && entry->IsSigninRequired(); |
| 158 } | 160 } |
| 159 | 161 |
| 160 private: | 162 private: |
| 161 ProfileManager* profile_manager_; | 163 ProfileManager* profile_manager_; |
| 162 base::WeakPtrFactory<ProfileStoreImpl> weak_factory_; | 164 base::WeakPtrFactory<ProfileStoreImpl> weak_factory_; |
| 163 }; | 165 }; |
| 164 | 166 |
| 165 void RecordAppListDiscoverability(PrefService* local_state, | 167 void RecordAppListDiscoverability(PrefService* local_state, |
| 166 bool is_startup_check) { | 168 bool is_startup_check) { |
| 167 // Since this task may be delayed, ensure it does not interfere with shutdown | 169 // Since this task may be delayed, ensure it does not interfere with shutdown |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 void AppListServiceImpl::OnProfileWillBeRemoved( | 337 void AppListServiceImpl::OnProfileWillBeRemoved( |
| 336 const base::FilePath& profile_path) { | 338 const base::FilePath& profile_path) { |
| 337 // We need to watch for profile removal to keep kAppListProfile updated, for | 339 // We need to watch for profile removal to keep kAppListProfile updated, for |
| 338 // the case that the deleted profile is being used by the app list. | 340 // the case that the deleted profile is being used by the app list. |
| 339 std::string app_list_last_profile = local_state_->GetString( | 341 std::string app_list_last_profile = local_state_->GetString( |
| 340 prefs::kAppListProfile); | 342 prefs::kAppListProfile); |
| 341 if (profile_path.BaseName().MaybeAsASCII() != app_list_last_profile) | 343 if (profile_path.BaseName().MaybeAsASCII() != app_list_last_profile) |
| 342 return; | 344 return; |
| 343 | 345 |
| 344 // Switch the app list over to a valid profile. | 346 // Switch the app list over to a valid profile. |
| 345 // Before ProfileInfoCache::DeleteProfileFromCache() calls this function, | 347 // Before ProfileAttributesStorage::RemoveProfile() calls this function, |
| 346 // ProfileManager::ScheduleProfileForDeletion() will have checked to see if | 348 // ProfileManager::ScheduleProfileForDeletion() will have checked to see if |
| 347 // the deleted profile was also "last used", and updated that setting with | 349 // the deleted profile was also "last used", and updated that setting with |
| 348 // something valid. | 350 // something valid. |
| 349 local_state_->SetString(prefs::kAppListProfile, | 351 local_state_->SetString(prefs::kAppListProfile, |
| 350 local_state_->GetString(prefs::kProfileLastUsed)); | 352 local_state_->GetString(prefs::kProfileLastUsed)); |
| 351 | 353 |
| 352 // If the app list was never shown, there won't be a |view_delegate_| yet. | 354 // If the app list was never shown, there won't be a |view_delegate_| yet. |
| 353 if (!view_delegate_) | 355 if (!view_delegate_) |
| 354 return; | 356 return; |
| 355 | 357 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 | 450 |
| 449 if (!base::ThreadTaskRunnerHandle::IsSet()) | 451 if (!base::ThreadTaskRunnerHandle::IsSet()) |
| 450 return; // In a unit test. | 452 return; // In a unit test. |
| 451 | 453 |
| 452 // Send app list usage stats after a delay. | 454 // Send app list usage stats after a delay. |
| 453 const int kSendUsageStatsDelay = 5; | 455 const int kSendUsageStatsDelay = 5; |
| 454 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 456 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 455 FROM_HERE, base::Bind(&AppListServiceImpl::SendAppListStats), | 457 FROM_HERE, base::Bind(&AppListServiceImpl::SendAppListStats), |
| 456 base::TimeDelta::FromSeconds(kSendUsageStatsDelay)); | 458 base::TimeDelta::FromSeconds(kSendUsageStatsDelay)); |
| 457 } | 459 } |
| OLD | NEW |