OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/api/autotest_private/autotest_private_api.h" | 5 #include "chrome/browser/extensions/api/autotest_private/autotest_private_api.h" |
6 | 6 |
| 7 #include "base/strings/string_number_conversions.h" |
7 #include "chrome/browser/extensions/api/autotest_private/autotest_private_api_fa
ctory.h" | 8 #include "chrome/browser/extensions/api/autotest_private/autotest_private_api_fa
ctory.h" |
8 #include "chrome/browser/extensions/extension_function_registry.h" | 9 #include "chrome/browser/extensions/extension_function_registry.h" |
9 #include "chrome/browser/lifetime/application_lifetime.h" | 10 #include "chrome/browser/lifetime/application_lifetime.h" |
10 #include "chrome/common/extensions/api/autotest_private.h" | 11 #include "chrome/common/extensions/api/autotest_private.h" |
11 | 12 |
12 #if defined(OS_CHROMEOS) | 13 #if defined(OS_CHROMEOS) |
13 #include "ash/shell.h" | 14 #include "chrome/browser/chromeos/login/screen_locker.h" |
14 #include "ash/system/tray/system_tray_delegate.h" | 15 #include "chrome/browser/chromeos/login/user_manager.h" |
15 #endif | 16 #endif |
16 | 17 |
17 namespace extensions { | 18 namespace extensions { |
18 namespace { | |
19 | |
20 std::string GetUserLoginStatus() { | |
21 #if defined(OS_CHROMEOS) | |
22 const ash::user::LoginStatus status = | |
23 ash::Shell::GetInstance()->system_tray_delegate() ? | |
24 ash::Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus() : | |
25 ash::user::LOGGED_IN_NONE; | |
26 | |
27 switch (status) { | |
28 case ash::user::LOGGED_IN_LOCKED: | |
29 return std::string("locked"); | |
30 case ash::user::LOGGED_IN_USER: | |
31 return std::string("user"); | |
32 case ash::user::LOGGED_IN_OWNER: | |
33 return std::string("owner"); | |
34 case ash::user::LOGGED_IN_GUEST: | |
35 return std::string("guest"); | |
36 case ash::user::LOGGED_IN_RETAIL_MODE: | |
37 return std::string("retail"); | |
38 case ash::user::LOGGED_IN_PUBLIC: | |
39 return std::string("public"); | |
40 case ash::user::LOGGED_IN_LOCALLY_MANAGED: | |
41 return std::string("local"); | |
42 case ash::user::LOGGED_IN_KIOSK_APP: | |
43 return std::string("kiosk"); | |
44 case ash::user::LOGGED_IN_NONE: | |
45 return std::string("none"); | |
46 // Intentionally leaves out default so that compiler catches missing | |
47 // branches when new login status is added. | |
48 } | |
49 | |
50 NOTREACHED(); | |
51 #endif | |
52 | |
53 return std::string("none"); | |
54 } | |
55 | |
56 } // namespace | |
57 | 19 |
58 bool AutotestPrivateLogoutFunction::RunImpl() { | 20 bool AutotestPrivateLogoutFunction::RunImpl() { |
59 DVLOG(1) << "AutotestPrivateLogoutFunction"; | 21 DVLOG(1) << "AutotestPrivateLogoutFunction"; |
60 if (!AutotestPrivateAPIFactory::GetForProfile(profile())->test_mode()) | 22 if (!AutotestPrivateAPIFactory::GetForProfile(profile())->test_mode()) |
61 chrome::AttemptUserExit(); | 23 chrome::AttemptUserExit(); |
62 return true; | 24 return true; |
63 } | 25 } |
64 | 26 |
65 bool AutotestPrivateRestartFunction::RunImpl() { | 27 bool AutotestPrivateRestartFunction::RunImpl() { |
66 DVLOG(1) << "AutotestPrivateRestartFunction"; | 28 DVLOG(1) << "AutotestPrivateRestartFunction"; |
(...skipping 16 matching lines...) Expand all Loading... |
83 return true; | 45 return true; |
84 } | 46 } |
85 #endif | 47 #endif |
86 if (!AutotestPrivateAPIFactory::GetForProfile(profile())->test_mode()) | 48 if (!AutotestPrivateAPIFactory::GetForProfile(profile())->test_mode()) |
87 chrome::AttemptExit(); | 49 chrome::AttemptExit(); |
88 return true; | 50 return true; |
89 } | 51 } |
90 | 52 |
91 bool AutotestPrivateLoginStatusFunction::RunImpl() { | 53 bool AutotestPrivateLoginStatusFunction::RunImpl() { |
92 DVLOG(1) << "AutotestPrivateLoginStatusFunction"; | 54 DVLOG(1) << "AutotestPrivateLoginStatusFunction"; |
93 SetResult(base::Value::CreateStringValue(GetUserLoginStatus())); | 55 |
| 56 DictionaryValue* result(new DictionaryValue); |
| 57 #if defined(OS_CHROMEOS) |
| 58 const chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
| 59 const bool is_screen_locked = |
| 60 !!chromeos::ScreenLocker::default_screen_locker(); |
| 61 |
| 62 if (user_manager) { |
| 63 result->SetBoolean("isLoggedIn", user_manager->IsUserLoggedIn()); |
| 64 result->SetBoolean("isOwner", user_manager->IsCurrentUserOwner()); |
| 65 result->SetBoolean("isScreenLocked", is_screen_locked); |
| 66 if (user_manager->IsUserLoggedIn()) { |
| 67 result->SetBoolean("isRegularUser", |
| 68 user_manager->IsLoggedInAsRegularUser()); |
| 69 result->SetBoolean("isGuest", user_manager->IsLoggedInAsGuest()); |
| 70 result->SetBoolean("isKiosk", user_manager->IsLoggedInAsKioskApp()); |
| 71 |
| 72 const chromeos::User* user = user_manager->GetLoggedInUser(); |
| 73 result->SetString("email", user->email()); |
| 74 result->SetString("displayEmail", user->display_email()); |
| 75 |
| 76 std::string user_image; |
| 77 switch (user->image_index()) { |
| 78 case chromeos::User::kExternalImageIndex: |
| 79 user_image = "file"; |
| 80 break; |
| 81 |
| 82 case chromeos::User::kProfileImageIndex: |
| 83 user_image = "profile"; |
| 84 break; |
| 85 |
| 86 default: |
| 87 user_image = base::IntToString(user->image_index()); |
| 88 break; |
| 89 } |
| 90 result->SetString("userImage", user_image); |
| 91 } |
| 92 } |
| 93 #endif |
| 94 |
| 95 SetResult(result); |
94 return true; | 96 return true; |
95 } | 97 } |
96 | 98 |
97 AutotestPrivateAPI::AutotestPrivateAPI() : test_mode_(false) { | 99 AutotestPrivateAPI::AutotestPrivateAPI() : test_mode_(false) { |
98 } | 100 } |
99 | 101 |
100 AutotestPrivateAPI::~AutotestPrivateAPI() { | 102 AutotestPrivateAPI::~AutotestPrivateAPI() { |
101 } | 103 } |
102 | 104 |
103 } // namespace extensions | 105 } // namespace extensions |
OLD | NEW |