app_list: Re-enable people search.
[chromium-blink-merge.git] / chrome / browser / extensions / api / idle / idle_api.cc
blob5bbbacd301c8a8ea1651b3da3a76da71facdc88e
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
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/api/idle/idle_api.h"
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "chrome/browser/extensions/api/idle/idle_api_constants.h"
10 #include "chrome/browser/extensions/api/idle/idle_manager.h"
11 #include "chrome/browser/extensions/api/idle/idle_manager_factory.h"
13 namespace {
15 const int kMinThreshold = 15; // In seconds. Set >1 sec for security concerns.
16 const int kMaxThreshold = 4*60*60; // Four hours, in seconds. Not set
17 // arbitrarily high for security concerns.
19 int ClampThreshold(int threshold) {
20 if (threshold < kMinThreshold) {
21 threshold = kMinThreshold;
22 } else if (threshold > kMaxThreshold) {
23 threshold = kMaxThreshold;
26 return threshold;
29 } // namespace
31 namespace extensions {
33 bool IdleQueryStateFunction::RunAsync() {
34 int threshold;
35 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &threshold));
36 threshold = ClampThreshold(threshold);
38 IdleManagerFactory::GetForBrowserContext(context_)->QueryState(
39 threshold, base::Bind(&IdleQueryStateFunction::IdleStateCallback, this));
41 // Don't send the response, it'll be sent by our callback
42 return true;
45 void IdleQueryStateFunction::IdleStateCallback(IdleState state) {
46 SetResult(IdleManager::CreateIdleValue(state));
47 SendResponse(true);
50 bool IdleSetDetectionIntervalFunction::RunSync() {
51 int threshold;
52 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &threshold));
53 threshold = ClampThreshold(threshold);
55 IdleManagerFactory::GetForBrowserContext(context_)
56 ->SetThreshold(extension_id(), threshold);
58 return true;
61 } // namespace extensions