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

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

Issue 2801173002: arc: Provide API to control Play Store state from autotests (Closed)
Patch Set: fix browser test Created 3 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
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 <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/extensions/extension_action_manager.h" 14 #include "chrome/browser/extensions/extension_action_manager.h"
15 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/extension_util.h" 16 #include "chrome/browser/extensions/extension_util.h"
17 #include "chrome/browser/lifetime/application_lifetime.h" 17 #include "chrome/browser/lifetime/application_lifetime.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/common/extensions/api/autotest_private.h" 19 #include "chrome/common/extensions/api/autotest_private.h"
20 #include "extensions/browser/extension_function_registry.h" 20 #include "extensions/browser/extension_function_registry.h"
21 #include "extensions/browser/extension_registry.h" 21 #include "extensions/browser/extension_registry.h"
22 #include "extensions/browser/extension_system.h" 22 #include "extensions/browser/extension_system.h"
23 #include "extensions/common/manifest_handlers/background_info.h" 23 #include "extensions/common/manifest_handlers/background_info.h"
24 #include "extensions/common/manifest_handlers/options_page_info.h" 24 #include "extensions/common/manifest_handlers/options_page_info.h"
25 #include "extensions/common/permissions/api_permission_set.h" 25 #include "extensions/common/permissions/api_permission_set.h"
26 #include "extensions/common/permissions/permission_set.h" 26 #include "extensions/common/permissions/permission_set.h"
27 #include "extensions/common/permissions/permissions_data.h" 27 #include "extensions/common/permissions/permissions_data.h"
28 28
29 #if defined(OS_CHROMEOS) 29 #if defined(OS_CHROMEOS)
30 #include "chrome/browser/chromeos/arc/arc_util.h"
30 #include "chrome/browser/chromeos/login/lock/screen_locker.h" 31 #include "chrome/browser/chromeos/login/lock/screen_locker.h"
31 #include "chrome/browser/chromeos/system/input_device_settings.h" 32 #include "chrome/browser/chromeos/system/input_device_settings.h"
33 #include "chrome/browser/profiles/profile_manager.h"
32 #include "chromeos/dbus/dbus_thread_manager.h" 34 #include "chromeos/dbus/dbus_thread_manager.h"
33 #include "chromeos/dbus/session_manager_client.h" 35 #include "chromeos/dbus/session_manager_client.h"
34 #include "components/user_manager/user.h" 36 #include "components/user_manager/user.h"
35 #include "components/user_manager/user_manager.h" 37 #include "components/user_manager/user_manager.h"
36 #include "ui/message_center/message_center.h" 38 #include "ui/message_center/message_center.h"
37 #include "ui/message_center/notification.h" 39 #include "ui/message_center/notification.h"
38 #endif 40 #endif
39 41
40 namespace extensions { 42 namespace extensions {
41 namespace { 43 namespace {
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 result->SetString("message", notification->message()); 373 result->SetString("message", notification->message());
372 result->SetInteger("priority", notification->priority()); 374 result->SetInteger("priority", notification->priority());
373 result->SetInteger("progress", notification->progress()); 375 result->SetInteger("progress", notification->progress());
374 values->Append(std::move(result)); 376 values->Append(std::move(result));
375 } 377 }
376 378
377 #endif 379 #endif
378 return RespondNow(OneArgument(std::move(values))); 380 return RespondNow(OneArgument(std::move(values)));
379 } 381 }
380 382
383 ExtensionFunction::ResponseAction
384 AutotestPrivateIsPlayStoreEnabledFunction::Run() {
385 DVLOG(1) << "AutotestPrivateIsPlayStoreEnabledFunction";
386 bool enabled = false;
387 #if defined(OS_CHROMEOS)
388 Profile* profile = ProfileManager::GetActiveUserProfile();
Luis Héctor Chávez 2017/04/07 01:57:50 qq: is Profile* guaranteed to be non-null at this
khmel 2017/04/07 15:52:45 I think no, but arc::IsArcAllowedForProfile(profil
389 enabled = arc::IsArcAllowedForProfile(profile) &&
Luis Héctor Chávez 2017/04/07 01:57:50 nit: This is redundant.
khmel 2017/04/07 15:52:45 Removed.
390 arc::IsArcPlayStoreEnabledForProfile(profile);
391 #endif
392 return RespondNow(OneArgument(base::MakeUnique<base::Value>(enabled)));
393 }
394
395 ExtensionFunction::ResponseAction
396 AutotestPrivateIsPlayStoreManagedFunction::Run() {
397 DVLOG(1) << "AutotestPrivateIsPlayStoreManagedFunction";
398 bool managed = false;
399 #if defined(OS_CHROMEOS)
400 Profile* profile = ProfileManager::GetActiveUserProfile();
401 managed = arc::IsArcAllowedForProfile(profile) &&
402 arc::IsArcPlayStoreEnabledPreferenceManagedForProfile(profile);
403 #endif
404 return RespondNow(OneArgument(base::MakeUnique<base::Value>(managed)));
405 }
406
407 ExtensionFunction::ResponseAction
408 AutotestPrivateSetPlayStoreEnabledFunction::Run() {
409 DVLOG(1) << "AutotestPrivateSetPlayStoreEnabledFunction";
410 std::unique_ptr<api::autotest_private::SetPlayStoreEnabled::Params> params(
411 api::autotest_private::SetPlayStoreEnabled::Params::Create(*args_));
412 EXTENSION_FUNCTION_VALIDATE(params.get());
413 #if defined(OS_CHROMEOS)
414 Profile* profile = ProfileManager::GetActiveUserProfile();
415 if (arc::IsArcAllowedForProfile(profile))
Luis Héctor Chávez 2017/04/07 02:01:53 Do you also want the semantics of this actually en
khmel 2017/04/07 15:52:45 This is good point. I will update arc::SetArcPlayS
416 arc::SetArcPlayStoreEnabledForProfile(profile, params->enabled);
417 #endif
418 return RespondNow(NoArguments());
Luis Héctor Chávez 2017/04/07 01:57:50 Don't you want to return success/failure? Otherwis
khmel 2017/04/07 15:52:45 Added returning the value
419 }
420
381 static base::LazyInstance<BrowserContextKeyedAPIFactory<AutotestPrivateAPI>>:: 421 static base::LazyInstance<BrowserContextKeyedAPIFactory<AutotestPrivateAPI>>::
382 DestructorAtExit g_factory = LAZY_INSTANCE_INITIALIZER; 422 DestructorAtExit g_factory = LAZY_INSTANCE_INITIALIZER;
383 423
384 // static 424 // static
385 BrowserContextKeyedAPIFactory<AutotestPrivateAPI>* 425 BrowserContextKeyedAPIFactory<AutotestPrivateAPI>*
386 AutotestPrivateAPI::GetFactoryInstance() { 426 AutotestPrivateAPI::GetFactoryInstance() {
387 return g_factory.Pointer(); 427 return g_factory.Pointer();
388 } 428 }
389 429
390 template <> 430 template <>
391 KeyedService* 431 KeyedService*
392 BrowserContextKeyedAPIFactory<AutotestPrivateAPI>::BuildServiceInstanceFor( 432 BrowserContextKeyedAPIFactory<AutotestPrivateAPI>::BuildServiceInstanceFor(
393 content::BrowserContext* context) const { 433 content::BrowserContext* context) const {
394 return new AutotestPrivateAPI(); 434 return new AutotestPrivateAPI();
395 } 435 }
396 436
397 AutotestPrivateAPI::AutotestPrivateAPI() : test_mode_(false) { 437 AutotestPrivateAPI::AutotestPrivateAPI() : test_mode_(false) {
398 } 438 }
399 439
400 AutotestPrivateAPI::~AutotestPrivateAPI() { 440 AutotestPrivateAPI::~AutotestPrivateAPI() {
401 } 441 }
402 442
403 } // namespace extensions 443 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698