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

Side by Side Diff: chrome/browser/sync/notifier/chrome_system_resources.h

Issue 2979003: Reworked ChromeSystemResources to handle callbacks properly. (Closed)
Patch Set: Fixed compile error Created 10 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
« no previous file with comments | « no previous file | chrome/browser/sync/notifier/chrome_system_resources.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 // Simple system resources class that uses the current message loop 5 // Simple system resources class that uses the current message loop
6 // for scheduling. Assumes the current message loop is already 6 // for scheduling. Assumes the current message loop is already
7 // running. 7 // running.
8 8
9 #ifndef CHROME_BROWSER_SYNC_NOTIFIER_CHROME_SYSTEM_RESOURCES_H_ 9 #ifndef CHROME_BROWSER_SYNC_NOTIFIER_CHROME_SYSTEM_RESOURCES_H_
10 #define CHROME_BROWSER_SYNC_NOTIFIER_CHROME_SYSTEM_RESOURCES_H_ 10 #define CHROME_BROWSER_SYNC_NOTIFIER_CHROME_SYSTEM_RESOURCES_H_
11 11
12 #include <set>
13
14 #include "base/non_thread_safe.h"
15 #include "base/scoped_ptr.h"
16 #include "base/task.h"
12 #include "google/cacheinvalidation/invalidation-client.h" 17 #include "google/cacheinvalidation/invalidation-client.h"
13 18
14 namespace sync_notifier { 19 namespace sync_notifier {
15 20
16 // TODO(akalin): Add a NonThreadSafe member to this class and use it.
17
18 class ChromeSystemResources : public invalidation::SystemResources { 21 class ChromeSystemResources : public invalidation::SystemResources {
19 public: 22 public:
20 ChromeSystemResources(); 23 ChromeSystemResources();
21 24
22 ~ChromeSystemResources(); 25 ~ChromeSystemResources();
23 26
27 // invalidation::SystemResources implementation.
28
24 virtual invalidation::Time current_time(); 29 virtual invalidation::Time current_time();
25 30
26 virtual void StartScheduler(); 31 virtual void StartScheduler();
27 32
28 // We assume that the current message loop is stopped shortly after
29 // this is called, i.e. that any in-flight delayed tasks won't get
30 // run.
31 //
32 // TODO(akalin): Make sure that the above actually holds. Use a
33 // ScopedRunnableMethodFactory for better safety.
34 virtual void StopScheduler(); 33 virtual void StopScheduler();
35 34
36 virtual void ScheduleWithDelay(invalidation::TimeDelta delay, 35 virtual void ScheduleWithDelay(invalidation::TimeDelta delay,
37 invalidation::Closure* task); 36 invalidation::Closure* task);
38 37
39 virtual void ScheduleImmediately(invalidation::Closure* task); 38 virtual void ScheduleImmediately(invalidation::Closure* task);
40 39
41 virtual void Log(LogLevel level, const char* file, int line, 40 virtual void Log(LogLevel level, const char* file, int line,
42 const char* format, ...); 41 const char* format, ...);
43 42
44 private: 43 private:
45 bool scheduler_active_; 44 NonThreadSafe non_thread_safe_;
45 scoped_ptr<ScopedRunnableMethodFactory<ChromeSystemResources> >
46 scoped_runnable_method_factory_;
47 // Holds all posted tasks that have not yet been run.
48 std::set<invalidation::Closure*> posted_tasks_;
49
50 // If the scheduler has been started, inserts |task| into
51 // |posted_tasks_| and returns a Task* to post. Otherwise,
52 // immediately deletes |task| and returns NULL.
53 Task* MakeTaskToPost(invalidation::Closure* task);
54
55 // Runs the task, deletes it, and removes it from |posted_tasks_|.
56 void RunPostedTask(invalidation::Closure* task);
46 }; 57 };
47 58
48 } // namespace sync_notifier 59 } // namespace sync_notifier
49 60
50 #endif // CHROME_BROWSER_SYNC_NOTIFIER_CHROME_SYSTEM_RESOURCES_H_ 61 #endif // CHROME_BROWSER_SYNC_NOTIFIER_CHROME_SYSTEM_RESOURCES_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync/notifier/chrome_system_resources.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698