Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: chrome/browser/chromeos/app_mode/kiosk_app_launcher.cc

Issue 14927015: Translate device-local account IDs to user IDs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix browser_tests. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/chromeos/app_mode/kiosk_app_launcher.h" 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_launcher.h"
6 6
7 #include "base/chromeos/chromeos_version.h" 7 #include "base/chromeos/chromeos_version.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
11 #include "chrome/browser/chromeos/app_mode/startup_app_launcher.h" 12 #include "chrome/browser/chromeos/app_mode/startup_app_launcher.h"
12 #include "chrome/browser/chromeos/login/login_display_host_impl.h" 13 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
13 #include "chrome/browser/chromeos/login/login_utils.h" 14 #include "chrome/browser/chromeos/login/login_utils.h"
14 #include "chrome/browser/chromeos/login/user_manager.h" 15 #include "chrome/browser/chromeos/login/user_manager.h"
16 #include "chrome/browser/chromeos/settings/cros_settings.h"
15 #include "chrome/browser/chromeos/ui/app_launch_view.h" 17 #include "chrome/browser/chromeos/ui/app_launch_view.h"
16 #include "chrome/browser/lifetime/application_lifetime.h" 18 #include "chrome/browser/lifetime/application_lifetime.h"
17 #include "chromeos/cryptohome/async_method_caller.h" 19 #include "chromeos/cryptohome/async_method_caller.h"
18 #include "chromeos/cryptohome/cryptohome_library.h" 20 #include "chromeos/cryptohome/cryptohome_library.h"
19 #include "chromeos/dbus/cryptohome_client.h" 21 #include "chromeos/dbus/cryptohome_client.h"
20 #include "chromeos/dbus/dbus_thread_manager.h" 22 #include "chromeos/dbus/dbus_thread_manager.h"
21 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
22 24
23 using content::BrowserThread; 25 using content::BrowserThread;
24 26
25 namespace chromeos { 27 namespace chromeos {
26 28
27 namespace { 29 namespace {
28 30
29 std::string GetAppUserNameFromAppId(const std::string& app_id) {
30 return app_id + "@" + UserManager::kKioskAppUserDomain;
31 }
32
33 } // namespace 31 } // namespace
Joao da Silva 2013/05/17 18:10:55 nit: The empty namespace { } can be removed
bartfab (slow) 2013/05/21 13:27:07 Done.
34 32
35 // static 33 // static
36 KioskAppLauncher* KioskAppLauncher::running_instance_ = NULL; 34 KioskAppLauncher* KioskAppLauncher::running_instance_ = NULL;
37 35
38 //////////////////////////////////////////////////////////////////////////////// 36 ////////////////////////////////////////////////////////////////////////////////
39 // KioskAppLauncher::CryptohomedChecker ensures cryptohome daemon is up 37 // KioskAppLauncher::CryptohomedChecker ensures cryptohome daemon is up
40 // and running by issuing an IsMounted call. If the call does not go through 38 // and running by issuing an IsMounted call. If the call does not go through
41 // and chromeos::DBUS_METHOD_CALL_SUCCESS is not returned, it will retry after 39 // and chromeos::DBUS_METHOD_CALL_SUCCESS is not returned, it will retry after
42 // some time out and at the maximum five times before it gives up. Upon 40 // some time out and at the maximum five times before it gives up. Upon
43 // success, it resumes the launch by calling KioskAppLauncher::StartMount. 41 // success, it resumes the launch by calling KioskAppLauncher::StartMount.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 int retry_count_; 96 int retry_count_;
99 97
100 DISALLOW_COPY_AND_ASSIGN(CryptohomedChecker); 98 DISALLOW_COPY_AND_ASSIGN(CryptohomedChecker);
101 }; 99 };
102 100
103 //////////////////////////////////////////////////////////////////////////////// 101 ////////////////////////////////////////////////////////////////////////////////
104 // KioskAppLauncher::ProfileLoader creates or loads the app profile. 102 // KioskAppLauncher::ProfileLoader creates or loads the app profile.
105 103
106 class KioskAppLauncher::ProfileLoader : public LoginUtils::Delegate { 104 class KioskAppLauncher::ProfileLoader : public LoginUtils::Delegate {
107 public: 105 public:
108 explicit ProfileLoader(KioskAppLauncher* launcher) 106 ProfileLoader(KioskAppManager* kiosk_app_manager,
109 : launcher_(launcher) { 107 KioskAppLauncher* kiosk_app_launcher)
108 : kiosk_app_launcher_(kiosk_app_launcher) {
109 KioskAppManager::App app;
110 if (!kiosk_app_manager->GetApp(kiosk_app_launcher->app_id_, &app))
111 NOTREACHED() << "Logging into nonexistent kiosk-app account.";
112 user_id_ = app.user_id;
110 } 113 }
111 114
112 virtual ~ProfileLoader() { 115 virtual ~ProfileLoader() {
113 LoginUtils::Get()->DelegateDeleted(this); 116 LoginUtils::Get()->DelegateDeleted(this);
114 } 117 }
115 118
116 void Start() { 119 void Start() {
117 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( 120 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername(
118 GetAppUserNameFromAppId(launcher_->app_id_), 121 user_id_,
119 base::Bind(&ProfileLoader::OnUsernameHashRetrieved, 122 base::Bind(&ProfileLoader::OnUsernameHashRetrieved,
120 base::Unretained(this))); 123 base::Unretained(this)));
121 } 124 }
122 125
123 private: 126 private:
124 void OnUsernameHashRetrieved(bool success, 127 void OnUsernameHashRetrieved(bool success,
125 const std::string& username_hash) { 128 const std::string& username_hash) {
126 if (!success) { 129 if (!success) {
127 LOG(ERROR) << "Unable to retrieve username hash for user '" << 130 LOG(ERROR) << "Unable to retrieve username hash for user '" << user_id_
128 GetAppUserNameFromAppId(launcher_->app_id_) << "'"; 131 << "'.";
129 launcher_->ReportLaunchResult( 132 kiosk_app_launcher_->ReportLaunchResult(
130 KioskAppLaunchError::UNABLE_TO_RETRIEVE_HASH); 133 KioskAppLaunchError::UNABLE_TO_RETRIEVE_HASH);
131 return; 134 return;
132 } 135 }
133 LoginUtils::Get()->PrepareProfile( 136 LoginUtils::Get()->PrepareProfile(
134 UserContext(GetAppUserNameFromAppId(launcher_->app_id_), 137 UserContext(user_id_,
135 std::string(), // password 138 std::string(), // password
136 std::string(), // auth_code 139 std::string(), // auth_code
137 username_hash), 140 username_hash),
138 std::string(), // display email 141 std::string(), // display email
139 false, // using_oauth 142 false, // using_oauth
140 false, // has_cookies 143 false, // has_cookies
141 this); 144 this);
142 } 145 }
143 146
144 // LoginUtils::Delegate overrides: 147 // LoginUtils::Delegate overrides:
145 virtual void OnProfilePrepared(Profile* profile) OVERRIDE { 148 virtual void OnProfilePrepared(Profile* profile) OVERRIDE {
146 launcher_->OnProfilePrepared(profile); 149 kiosk_app_launcher_->OnProfilePrepared(profile);
147 } 150 }
148 151
149 KioskAppLauncher* launcher_; 152 KioskAppLauncher* kiosk_app_launcher_;
153 std::string user_id_;
154
150 DISALLOW_COPY_AND_ASSIGN(ProfileLoader); 155 DISALLOW_COPY_AND_ASSIGN(ProfileLoader);
151 }; 156 };
152 157
153 //////////////////////////////////////////////////////////////////////////////// 158 ////////////////////////////////////////////////////////////////////////////////
154 // KioskAppLauncher 159 // KioskAppLauncher
155 160
156 KioskAppLauncher::KioskAppLauncher(const std::string& app_id) 161 KioskAppLauncher::KioskAppLauncher(KioskAppManager* kiosk_app_manager,
157 : app_id_(app_id), 162 const std::string& app_id)
163 : kiosk_app_manager_(kiosk_app_manager),
164 app_id_(app_id),
158 remove_attempted_(false) { 165 remove_attempted_(false) {
159 } 166 }
160 167
161 KioskAppLauncher::~KioskAppLauncher() {} 168 KioskAppLauncher::~KioskAppLauncher() {}
162 169
163 void KioskAppLauncher::Start() { 170 void KioskAppLauncher::Start() {
164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
165 172
166 if (running_instance_) { 173 if (running_instance_) {
167 LOG(WARNING) << "Unable to launch " << app_id_ << "with a pending launch."; 174 LOG(WARNING) << "Unable to launch " << app_id_ << "with a pending launch.";
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 app_id_, 210 app_id_,
204 token, 211 token,
205 cryptohome::CREATE_IF_MISSING, 212 cryptohome::CREATE_IF_MISSING,
206 base::Bind(&KioskAppLauncher::MountCallback, 213 base::Bind(&KioskAppLauncher::MountCallback,
207 base::Unretained(this))); 214 base::Unretained(this)));
208 } 215 }
209 216
210 void KioskAppLauncher::MountCallback(bool mount_success, 217 void KioskAppLauncher::MountCallback(bool mount_success,
211 cryptohome::MountError mount_error) { 218 cryptohome::MountError mount_error) {
212 if (mount_success) { 219 if (mount_success) {
213 profile_loader_.reset(new ProfileLoader(this)); 220 profile_loader_.reset(new ProfileLoader(kiosk_app_manager_, this));
214 profile_loader_->Start(); 221 profile_loader_->Start();
215 return; 222 return;
216 } 223 }
217 224
218 if (!remove_attempted_) { 225 if (!remove_attempted_) {
219 LOG(ERROR) << "Attempt to remove app cryptohome because of mount failure" 226 LOG(ERROR) << "Attempt to remove app cryptohome because of mount failure"
220 << ", mount error=" << mount_error; 227 << ", mount error=" << mount_error;
221 228
222 remove_attempted_ = true; 229 remove_attempted_ = true;
223 AttemptRemove(); 230 AttemptRemove();
(...skipping 27 matching lines...) Expand all
251 (new chromeos::StartupAppLauncher(profile, app_id_))->Start(); 258 (new chromeos::StartupAppLauncher(profile, app_id_))->Start();
252 259
253 if (LoginDisplayHostImpl::default_host()) 260 if (LoginDisplayHostImpl::default_host())
254 LoginDisplayHostImpl::default_host()->OnSessionStart(); 261 LoginDisplayHostImpl::default_host()->OnSessionStart();
255 UserManager::Get()->SessionStarted(); 262 UserManager::Get()->SessionStarted();
256 263
257 ReportLaunchResult(KioskAppLaunchError::NONE); 264 ReportLaunchResult(KioskAppLaunchError::NONE);
258 } 265 }
259 266
260 } // namespace chromeos 267 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698