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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/browser_shutdown.h" | 16 #include "chrome/browser/browser_shutdown.h" |
17 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
18 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" | 18 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" |
19 #include "chrome/browser/ui/app_list/profile_loader.h" | 19 #include "chrome/browser/ui/app_list/profile_loader.h" |
20 #include "chrome/browser/ui/app_list/profile_store.h" | 20 #include "chrome/browser/ui/app_list/profile_store.h" |
21 #include "chrome/browser/ui/user_manager.h" | |
21 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
24 #include "ui/app_list/app_list_model.h" | 25 #include "ui/app_list/app_list_model.h" |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 const int kDiscoverabilityTimeoutMinutes = 60; | 29 const int kDiscoverabilityTimeoutMinutes = 60; |
29 | 30 |
30 void SendAppListAppLaunch(int count) { | 31 void SendAppListAppLaunch(int count) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 : profile_manager_(profile_manager), | 87 : profile_manager_(profile_manager), |
87 weak_factory_(this) { | 88 weak_factory_(this) { |
88 } | 89 } |
89 | 90 |
90 void AddProfileObserver(ProfileInfoCacheObserver* observer) override { | 91 void AddProfileObserver(ProfileInfoCacheObserver* observer) override { |
91 profile_manager_->GetProfileInfoCache().AddObserver(observer); | 92 profile_manager_->GetProfileInfoCache().AddObserver(observer); |
92 } | 93 } |
93 | 94 |
94 void LoadProfileAsync(const base::FilePath& path, | 95 void LoadProfileAsync(const base::FilePath& path, |
95 base::Callback<void(Profile*)> callback) override { | 96 base::Callback<void(Profile*)> callback) override { |
97 if (IsProfileLocked(path)) { | |
98 UserManager::Show(base::FilePath(), | |
tapted
2015/01/19 22:25:50
WDYT about just calling DismissAppList() before th
Mike Lerman
2015/01/21 21:54:13
We discussed offline - shall leave it as is. If th
| |
99 profiles::USER_MANAGER_NO_TUTORIAL, | |
100 profiles::USER_MANAGER_SELECT_PROFILE_APP_LAUNCHER); | |
101 return; | |
102 } | |
103 | |
96 profile_manager_->CreateProfileAsync( | 104 profile_manager_->CreateProfileAsync( |
97 path, | 105 path, |
98 base::Bind(&ProfileStoreImpl::OnProfileCreated, | 106 base::Bind(&ProfileStoreImpl::OnProfileCreated, |
99 weak_factory_.GetWeakPtr(), | 107 weak_factory_.GetWeakPtr(), |
100 callback), | 108 callback), |
101 base::string16(), | 109 base::string16(), |
102 base::string16(), | 110 base::string16(), |
103 std::string()); | 111 std::string()); |
104 } | 112 } |
105 | 113 |
(...skipping 10 matching lines...) Expand all Loading... | |
116 case Profile::CREATE_STATUS_REMOTE_FAIL: | 124 case Profile::CREATE_STATUS_REMOTE_FAIL: |
117 case Profile::CREATE_STATUS_CANCELED: | 125 case Profile::CREATE_STATUS_CANCELED: |
118 break; | 126 break; |
119 case Profile::MAX_CREATE_STATUS: | 127 case Profile::MAX_CREATE_STATUS: |
120 NOTREACHED(); | 128 NOTREACHED(); |
121 break; | 129 break; |
122 } | 130 } |
123 } | 131 } |
124 | 132 |
125 Profile* GetProfileByPath(const base::FilePath& path) override { | 133 Profile* GetProfileByPath(const base::FilePath& path) override { |
134 if (IsProfileLocked(path)) | |
135 return nullptr; | |
tapted
2015/01/19 22:25:51
I'm a little wary of this - I don't think it's the
Mike Lerman
2015/01/21 21:54:13
Done.
| |
126 return profile_manager_->GetProfileByPath(path); | 136 return profile_manager_->GetProfileByPath(path); |
127 } | 137 } |
128 | 138 |
129 base::FilePath GetUserDataDir() override { | 139 base::FilePath GetUserDataDir() override { |
130 return profile_manager_->user_data_dir(); | 140 return profile_manager_->user_data_dir(); |
131 } | 141 } |
132 | 142 |
133 bool IsProfileSupervised(const base::FilePath& profile_path) override { | 143 bool IsProfileSupervised(const base::FilePath& profile_path) override { |
134 ProfileInfoCache& profile_info = | 144 ProfileInfoCache& profile_info = |
135 g_browser_process->profile_manager()->GetProfileInfoCache(); | 145 g_browser_process->profile_manager()->GetProfileInfoCache(); |
136 size_t profile_index = profile_info.GetIndexOfProfileWithPath(profile_path); | 146 size_t profile_index = profile_info.GetIndexOfProfileWithPath(profile_path); |
137 return profile_index != std::string::npos && | 147 return profile_index != std::string::npos && |
138 profile_info.ProfileIsSupervisedAtIndex(profile_index); | 148 profile_info.ProfileIsSupervisedAtIndex(profile_index); |
139 } | 149 } |
140 | 150 |
151 bool IsProfileLocked(const base::FilePath& profile_path) { | |
152 ProfileInfoCache& profile_info = | |
153 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
154 size_t profile_index = profile_info.GetIndexOfProfileWithPath(profile_path); | |
155 return profile_index != std::string::npos && | |
156 profile_info.ProfileIsSigninRequiredAtIndex(profile_index); | |
157 } | |
158 | |
141 private: | 159 private: |
142 ProfileManager* profile_manager_; | 160 ProfileManager* profile_manager_; |
143 base::WeakPtrFactory<ProfileStoreImpl> weak_factory_; | 161 base::WeakPtrFactory<ProfileStoreImpl> weak_factory_; |
144 }; | 162 }; |
145 | 163 |
146 void RecordAppListDiscoverability(PrefService* local_state, | 164 void RecordAppListDiscoverability(PrefService* local_state, |
147 bool is_startup_check) { | 165 bool is_startup_check) { |
148 // Since this task may be delayed, ensure it does not interfere with shutdown | 166 // Since this task may be delayed, ensure it does not interfere with shutdown |
149 // when they unluckily coincide. | 167 // when they unluckily coincide. |
150 if (browser_shutdown::IsTryingToQuit()) | 168 if (browser_shutdown::IsTryingToQuit()) |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 if (!base::MessageLoop::current()) | 425 if (!base::MessageLoop::current()) |
408 return; // In a unit test. | 426 return; // In a unit test. |
409 | 427 |
410 // Send app list usage stats after a delay. | 428 // Send app list usage stats after a delay. |
411 const int kSendUsageStatsDelay = 5; | 429 const int kSendUsageStatsDelay = 5; |
412 base::MessageLoop::current()->PostDelayedTask( | 430 base::MessageLoop::current()->PostDelayedTask( |
413 FROM_HERE, | 431 FROM_HERE, |
414 base::Bind(&AppListServiceImpl::SendAppListStats), | 432 base::Bind(&AppListServiceImpl::SendAppListStats), |
415 base::TimeDelta::FromSeconds(kSendUsageStatsDelay)); | 433 base::TimeDelta::FromSeconds(kSendUsageStatsDelay)); |
416 } | 434 } |
OLD | NEW |