Skip to content

Commit

Permalink
Move chrome.idle API to extensions/.
Browse files Browse the repository at this point in the history
Move the chrome.idle extension API from chrome/ to
extensions/. Also update it to use UIThreadExtensionFunction
and delete a long-disabled, mostly-useless-anyway API test.

BUG=446320,130138

Review URL: https://codereview.chromium.org/854393004

Cr-Commit-Position: refs/heads/master@{#312381}
  • Loading branch information
derat authored and Commit bot committed Jan 21, 2015
1 parent df59d8f commit ec410fc
Show file tree
Hide file tree
Showing 30 changed files with 145 additions and 228 deletions.
12 changes: 0 additions & 12 deletions chrome/browser/extensions/api/idle/idle_apitest.cc

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "chrome/browser/extensions/api/history/history_api.h"
#include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h"
#include "chrome/browser/extensions/api/identity/identity_api.h"
#include "chrome/browser/extensions/api/idle/idle_manager_factory.h"
#include "chrome/browser/extensions/api/location/location_manager.h"
#include "chrome/browser/extensions/api/mdns/mdns_api.h"
#include "chrome/browser/extensions/api/media_galleries_private/media_galleries_private_api.h"
Expand Down Expand Up @@ -109,7 +108,6 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
extensions::HistoryAPI::GetFactoryInstance();
extensions::HotwordPrivateEventService::GetFactoryInstance();
extensions::IdentityAPI::GetFactoryInstance();
extensions::IdleManagerFactory::GetInstance();
extensions::InstallTrackerFactory::GetInstance();
#if defined(OS_CHROMEOS)
extensions::InputImeAPI::GetFactoryInstance();
Expand Down
8 changes: 0 additions & 8 deletions chrome/chrome_browser_extensions.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,6 @@
'browser/extensions/api/identity/web_auth_flow.h',
'browser/extensions/api/identity_private/identity_private_api.cc',
'browser/extensions/api/identity_private/identity_private_api.h',
'browser/extensions/api/idle/idle_api.cc',
'browser/extensions/api/idle/idle_api.h',
'browser/extensions/api/idle/idle_api_constants.cc',
'browser/extensions/api/idle/idle_api_constants.h',
'browser/extensions/api/idle/idle_manager.cc',
'browser/extensions/api/idle/idle_manager.h',
'browser/extensions/api/idle/idle_manager_factory.cc',
'browser/extensions/api/idle/idle_manager_factory.h',
'browser/extensions/api/idltest/idltest_api.cc',
'browser/extensions/api/idltest/idltest_api.h',
'browser/extensions/api/image_writer_private/destroy_partitions_operation.cc',
Expand Down
1 change: 0 additions & 1 deletion chrome/chrome_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@
'browser/extensions/api/hotword_private/hotword_private_apitest.cc',
'browser/extensions/api/i18n/i18n_apitest.cc',
'browser/extensions/api/identity/identity_apitest.cc',
'browser/extensions/api/idle/idle_apitest.cc',
'browser/extensions/api/idltest/idltest_apitest.cc',
'browser/extensions/api/image_writer_private/image_writer_private_apitest.cc',
'browser/extensions/api/image_writer_private/test_utils.cc',
Expand Down
1 change: 0 additions & 1 deletion chrome/chrome_tests_unit.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,6 @@
'browser/extensions/api/identity/extension_token_key_unittest.cc',
'browser/extensions/api/identity/gaia_web_auth_flow_unittest.cc',
'browser/extensions/api/identity/identity_mint_queue_unittest.cc',
'browser/extensions/api/idle/idle_api_unittest.cc',
'browser/extensions/api/image_writer_private/destroy_partitions_operation_unittest.cc',
'browser/extensions/api/image_writer_private/operation_manager_unittest.cc',
'browser/extensions/api/image_writer_private/operation_unittest.cc',
Expand Down
4 changes: 0 additions & 4 deletions chrome/common/extensions/api/_api_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,6 @@
"dependencies": ["permission:idltest"],
"contexts": ["blessed_extension"]
},
"idle": {
"dependencies": ["permission:idle"],
"contexts": ["blessed_extension"]
},
"infobars": {
"dependencies": ["permission:infobars"],
"contexts": ["blessed_extension"]
Expand Down
4 changes: 0 additions & 4 deletions chrome/common/extensions/api/_permission_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,6 @@
"channel": "trunk",
"extension_types": ["extension"]
},
"idle": {
"channel": "stable",
"extension_types": ["extension", "legacy_packaged_app", "platform_app"]
},
"infobars": [
{
"channel": "dev",
Expand Down
1 change: 0 additions & 1 deletion chrome/common/extensions/api/schemas.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
'i18n.json',
'identity.idl',
'identity_private.idl',
'idle.json',
'image_writer_private.idl',
'inline_install_private.idl',
'input_ime.json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ std::vector<APIPermissionInfo*> ChromeAPIPermissions::GetAllPermissions()
IDS_EXTENSION_PROMPT_WARNING_HISTORY_WRITE,
PermissionMessage::kBrowsingHistory},
{APIPermission::kIdltest, "idltest"},
{APIPermission::kIdle, "idle"},
{APIPermission::kInfobars, "infobars"},
{APIPermission::kInput,
"input",
Expand Down
10 changes: 0 additions & 10 deletions chrome/test/data/extensions/api_test/idle/manifest.json

This file was deleted.

38 changes: 0 additions & 38 deletions chrome/test/data/extensions/api_test/idle/test.js

This file was deleted.

19 changes: 10 additions & 9 deletions extensions/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,26 @@ if (false) {
sources = [
"browser/admin_policy_unittest.cc",
"browser/api/api_resource_manager_unittest.cc",
"browser/api/cast_channel/cast_auth_ica_unittest.cc",
"browser/api/cast_channel/cast_auth_util_unittest.cc",
"browser/api/cast_channel/cast_channel_api_unittest.cc",
"browser/api/cast_channel/cast_framer_unittest.cc",
"browser/api/cast_channel/cast_socket_unittest.cc",
"browser/api/cast_channel/cast_transport_unittest.cc",
"browser/api/cast_channel/keep_alive_delegate_unittest.cc",
"browser/api/cast_channel/logger_unittest.cc",
"browser/api/declarative/declarative_rule_unittest.cc",
"browser/api/declarative/deduping_factory_unittest.cc",
"browser/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc",
"browser/api/declarative_webrequest/webrequest_condition_unittest.cc",
"browser/api/idle/idle_api_unittest.cc",
"browser/api/sockets_tcp/sockets_tcp_api_unittest.cc",
"browser/api/storage/settings_quota_unittest.cc",
"browser/api/storage/storage_api_unittest.cc",
"browser/api/storage/storage_frontend_unittest.cc",
"browser/api/web_request/form_data_parser_unittest.cc",
"browser/api/web_request/upload_data_presenter_unittest.cc",
"browser/api/web_request/web_request_time_tracker_unittest.cc",
"browser/api/cast_channel/cast_auth_ica_unittest.cc",
"browser/api/cast_channel/cast_auth_util_unittest.cc",
"browser/api/cast_channel/cast_channel_api_unittest.cc",
"browser/api/cast_channel/cast_framer_unittest.cc",
"browser/api/cast_channel/cast_socket_unittest.cc",
"browser/api/cast_channel/cast_transport_unittest.cc",
"browser/api/cast_channel/keep_alive_delegate_unittest.cc",
"browser/api/cast_channel/logger_unittest.cc",
"browser/computed_hashes_unittest.cc",
"browser/content_hash_tree_unittest.cc",
"browser/event_listener_map_unittest.cc",
Expand Down Expand Up @@ -224,10 +225,10 @@ if (false) {
"common/extension_set_unittest.cc",
"common/file_util_unittest.cc",
"common/image_util_unittest.cc",
"common/manifest_handler_unittest.cc",
"common/manifest_handlers/content_capabilities_manifest_unittest.cc",
"common/manifest_handlers/oauth2_manifest_unittest.cc",
"common/manifest_handlers/shared_module_manifest_unittest.cc",
"common/manifest_handler_unittest.cc",
"common/message_bundle_unittest.cc",
"common/one_shot_event_unittest.cc",
"common/permissions/manifest_permission_set_unittest.cc",
Expand Down
8 changes: 8 additions & 0 deletions extensions/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ source_set("browser") {
"api/hid/hid_connection_resource.h",
"api/hid/hid_device_manager.cc",
"api/hid/hid_device_manager.h",
"api/idle/idle_api.cc",
"api/idle/idle_api.h",
"api/idle/idle_api_constants.cc",
"api/idle/idle_api_constants.h",
"api/idle/idle_manager.cc",
"api/idle/idle_manager.h",
"api/idle/idle_manager_factory.cc",
"api/idle/idle_manager_factory.h",
"api/management/management_api.cc",
"api/management/management_api.h",
"api/management/management_api_constants.cc",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/extensions/api/idle/idle_api.h"
#include "extensions/browser/api/idle/idle_api.h"

#include "base/bind.h"
#include "base/callback.h"
#include "chrome/browser/extensions/api/idle/idle_api_constants.h"
#include "chrome/browser/extensions/api/idle/idle_manager.h"
#include "chrome/browser/extensions/api/idle/idle_manager_factory.h"
#include "base/values.h"
#include "extensions/browser/api/idle/idle_api_constants.h"
#include "extensions/browser/api/idle/idle_manager.h"
#include "extensions/browser/api/idle/idle_manager_factory.h"

namespace extensions {

namespace {

const int kMinThreshold = 15; // In seconds. Set >1 sec for security concerns.
const int kMaxThreshold = 4*60*60; // Four hours, in seconds. Not set
// arbitrarily high for security concerns.
// In seconds. Set >1 sec for security concerns.
const int kMinThreshold = 15;

// Four hours, in seconds. Not set arbitrarily high for security concerns.
const int kMaxThreshold = 4 * 60 * 60;

int ClampThreshold(int threshold) {
if (threshold < kMinThreshold) {
Expand All @@ -28,34 +33,30 @@ int ClampThreshold(int threshold) {

} // namespace

namespace extensions {

bool IdleQueryStateFunction::RunAsync() {
int threshold;
ExtensionFunction::ResponseAction IdleQueryStateFunction::Run() {
int threshold = 0;
EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &threshold));
threshold = ClampThreshold(threshold);

IdleManagerFactory::GetForBrowserContext(context_)->QueryState(
threshold, base::Bind(&IdleQueryStateFunction::IdleStateCallback, this));

// Don't send the response, it'll be sent by our callback
return true;
return RespondLater();
}

void IdleQueryStateFunction::IdleStateCallback(ui::IdleState state) {
SetResult(IdleManager::CreateIdleValue(state));
SendResponse(true);
Respond(OneArgument(IdleManager::CreateIdleValue(state)));
}

bool IdleSetDetectionIntervalFunction::RunSync() {
int threshold;
ExtensionFunction::ResponseAction IdleSetDetectionIntervalFunction::Run() {
int threshold = 0;
EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &threshold));
threshold = ClampThreshold(threshold);

IdleManagerFactory::GetForBrowserContext(context_)
->SetThreshold(extension_id(), threshold);

return true;
return RespondNow(NoArguments());
}

} // namespace extensions
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,42 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_API_IDLE_IDLE_API_H_
#define CHROME_BROWSER_EXTENSIONS_API_IDLE_IDLE_API_H_
#ifndef EXTENSIONS_BROWSER_API_IDLE_IDLE_API_H_
#define EXTENSIONS_BROWSER_API_IDLE_IDLE_API_H_

#include "extensions/browser/extension_function.h"
#include "ui/base/idle/idle.h"

namespace extensions {

// Implementation of the chrome.idle.queryState API.
class IdleQueryStateFunction : public AsyncExtensionFunction {
class IdleQueryStateFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("idle.queryState", IDLE_QUERYSTATE)

protected:
~IdleQueryStateFunction() override {}

// ExtensionFunction:
bool RunAsync() override;
// UIThreadExtensionFunction:
ResponseAction Run() override;

private:
void IdleStateCallback(ui::IdleState state);
};

// Implementation of the chrome.idle.setDetectionInterval API.
class IdleSetDetectionIntervalFunction : public SyncExtensionFunction {
class IdleSetDetectionIntervalFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("idle.setDetectionInterval",
IDLE_SETDETECTIONINTERVAL)

protected:
~IdleSetDetectionIntervalFunction() override {}

// ExtensionFunction:
bool RunSync() override;
// UIThreadExtensionFunction:
ResponseAction Run() override;
};

} // namespace extensions

#endif // CHROME_BROWSER_EXTENSIONS_API_IDLE_IDLE_API_H_
#endif // EXTENSIONS_BROWSER_API_IDLE_IDLE_API_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/extensions/api/idle/idle_api_constants.h"
#include "extensions/browser/api/idle/idle_api_constants.h"

namespace extensions {

namespace idle_api_constants {

const char kStateActive[] = "active";
const char kStateIdle[] = "idle";
const char kStateLocked[] = "locked";

} // namespace idle_api_constants

} // namespace extensions
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_API_IDLE_IDLE_API_CONSTANTS_H_
#define CHROME_BROWSER_EXTENSIONS_API_IDLE_IDLE_API_CONSTANTS_H_
#ifndef EXTENSIONS_BROWSER_API_IDLE_IDLE_API_CONSTANTS_H_
#define EXTENSIONS_BROWSER_API_IDLE_IDLE_API_CONSTANTS_H_

namespace extensions {

namespace idle_api_constants {

// Events.
extern const char kOnStateChanged[];

// States
// States.
extern const char kStateActive[];
extern const char kStateIdle[];
extern const char kStateLocked[];

} // namespace idle_api_constants

} // namespace extensions

#endif // CHROME_BROWSER_EXTENSIONS_API_IDLE_IDLE_API_CONSTANTS_H_
#endif // EXTENSIONS_BROWSER_API_IDLE_IDLE_API_CONSTANTS_H_
Loading

0 comments on commit ec410fc

Please sign in to comment.