blob: 2a0d2d8466b6235360f71c24fb18dcf62c1a86ab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// 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 "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; // 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.
int ClampThreshold(int threshold) {
if (threshold < kMinThreshold) {
threshold = kMinThreshold;
} else if (threshold > kMaxThreshold) {
threshold = kMaxThreshold;
}
return threshold;
}
} // namespace
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));
// Don't send the response, it'll be sent by our callback
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;
}
} // namespace extensions
|