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

Side by Side Diff: chrome/browser/extensions/api/alarms/alarms_api.h

Issue 22900005: Fixing race conditions in chrome.alarms (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
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 #ifndef CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARMS_API_H__ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARMS_API_H__
6 #define CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARMS_API_H__ 6 #define CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARMS_API_H__
7 7
8 #include <vector>
9
8 #include "chrome/browser/extensions/extension_function.h" 10 #include "chrome/browser/extensions/extension_function.h"
9 11
10 namespace base { 12 namespace base {
11 class Clock; 13 class Clock;
12 } // namespace base 14 } // namespace base
13 15
14 namespace extensions { 16 namespace extensions {
17 struct Alarm;
18 typedef std::vector<Alarm> AlarmList;
15 19
16 class AlarmsCreateFunction : public SyncExtensionFunction { 20 class AlarmsCreateFunction : public AsyncExtensionFunction {
17 public: 21 public:
18 AlarmsCreateFunction(); 22 AlarmsCreateFunction();
19 // Use |clock| instead of the default clock. Does not take ownership 23 // Use |clock| instead of the default clock. Does not take ownership
20 // of |clock|. Used for testing. 24 // of |clock|. Used for testing.
21 explicit AlarmsCreateFunction(base::Clock* clock); 25 explicit AlarmsCreateFunction(base::Clock* clock);
22 protected: 26 protected:
23 virtual ~AlarmsCreateFunction(); 27 virtual ~AlarmsCreateFunction();
24 28
25 // ExtensionFunction: 29 // ExtensionFunction:
26 virtual bool RunImpl() OVERRIDE; 30 virtual bool RunImpl() OVERRIDE;
27 DECLARE_EXTENSION_FUNCTION("alarms.create", ALARMS_CREATE) 31 DECLARE_EXTENSION_FUNCTION("alarms.create", ALARMS_CREATE)
28 private: 32 private:
33 void Callback();
34
29 base::Clock* const clock_; 35 base::Clock* const clock_;
30 // Whether or not we own |clock_|. This is needed because we own it 36 // Whether or not we own |clock_|. This is needed because we own it
31 // when we create it ourselves, but not when it's passed in for 37 // when we create it ourselves, but not when it's passed in for
32 // testing. 38 // testing.
33 bool owns_clock_; 39 bool owns_clock_;
34 }; 40 };
35 41
36 class AlarmsGetFunction : public SyncExtensionFunction { 42 class AlarmsGetFunction : public AsyncExtensionFunction {
37 protected: 43 protected:
38 virtual ~AlarmsGetFunction() {} 44 virtual ~AlarmsGetFunction() {}
39 45
40 // ExtensionFunction: 46 // ExtensionFunction:
41 virtual bool RunImpl() OVERRIDE; 47 virtual bool RunImpl() OVERRIDE;
48
49 private:
50 void Callback(const std::string& name, Alarm* alarm);
42 DECLARE_EXTENSION_FUNCTION("alarms.get", ALARMS_GET) 51 DECLARE_EXTENSION_FUNCTION("alarms.get", ALARMS_GET)
43 }; 52 };
44 53
45 class AlarmsGetAllFunction : public SyncExtensionFunction { 54 class AlarmsGetAllFunction : public AsyncExtensionFunction {
46 protected: 55 protected:
47 virtual ~AlarmsGetAllFunction() {} 56 virtual ~AlarmsGetAllFunction() {}
48 57
49 // ExtensionFunction: 58 // ExtensionFunction:
50 virtual bool RunImpl() OVERRIDE; 59 virtual bool RunImpl() OVERRIDE;
60 private:
61 void Callback(const AlarmList* alarms);
51 DECLARE_EXTENSION_FUNCTION("alarms.getAll", ALARMS_GETALL) 62 DECLARE_EXTENSION_FUNCTION("alarms.getAll", ALARMS_GETALL)
52 }; 63 };
53 64
54 class AlarmsClearFunction : public SyncExtensionFunction { 65 class AlarmsClearFunction : public AsyncExtensionFunction {
55 protected: 66 protected:
56 virtual ~AlarmsClearFunction() {} 67 virtual ~AlarmsClearFunction() {}
57 68
58 // ExtensionFunction: 69 // ExtensionFunction:
59 virtual bool RunImpl() OVERRIDE; 70 virtual bool RunImpl() OVERRIDE;
71 private:
72 void Callback(const std::string& name, bool success);
60 DECLARE_EXTENSION_FUNCTION("alarms.clear", ALARMS_CLEAR) 73 DECLARE_EXTENSION_FUNCTION("alarms.clear", ALARMS_CLEAR)
61 }; 74 };
62 75
63 class AlarmsClearAllFunction : public SyncExtensionFunction { 76 class AlarmsClearAllFunction : public AsyncExtensionFunction {
64 protected: 77 protected:
65 virtual ~AlarmsClearAllFunction() {} 78 virtual ~AlarmsClearAllFunction() {}
66 79
67 // ExtensionFunction: 80 // ExtensionFunction:
68 virtual bool RunImpl() OVERRIDE; 81 virtual bool RunImpl() OVERRIDE;
82 private:
83 void Callback();
69 DECLARE_EXTENSION_FUNCTION("alarms.clearAll", ALARMS_CLEARALL) 84 DECLARE_EXTENSION_FUNCTION("alarms.clearAll", ALARMS_CLEARALL)
70 }; 85 };
71 86
72 } // namespace extensions 87 } // namespace extensions
73 88
74 #endif // CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARMS_API_H__ 89 #endif // CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARMS_API_H__
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/alarms/alarm_manager.cc ('k') | chrome/browser/extensions/api/alarms/alarms_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698