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

Side by Side Diff: chrome/browser/extensions/api/autotest_private/autotest_private_api.cc

Issue 13520005: autotestPrivate.loginStatus returns a dictionary instead of a string. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 8 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 (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 "chrome/browser/extensions/api/autotest_private/autotest_private_api_fa ctory.h" 7 #include "chrome/browser/extensions/api/autotest_private/autotest_private_api_fa ctory.h"
8 #include "chrome/browser/extensions/extension_function_registry.h" 8 #include "chrome/browser/extensions/extension_function_registry.h"
9 #include "chrome/browser/lifetime/application_lifetime.h" 9 #include "chrome/browser/lifetime/application_lifetime.h"
10 #include "chrome/common/extensions/api/autotest_private.h" 10 #include "chrome/common/extensions/api/autotest_private.h"
11 11
12 #if defined(OS_CHROMEOS) 12 #if defined(OS_CHROMEOS)
13 #include "ash/shell.h" 13 #include "chrome/browser/chromeos/login/screen_locker.h"
14 #include "ash/system/tray/system_tray_delegate.h" 14 #include "chrome/browser/chromeos/login/user_manager.h"
15 #endif 15 #endif
16 16
17 namespace extensions { 17 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 18
58 bool AutotestPrivateLogoutFunction::RunImpl() { 19 bool AutotestPrivateLogoutFunction::RunImpl() {
59 DVLOG(1) << "AutotestPrivateLogoutFunction"; 20 DVLOG(1) << "AutotestPrivateLogoutFunction";
60 if (!AutotestPrivateAPIFactory::GetForProfile(profile())->test_mode()) 21 if (!AutotestPrivateAPIFactory::GetForProfile(profile())->test_mode())
61 chrome::AttemptUserExit(); 22 chrome::AttemptUserExit();
62 return true; 23 return true;
63 } 24 }
64 25
65 bool AutotestPrivateRestartFunction::RunImpl() { 26 bool AutotestPrivateRestartFunction::RunImpl() {
66 DVLOG(1) << "AutotestPrivateRestartFunction"; 27 DVLOG(1) << "AutotestPrivateRestartFunction";
(...skipping 16 matching lines...) Expand all
83 return true; 44 return true;
84 } 45 }
85 #endif 46 #endif
86 if (!AutotestPrivateAPIFactory::GetForProfile(profile())->test_mode()) 47 if (!AutotestPrivateAPIFactory::GetForProfile(profile())->test_mode())
87 chrome::AttemptExit(); 48 chrome::AttemptExit();
88 return true; 49 return true;
89 } 50 }
90 51
91 bool AutotestPrivateLoginStatusFunction::RunImpl() { 52 bool AutotestPrivateLoginStatusFunction::RunImpl() {
92 DVLOG(1) << "AutotestPrivateLoginStatusFunction"; 53 DVLOG(1) << "AutotestPrivateLoginStatusFunction";
93 SetResult(base::Value::CreateStringValue(GetUserLoginStatus())); 54
55 DictionaryValue* return_value(new DictionaryValue);
56 #if defined(OS_CHROMEOS)
57 const chromeos::UserManager* user_manager = chromeos::UserManager::Get();
58 const chromeos::ScreenLocker* screen_locker =
59 chromeos::ScreenLocker::default_screen_locker();
60
61 if (user_manager) {
62 return_value->SetBoolean("is_logged_in", user_manager->IsUserLoggedIn());
63 return_value->SetBoolean("is_owner", user_manager->IsCurrentUserOwner());
64 return_value->SetBoolean("is_screen_locked", screen_locker);
65 if (user_manager->IsUserLoggedIn()) {
66 return_value->SetBoolean("is_regular_user",
67 user_manager->IsLoggedInAsRegularUser());
68 return_value->SetBoolean("is_guest", user_manager->IsLoggedInAsGuest());
69 return_value->SetBoolean("is_kiosk",
70 user_manager->IsLoggedInAsKioskApp());
71
72 const chromeos::User* user = user_manager->GetLoggedInUser();
73 return_value->SetString("email", user->email());
74 return_value->SetString("display_email", user->display_email());
75 switch (user->image_index()) {
76 case chromeos::User::kExternalImageIndex:
77 return_value->SetString("user_image", "file");
78 break;
79
80 case chromeos::User::kProfileImageIndex:
81 return_value->SetString("user_image", "profile");
82 break;
83
84 default:
85 return_value->SetInteger("user_image", user->image_index());
86 break;
87 }
88 }
89 }
90 #endif
91
92 SetResult(return_value);
94 return true; 93 return true;
95 } 94 }
96 95
97 AutotestPrivateAPI::AutotestPrivateAPI() : test_mode_(false) { 96 AutotestPrivateAPI::AutotestPrivateAPI() : test_mode_(false) {
98 } 97 }
99 98
100 AutotestPrivateAPI::~AutotestPrivateAPI() { 99 AutotestPrivateAPI::~AutotestPrivateAPI() {
101 } 100 }
102 101
103 } // namespace extensions 102 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698