OLD | NEW |
---|---|
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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_IDLE_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDLE_IDLE_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_IDLE_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_IDLE_IDLE_API_H_ |
7 | 7 |
8 #include "base/gtest_prod_util.h" | |
8 #include "chrome/browser/idle.h" | 9 #include "chrome/browser/idle.h" |
9 #include "chrome/browser/extensions/extension_function.h" | 10 #include "chrome/browser/extensions/extension_function.h" |
10 | 11 |
11 class Profile; | 12 class Profile; |
12 | 13 |
14 FORWARD_DECLARE_TEST(ExtensionIdleApiTest, CacheTest); | |
15 | |
16 namespace extensions { | |
17 | |
13 // Event router class for events related to the idle API. | 18 // Event router class for events related to the idle API. |
14 class ExtensionIdleEventRouter { | 19 class ExtensionIdleEventRouter { |
15 public: | 20 public: |
16 static void OnIdleStateChange(Profile* profile, | 21 static void OnIdleStateChange(Profile* profile, |
17 IdleState idleState); | 22 IdleState idleState); |
18 private: | 23 private: |
19 DISALLOW_COPY_AND_ASSIGN(ExtensionIdleEventRouter); | 24 DISALLOW_COPY_AND_ASSIGN(ExtensionIdleEventRouter); |
20 }; | 25 }; |
21 | 26 |
22 // Implementation of the chrome.idle.queryState API. | 27 // Implementation of the chrome.idle.queryState API. |
(...skipping 11 matching lines...) Expand all Loading... | |
34 void IdleStateCallback(int threshold, IdleState state); | 39 void IdleStateCallback(int threshold, IdleState state); |
35 }; | 40 }; |
36 | 41 |
37 // Class used for caching answers from CalculateIdleState. | 42 // Class used for caching answers from CalculateIdleState. |
38 class ExtensionIdleCache { | 43 class ExtensionIdleCache { |
39 public: | 44 public: |
40 static IdleState CalculateIdleState(int threshold); | 45 static IdleState CalculateIdleState(int threshold); |
41 static void UpdateCache(int threshold, IdleState state); | 46 static void UpdateCache(int threshold, IdleState state); |
42 | 47 |
43 private: | 48 private: |
44 FRIEND_TEST_ALL_PREFIXES(ExtensionIdleApiTest, CacheTest); | 49 FRIEND_TEST_ALL_PREFIXES(::ExtensionIdleApiTest, CacheTest); |
45 | 50 |
46 struct CacheData { | 51 struct CacheData { |
47 // Latest moment in history after which we are certain that there was some | 52 // Latest moment in history after which we are certain that there was some |
48 // activity. If we are querying for a threshold beyond this moment, we know | 53 // activity. If we are querying for a threshold beyond this moment, we know |
49 // the result will be active. | 54 // the result will be active. |
50 double latest_known_active; | 55 double latest_known_active; |
51 // [idle_interval_start, idle_interval_end] is the latest interval in | 56 // [idle_interval_start, idle_interval_end] is the latest interval in |
52 // history for which we are certain there was no activity. | 57 // history for which we are certain there was no activity. |
53 double idle_interval_start; | 58 double idle_interval_start; |
54 double idle_interval_end; | 59 double idle_interval_end; |
(...skipping 18 matching lines...) Expand all Loading... | |
73 // |state| is result of the query. | 78 // |state| is result of the query. |
74 // |moment| is moment in time this method is called. | 79 // |moment| is moment in time this method is called. |
75 static void Update(int threshold, IdleState state, double moment); | 80 static void Update(int threshold, IdleState state, double moment); |
76 | 81 |
77 static int get_min_threshold(); | 82 static int get_min_threshold(); |
78 static double get_throttle_interval(); | 83 static double get_throttle_interval(); |
79 | 84 |
80 static CacheData cached_data; | 85 static CacheData cached_data; |
81 }; | 86 }; |
82 | 87 |
83 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_IDLE_API_H_ | 88 } // namespace extension |
Yoyo Zhou
2012/07/30 08:16:27
typo: extensions
mitchellwrosen
2012/07/30 17:29:20
Done.
| |
89 | |
90 #endif // CHROME_BROWSER_EXTENSIONS_API_IDLE_IDLE_API_H_ | |
OLD | NEW |