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

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 forward declaration. 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 {
28
29 std::string GetAppUserNameFromAppId(const std::string& app_id) {
30 return app_id + "@" + UserManager::kKioskAppUserDomain;
31 }
32
33 } // namespace
34
35 // static 29 // static
36 KioskAppLauncher* KioskAppLauncher::running_instance_ = NULL; 30 KioskAppLauncher* KioskAppLauncher::running_instance_ = NULL;
37 31
38 //////////////////////////////////////////////////////////////////////////////// 32 ////////////////////////////////////////////////////////////////////////////////
39 // KioskAppLauncher::CryptohomedChecker ensures cryptohome daemon is up 33 // KioskAppLauncher::CryptohomedChecker ensures cryptohome daemon is up
40 // and running by issuing an IsMounted call. If the call does not go through 34 // 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 35 // 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 36 // some time out and at the maximum five times before it gives up. Upon
43 // success, it resumes the launch by calling KioskAppLauncher::StartMount. 37 // success, it resumes the launch by calling KioskAppLauncher::StartMount.
44 38
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 int retry_count_; 92 int retry_count_;
99 93
100 DISALLOW_COPY_AND_ASSIGN(CryptohomedChecker); 94 DISALLOW_COPY_AND_ASSIGN(CryptohomedChecker);
101 }; 95 };
102 96
103 //////////////////////////////////////////////////////////////////////////////// 97 ////////////////////////////////////////////////////////////////////////////////
104 // KioskAppLauncher::ProfileLoader creates or loads the app profile. 98 // KioskAppLauncher::ProfileLoader creates or loads the app profile.
105 99
106 class KioskAppLauncher::ProfileLoader : public LoginUtils::Delegate { 100 class KioskAppLauncher::ProfileLoader : public LoginUtils::Delegate {
107 public: 101 public:
108 explicit ProfileLoader(KioskAppLauncher* launcher) 102 ProfileLoader(KioskAppManager* kiosk_app_manager,
109 : launcher_(launcher) { 103 KioskAppLauncher* kiosk_app_launcher)
104 : kiosk_app_launcher_(kiosk_app_launcher) {
105 KioskAppManager::App app;
106 if (!kiosk_app_manager->GetApp(kiosk_app_launcher->app_id_, &app))
107 NOTREACHED() << "Logging into nonexistent kiosk-app account.";
108 user_id_ = app.user_id;
110 } 109 }
111 110
112 virtual ~ProfileLoader() { 111 virtual ~ProfileLoader() {
113 LoginUtils::Get()->DelegateDeleted(this); 112 LoginUtils::Get()->DelegateDeleted(this);
114 } 113 }
115 114
116 void Start() { 115 void Start() {
117 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( 116 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername(
118 GetAppUserNameFromAppId(launcher_->app_id_), 117 user_id_,
119 base::Bind(&ProfileLoader::OnUsernameHashRetrieved, 118 base::Bind(&ProfileLoader::OnUsernameHashRetrieved,
120 base::Unretained(this))); 119 base::Unretained(this)));
121 } 120 }
122 121
123 private: 122 private:
124 void OnUsernameHashRetrieved(bool success, 123 void OnUsernameHashRetrieved(bool success,
125 const std::string& username_hash) { 124 const std::string& username_hash) {
126 if (!success) { 125 if (!success) {
127 LOG(ERROR) << "Unable to retrieve username hash for user '" << 126 LOG(ERROR) << "Unable to retrieve username hash for user '" << user_id_
128 GetAppUserNameFromAppId(launcher_->app_id_) << "'"; 127 << "'.";
129 launcher_->ReportLaunchResult( 128 kiosk_app_launcher_->ReportLaunchResult(
130 KioskAppLaunchError::UNABLE_TO_RETRIEVE_HASH); 129 KioskAppLaunchError::UNABLE_TO_RETRIEVE_HASH);
131 return; 130 return;
132 } 131 }
133 LoginUtils::Get()->PrepareProfile( 132 LoginUtils::Get()->PrepareProfile(
134 UserContext(GetAppUserNameFromAppId(launcher_->app_id_), 133 UserContext(user_id_,
135 std::string(), // password 134 std::string(), // password
136 std::string(), // auth_code 135 std::string(), // auth_code
137 username_hash), 136 username_hash),
138 std::string(), // display email 137 std::string(), // display email
139 false, // using_oauth 138 false, // using_oauth
140 false, // has_cookies 139 false, // has_cookies
141 this); 140 this);
142 } 141 }
143 142
144 // LoginUtils::Delegate overrides: 143 // LoginUtils::Delegate overrides:
145 virtual void OnProfilePrepared(Profile* profile) OVERRIDE { 144 virtual void OnProfilePrepared(Profile* profile) OVERRIDE {
146 launcher_->OnProfilePrepared(profile); 145 kiosk_app_launcher_->OnProfilePrepared(profile);
147 } 146 }
148 147
149 KioskAppLauncher* launcher_; 148 KioskAppLauncher* kiosk_app_launcher_;
149 std::string user_id_;
150
150 DISALLOW_COPY_AND_ASSIGN(ProfileLoader); 151 DISALLOW_COPY_AND_ASSIGN(ProfileLoader);
151 }; 152 };
152 153
153 //////////////////////////////////////////////////////////////////////////////// 154 ////////////////////////////////////////////////////////////////////////////////
154 // KioskAppLauncher 155 // KioskAppLauncher
155 156
156 KioskAppLauncher::KioskAppLauncher(const std::string& app_id) 157 KioskAppLauncher::KioskAppLauncher(KioskAppManager* kiosk_app_manager,
157 : app_id_(app_id), 158 const std::string& app_id)
159 : kiosk_app_manager_(kiosk_app_manager),
160 app_id_(app_id),
158 remove_attempted_(false) { 161 remove_attempted_(false) {
159 } 162 }
160 163
161 KioskAppLauncher::~KioskAppLauncher() {} 164 KioskAppLauncher::~KioskAppLauncher() {}
162 165
163 void KioskAppLauncher::Start() { 166 void KioskAppLauncher::Start() {
164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
165 168
166 if (running_instance_) { 169 if (running_instance_) {
167 LOG(WARNING) << "Unable to launch " << app_id_ << "with a pending launch."; 170 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_, 206 app_id_,
204 token, 207 token,
205 cryptohome::CREATE_IF_MISSING, 208 cryptohome::CREATE_IF_MISSING,
206 base::Bind(&KioskAppLauncher::MountCallback, 209 base::Bind(&KioskAppLauncher::MountCallback,
207 base::Unretained(this))); 210 base::Unretained(this)));
208 } 211 }
209 212
210 void KioskAppLauncher::MountCallback(bool mount_success, 213 void KioskAppLauncher::MountCallback(bool mount_success,
211 cryptohome::MountError mount_error) { 214 cryptohome::MountError mount_error) {
212 if (mount_success) { 215 if (mount_success) {
213 profile_loader_.reset(new ProfileLoader(this)); 216 profile_loader_.reset(new ProfileLoader(kiosk_app_manager_, this));
214 profile_loader_->Start(); 217 profile_loader_->Start();
215 return; 218 return;
216 } 219 }
217 220
218 if (!remove_attempted_) { 221 if (!remove_attempted_) {
219 LOG(ERROR) << "Attempt to remove app cryptohome because of mount failure" 222 LOG(ERROR) << "Attempt to remove app cryptohome because of mount failure"
220 << ", mount error=" << mount_error; 223 << ", mount error=" << mount_error;
221 224
222 remove_attempted_ = true; 225 remove_attempted_ = true;
223 AttemptRemove(); 226 AttemptRemove();
(...skipping 27 matching lines...) Expand all
251 (new chromeos::StartupAppLauncher(profile, app_id_))->Start(); 254 (new chromeos::StartupAppLauncher(profile, app_id_))->Start();
252 255
253 if (LoginDisplayHostImpl::default_host()) 256 if (LoginDisplayHostImpl::default_host())
254 LoginDisplayHostImpl::default_host()->OnSessionStart(); 257 LoginDisplayHostImpl::default_host()->OnSessionStart();
255 UserManager::Get()->SessionStarted(); 258 UserManager::Get()->SessionStarted();
256 259
257 ReportLaunchResult(KioskAppLaunchError::NONE); 260 ReportLaunchResult(KioskAppLaunchError::NONE);
258 } 261 }
259 262
260 } // namespace chromeos 263 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/app_mode/kiosk_app_launcher.h ('k') | chrome/browser/chromeos/app_mode/kiosk_app_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698