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

Side by Side Diff: chrome/browser/extensions/api/idle/idle_api.cc

Issue 10750016: Moved c/b/e/*idle* to c/b/e/api/idle/ (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: -> extensions namespace Created 8 years, 5 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/extension_idle_api.h" 5 #include "chrome/browser/extensions/api/idle/idle_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/json/json_writer.h" 13 #include "base/json/json_writer.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/time.h" 16 #include "base/time.h"
17 #include "chrome/browser/extensions/extension_event_router.h" 17 #include "chrome/browser/extensions/extension_event_router.h"
18 #include "chrome/browser/extensions/extension_host.h" 18 #include "chrome/browser/extensions/extension_host.h"
19 #include "chrome/browser/extensions/extension_idle_api_constants.h" 19 #include "chrome/browser/extensions/api/idle/idle_api_constants.h"
20 #include "chrome/browser/extensions/extension_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/common/extensions/extension.h" 22 #include "chrome/common/extensions/extension.h"
23 #include "content/public/browser/render_view_host.h" 23 #include "content/public/browser/render_view_host.h"
24 24
25 namespace keys = extension_idle_api_constants; 25 using extensions::ExtensionIdleCache;
26 using extensions::ExtensionIdleEventRouter;
27 using extensions::ExtensionIdleQueryStateFunction;
28
29 namespace keys = extensions::idle_api_constants;
26 30
27 namespace { 31 namespace {
28 32
29 const int kIdlePollInterval = 1; // Number of seconds between status checks 33 const int kIdlePollInterval = 1; // Number of seconds between status checks
30 // when polling for active. 34 // when polling for active.
31 const int kThrottleInterval = 1; // Number of seconds to throttle idle checks 35 const int kThrottleInterval = 1; // Number of seconds to throttle idle checks
32 // for. Return the previously checked idle 36 // for. Return the previously checked idle
33 // state if the next check is faster than this 37 // state if the next check is faster than this
34 const int kMinThreshold = 15; // In seconds. Set >1 sec for security concerns. 38 const int kMinThreshold = 15; // In seconds. Set >1 sec for security concerns.
35 const int kMaxThreshold = 4*60*60; // Four hours, in seconds. Not set 39 const int kMaxThreshold = 4*60*60; // Four hours, in seconds. Not set
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 75
72 DISALLOW_COPY_AND_ASSIGN(ExtensionIdlePollingTask); 76 DISALLOW_COPY_AND_ASSIGN(ExtensionIdlePollingTask);
73 }; 77 };
74 78
75 // Implementation of ExtensionIdlePollingTask. 79 // Implementation of ExtensionIdlePollingTask.
76 bool ExtensionIdlePollingTask::poll_task_running_ = false; 80 bool ExtensionIdlePollingTask::poll_task_running_ = false;
77 81
78 void ExtensionIdlePollingTask::IdleStateCallback(IdleState current_state) { 82 void ExtensionIdlePollingTask::IdleStateCallback(IdleState current_state) {
79 // If we just came into an active state, notify the extension. 83 // If we just came into an active state, notify the extension.
80 if (IDLE_STATE_ACTIVE == current_state && last_state_ != current_state) 84 if (IDLE_STATE_ACTIVE == current_state && last_state_ != current_state)
81 ExtensionIdleEventRouter::OnIdleStateChange(profile_, current_state); 85 extensions::ExtensionIdleEventRouter::OnIdleStateChange(profile_,
Yoyo Zhou 2012/07/30 08:16:27 If you're using this class you shouldn't need the
mitchellwrosen 2012/07/30 17:29:20 Done.
86 current_state);
82 87
83 ExtensionIdlePollingTask::poll_task_running_ = false; 88 ExtensionIdlePollingTask::poll_task_running_ = false;
84 89
85 ExtensionIdleCache::UpdateCache(threshold_, current_state); 90 ExtensionIdleCache::UpdateCache(threshold_, current_state);
86 91
87 // Startup another polling task as we exit. 92 // Startup another polling task as we exit.
88 if (current_state != IDLE_STATE_ACTIVE) 93 if (current_state != IDLE_STATE_ACTIVE)
89 ExtensionIdlePollingTask::CreateNewPollTask(threshold_, current_state, 94 ExtensionIdlePollingTask::CreateNewPollTask(threshold_, current_state,
90 profile_); 95 profile_);
91 96
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 StringValue* result = new StringValue(IdleStateToDescription(idle_state)); 132 StringValue* result = new StringValue(IdleStateToDescription(idle_state));
128 return result; 133 return result;
129 } 134 }
130 135
131 int CheckThresholdBounds(int timeout) { 136 int CheckThresholdBounds(int timeout) {
132 if (timeout < kMinThreshold) return kMinThreshold; 137 if (timeout < kMinThreshold) return kMinThreshold;
133 if (timeout > kMaxThreshold) return kMaxThreshold; 138 if (timeout > kMaxThreshold) return kMaxThreshold;
134 return timeout; 139 return timeout;
135 } 140 }
136 141
137 }; // namespace 142 } // namespace
138 143
139 void ExtensionIdleEventRouter::OnIdleStateChange(Profile* profile, 144 void ExtensionIdleEventRouter::OnIdleStateChange(Profile* profile,
140 IdleState state) { 145 IdleState state) {
141 // Prepare the single argument of the current state. 146 // Prepare the single argument of the current state.
142 ListValue args; 147 ListValue args;
143 args.Append(CreateIdleValue(state)); 148 args.Append(CreateIdleValue(state));
144 std::string json_args; 149 std::string json_args;
145 base::JSONWriter::Write(&args, &json_args); 150 base::JSONWriter::Write(&args, &json_args);
146 151
147 profile->GetExtensionEventRouter()->DispatchEventToRenderers( 152 profile->GetExtensionEventRouter()->DispatchEventToRenderers(
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 267 }
263 } 268 }
264 269
265 int ExtensionIdleCache::get_min_threshold() { 270 int ExtensionIdleCache::get_min_threshold() {
266 return kMinThreshold; 271 return kMinThreshold;
267 } 272 }
268 273
269 double ExtensionIdleCache::get_throttle_interval() { 274 double ExtensionIdleCache::get_throttle_interval() {
270 return static_cast<double>(kThrottleInterval); 275 return static_cast<double>(kThrottleInterval);
271 } 276 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698