This source file includes following definitions.
- ClampThreshold
- RunImpl
- IdleStateCallback
- RunImpl
#include "chrome/browser/extensions/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"
namespace {
const int kMinThreshold = 15;
const int kMaxThreshold = 4*60*60;
int ClampThreshold(int threshold) {
if (threshold < kMinThreshold) {
threshold = kMinThreshold;
} else if (threshold > kMaxThreshold) {
threshold = kMaxThreshold;
}
return threshold;
}
}
namespace extensions {
bool IdleQueryStateFunction::RunImpl() {
int threshold;
EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &threshold));
threshold = ClampThreshold(threshold);
IdleManagerFactory::GetForProfile(GetProfile())->QueryState(
threshold, base::Bind(&IdleQueryStateFunction::IdleStateCallback, this));
return true;
}
void IdleQueryStateFunction::IdleStateCallback(IdleState state) {
SetResult(IdleManager::CreateIdleValue(state));
SendResponse(true);
}
bool IdleSetDetectionIntervalFunction::RunImpl() {
int threshold;
EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &threshold));
threshold = ClampThreshold(threshold);
IdleManagerFactory::GetForProfile(GetProfile())
->SetThreshold(extension_id(), threshold);
return true;
}
}