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/lazy_instance.h" |
7 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
8 #include "chrome/browser/extensions/api/autotest_private/autotest_private_api_fa
ctory.h" | |
9 #include "chrome/browser/extensions/extension_action_manager.h" | 9 #include "chrome/browser/extensions/extension_action_manager.h" |
10 #include "chrome/browser/extensions/extension_function_registry.h" | 10 #include "chrome/browser/extensions/extension_function_registry.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/extensions/extension_util.h" | 12 #include "chrome/browser/extensions/extension_util.h" |
13 #include "chrome/browser/lifetime/application_lifetime.h" | 13 #include "chrome/browser/lifetime/application_lifetime.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/extensions/api/autotest_private.h" | 15 #include "chrome/common/extensions/api/autotest_private.h" |
16 #include "chrome/common/extensions/manifest_url_handler.h" | 16 #include "chrome/common/extensions/manifest_url_handler.h" |
17 #include "extensions/browser/extension_registry.h" | 17 #include "extensions/browser/extension_registry.h" |
18 #include "extensions/browser/extension_system.h" | 18 #include "extensions/browser/extension_system.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 base::ListValue* permissions = new base::ListValue; | 53 base::ListValue* permissions = new base::ListValue; |
54 std::set<std::string> perm_list = | 54 std::set<std::string> perm_list = |
55 ext->GetActivePermissions()->GetAPIsAsStrings(); | 55 ext->GetActivePermissions()->GetAPIsAsStrings(); |
56 for (std::set<std::string>::const_iterator perm = perm_list.begin(); | 56 for (std::set<std::string>::const_iterator perm = perm_list.begin(); |
57 perm != perm_list.end(); ++perm) { | 57 perm != perm_list.end(); ++perm) { |
58 permissions->Append(new base::StringValue(perm->c_str())); | 58 permissions->Append(new base::StringValue(perm->c_str())); |
59 } | 59 } |
60 return permissions; | 60 return permissions; |
61 } | 61 } |
62 | 62 |
| 63 bool IsTestMode(Profile* profile) { |
| 64 return AutotestPrivateAPI::GetFactoryInstance() |
| 65 ->GetForProfile(profile) |
| 66 ->test_mode(); |
| 67 } |
| 68 |
63 } // namespace | 69 } // namespace |
64 | 70 |
65 bool AutotestPrivateLogoutFunction::RunImpl() { | 71 bool AutotestPrivateLogoutFunction::RunImpl() { |
66 DVLOG(1) << "AutotestPrivateLogoutFunction"; | 72 DVLOG(1) << "AutotestPrivateLogoutFunction"; |
67 if (!AutotestPrivateAPIFactory::GetForProfile(GetProfile())->test_mode()) | 73 if (!IsTestMode(GetProfile())) |
68 chrome::AttemptUserExit(); | 74 chrome::AttemptUserExit(); |
69 return true; | 75 return true; |
70 } | 76 } |
71 | 77 |
72 bool AutotestPrivateRestartFunction::RunImpl() { | 78 bool AutotestPrivateRestartFunction::RunImpl() { |
73 DVLOG(1) << "AutotestPrivateRestartFunction"; | 79 DVLOG(1) << "AutotestPrivateRestartFunction"; |
74 if (!AutotestPrivateAPIFactory::GetForProfile(GetProfile())->test_mode()) | 80 if (!IsTestMode(GetProfile())) |
75 chrome::AttemptRestart(); | 81 chrome::AttemptRestart(); |
76 return true; | 82 return true; |
77 } | 83 } |
78 | 84 |
79 bool AutotestPrivateShutdownFunction::RunImpl() { | 85 bool AutotestPrivateShutdownFunction::RunImpl() { |
80 scoped_ptr<api::autotest_private::Shutdown::Params> params( | 86 scoped_ptr<api::autotest_private::Shutdown::Params> params( |
81 api::autotest_private::Shutdown::Params::Create(*args_)); | 87 api::autotest_private::Shutdown::Params::Create(*args_)); |
82 EXTENSION_FUNCTION_VALIDATE(params.get()); | 88 EXTENSION_FUNCTION_VALIDATE(params.get()); |
83 | 89 |
84 DVLOG(1) << "AutotestPrivateShutdownFunction " << params->force; | 90 DVLOG(1) << "AutotestPrivateShutdownFunction " << params->force; |
85 | 91 |
86 if (!AutotestPrivateAPIFactory::GetForProfile(GetProfile())->test_mode()) | 92 if (!IsTestMode(GetProfile())) |
87 chrome::AttemptExit(); | 93 chrome::AttemptExit(); |
88 return true; | 94 return true; |
89 } | 95 } |
90 | 96 |
91 bool AutotestPrivateLoginStatusFunction::RunImpl() { | 97 bool AutotestPrivateLoginStatusFunction::RunImpl() { |
92 DVLOG(1) << "AutotestPrivateLoginStatusFunction"; | 98 DVLOG(1) << "AutotestPrivateLoginStatusFunction"; |
93 | 99 |
94 base::DictionaryValue* result(new base::DictionaryValue); | 100 base::DictionaryValue* result(new base::DictionaryValue); |
95 #if defined(OS_CHROMEOS) | 101 #if defined(OS_CHROMEOS) |
96 const chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | 102 const chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 SetResult(return_value); | 209 SetResult(return_value); |
204 return true; | 210 return true; |
205 } | 211 } |
206 | 212 |
207 static int AccessArray(const volatile int arr[], const volatile int *index) { | 213 static int AccessArray(const volatile int arr[], const volatile int *index) { |
208 return arr[*index]; | 214 return arr[*index]; |
209 } | 215 } |
210 | 216 |
211 bool AutotestPrivateSimulateAsanMemoryBugFunction::RunImpl() { | 217 bool AutotestPrivateSimulateAsanMemoryBugFunction::RunImpl() { |
212 DVLOG(1) << "AutotestPrivateSimulateAsanMemoryBugFunction"; | 218 DVLOG(1) << "AutotestPrivateSimulateAsanMemoryBugFunction"; |
213 if (!AutotestPrivateAPIFactory::GetForProfile(GetProfile())->test_mode()) { | 219 if (!IsTestMode(GetProfile())) { |
214 // This array is volatile not to let compiler optimize us out. | 220 // This array is volatile not to let compiler optimize us out. |
215 volatile int testarray[3] = {0, 0, 0}; | 221 volatile int testarray[3] = {0, 0, 0}; |
216 | 222 |
217 // Cause Address Sanitizer to abort this process. | 223 // Cause Address Sanitizer to abort this process. |
218 volatile int index = 5; | 224 volatile int index = 5; |
219 AccessArray(testarray, &index); | 225 AccessArray(testarray, &index); |
220 } | 226 } |
221 return true; | 227 return true; |
222 } | 228 } |
223 | 229 |
| 230 static base::LazyInstance<ProfileKeyedAPIFactory<AutotestPrivateAPI> > |
| 231 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 232 |
| 233 // static |
| 234 ProfileKeyedAPIFactory<AutotestPrivateAPI>* |
| 235 AutotestPrivateAPI::GetFactoryInstance() { |
| 236 return g_factory.Pointer(); |
| 237 } |
| 238 |
| 239 template <> |
| 240 BrowserContextKeyedService* |
| 241 ProfileKeyedAPIFactory<AutotestPrivateAPI>::BuildServiceInstanceFor( |
| 242 content::BrowserContext* context) const { |
| 243 return new AutotestPrivateAPI(); |
| 244 } |
224 | 245 |
225 AutotestPrivateAPI::AutotestPrivateAPI() : test_mode_(false) { | 246 AutotestPrivateAPI::AutotestPrivateAPI() : test_mode_(false) { |
226 } | 247 } |
227 | 248 |
228 AutotestPrivateAPI::~AutotestPrivateAPI() { | 249 AutotestPrivateAPI::~AutotestPrivateAPI() { |
229 } | 250 } |
230 | 251 |
231 } // namespace extensions | 252 } // namespace extensions |
OLD | NEW |