blob: 4631e3185ec1bf93044fbbf9a0c4abd92a68f03d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Simple system resources class that uses the current message loop
// for scheduling. Assumes the current message loop is already
// running.
#ifndef CHROME_BROWSER_SYNC_NOTIFIER_CHROME_SYSTEM_RESOURCES_H_
#define CHROME_BROWSER_SYNC_NOTIFIER_CHROME_SYSTEM_RESOURCES_H_
#pragma once
#include <set>
#include <string>
#include "base/non_thread_safe.h"
#include "base/scoped_ptr.h"
#include "base/task.h"
#include "chrome/browser/sync/notifier/state_writer.h"
#include "google/cacheinvalidation/invalidation-client.h"
namespace sync_notifier {
class ChromeSystemResources : public invalidation::SystemResources {
public:
explicit ChromeSystemResources(StateWriter* state_writer);
~ChromeSystemResources();
// invalidation::SystemResources implementation.
virtual invalidation::Time current_time();
virtual void StartScheduler();
virtual void StopScheduler();
virtual void ScheduleWithDelay(invalidation::TimeDelta delay,
invalidation::Closure* task);
virtual void ScheduleImmediately(invalidation::Closure* task);
virtual void ScheduleOnListenerThread(invalidation::Closure* task);
virtual bool IsRunningOnInternalThread();
virtual void Log(LogLevel level, const char* file, int line,
const char* format, ...);
virtual void WriteState(const invalidation::string& state,
invalidation::StorageCallback* callback);
private:
NonThreadSafe non_thread_safe_;
scoped_ptr<ScopedRunnableMethodFactory<ChromeSystemResources> >
scoped_runnable_method_factory_;
// Holds all posted tasks that have not yet been run.
std::set<invalidation::Closure*> posted_tasks_;
StateWriter* state_writer_;
// If the scheduler has been started, inserts |task| into
// |posted_tasks_| and returns a Task* to post. Otherwise,
// immediately deletes |task| and returns NULL.
Task* MakeTaskToPost(invalidation::Closure* task);
// Runs the task, deletes it, and removes it from |posted_tasks_|.
void RunPostedTask(invalidation::Closure* task);
};
} // namespace sync_notifier
#endif // CHROME_BROWSER_SYNC_NOTIFIER_CHROME_SYSTEM_RESOURCES_H_
|