| 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 // 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 SYNC_NOTIFIER_CHROME_SYSTEM_RESOURCES_H_ | 9 #ifndef SYNC_NOTIFIER_SYNC_SYSTEM_RESOURCES_H_ |
| 10 #define SYNC_NOTIFIER_CHROME_SYSTEM_RESOURCES_H_ | 10 #define SYNC_NOTIFIER_SYNC_SYSTEM_RESOURCES_H_ |
| 11 | 11 |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
| 20 #include "base/threading/non_thread_safe.h" | 20 #include "base/threading/non_thread_safe.h" |
| 21 #include "google/cacheinvalidation/include/system-resources.h" | 21 #include "google/cacheinvalidation/include/system-resources.h" |
| 22 #include "sync/notifier/push_client_channel.h" | 22 #include "sync/notifier/push_client_channel.h" |
| 23 #include "sync/notifier/state_writer.h" | 23 #include "sync/notifier/state_writer.h" |
| 24 | 24 |
| 25 namespace notifier { | 25 namespace notifier { |
| 26 class PushClient; | 26 class PushClient; |
| 27 } // namespace notifier | 27 } // namespace notifier |
| 28 | 28 |
| 29 namespace syncer { | 29 namespace syncer { |
| 30 | 30 |
| 31 class ChromeLogger : public invalidation::Logger { | 31 class SyncLogger : public invalidation::Logger { |
| 32 public: | 32 public: |
| 33 ChromeLogger(); | 33 SyncLogger(); |
| 34 | 34 |
| 35 virtual ~ChromeLogger(); | 35 virtual ~SyncLogger(); |
| 36 | 36 |
| 37 // invalidation::Logger implementation. | 37 // invalidation::Logger implementation. |
| 38 virtual void Log(LogLevel level, const char* file, int line, | 38 virtual void Log(LogLevel level, const char* file, int line, |
| 39 const char* format, ...) OVERRIDE; | 39 const char* format, ...) OVERRIDE; |
| 40 | 40 |
| 41 virtual void SetSystemResources( | 41 virtual void SetSystemResources( |
| 42 invalidation::SystemResources* resources) OVERRIDE; | 42 invalidation::SystemResources* resources) OVERRIDE; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 class ChromeScheduler : public invalidation::Scheduler { | 45 class SyncInvalidationScheduler : public invalidation::Scheduler { |
| 46 public: | 46 public: |
| 47 ChromeScheduler(); | 47 SyncInvalidationScheduler(); |
| 48 | 48 |
| 49 virtual ~ChromeScheduler(); | 49 virtual ~SyncInvalidationScheduler(); |
| 50 | 50 |
| 51 // Start and stop the scheduler. | 51 // Start and stop the scheduler. |
| 52 void Start(); | 52 void Start(); |
| 53 void Stop(); | 53 void Stop(); |
| 54 | 54 |
| 55 // invalidation::Scheduler implementation. | 55 // invalidation::Scheduler implementation. |
| 56 virtual void Schedule(invalidation::TimeDelta delay, | 56 virtual void Schedule(invalidation::TimeDelta delay, |
| 57 invalidation::Closure* task) OVERRIDE; | 57 invalidation::Closure* task) OVERRIDE; |
| 58 | 58 |
| 59 virtual bool IsRunningOnThread() const OVERRIDE; | 59 virtual bool IsRunningOnThread() const OVERRIDE; |
| 60 | 60 |
| 61 virtual invalidation::Time GetCurrentTime() const OVERRIDE; | 61 virtual invalidation::Time GetCurrentTime() const OVERRIDE; |
| 62 | 62 |
| 63 virtual void SetSystemResources( | 63 virtual void SetSystemResources( |
| 64 invalidation::SystemResources* resources) OVERRIDE; | 64 invalidation::SystemResources* resources) OVERRIDE; |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 base::WeakPtrFactory<ChromeScheduler> weak_factory_; | 67 base::WeakPtrFactory<SyncInvalidationScheduler> weak_factory_; |
| 68 // Holds all posted tasks that have not yet been run. | 68 // Holds all posted tasks that have not yet been run. |
| 69 std::set<invalidation::Closure*> posted_tasks_; | 69 std::set<invalidation::Closure*> posted_tasks_; |
| 70 | 70 |
| 71 const MessageLoop* created_on_loop_; | 71 const MessageLoop* created_on_loop_; |
| 72 bool is_started_; | 72 bool is_started_; |
| 73 bool is_stopped_; | 73 bool is_stopped_; |
| 74 | 74 |
| 75 // Runs the task, deletes it, and removes it from |posted_tasks_|. | 75 // Runs the task, deletes it, and removes it from |posted_tasks_|. |
| 76 void RunPostedTask(invalidation::Closure* task); | 76 void RunPostedTask(invalidation::Closure* task); |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 class ChromeStorage : public invalidation::Storage { | 79 class SyncStorage : public invalidation::Storage { |
| 80 public: | 80 public: |
| 81 ChromeStorage(StateWriter* state_writer, invalidation::Scheduler* scheduler); | 81 SyncStorage(StateWriter* state_writer, invalidation::Scheduler* scheduler); |
| 82 | 82 |
| 83 virtual ~ChromeStorage(); | 83 virtual ~SyncStorage(); |
| 84 | 84 |
| 85 void SetInitialState(const std::string& value) { | 85 void SetInitialState(const std::string& value) { |
| 86 cached_state_ = value; | 86 cached_state_ = value; |
| 87 } | 87 } |
| 88 | 88 |
| 89 // invalidation::Storage implementation. | 89 // invalidation::Storage implementation. |
| 90 virtual void WriteKey(const std::string& key, const std::string& value, | 90 virtual void WriteKey(const std::string& key, const std::string& value, |
| 91 invalidation::WriteKeyCallback* done) OVERRIDE; | 91 invalidation::WriteKeyCallback* done) OVERRIDE; |
| 92 | 92 |
| 93 virtual void ReadKey(const std::string& key, | 93 virtual void ReadKey(const std::string& key, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 109 | 109 |
| 110 // Runs the given callback with the given value and deletes it. | 110 // Runs the given callback with the given value and deletes it. |
| 111 void RunAndDeleteReadKeyCallback( | 111 void RunAndDeleteReadKeyCallback( |
| 112 invalidation::ReadKeyCallback* callback, const std::string& value); | 112 invalidation::ReadKeyCallback* callback, const std::string& value); |
| 113 | 113 |
| 114 StateWriter* state_writer_; | 114 StateWriter* state_writer_; |
| 115 invalidation::Scheduler* scheduler_; | 115 invalidation::Scheduler* scheduler_; |
| 116 std::string cached_state_; | 116 std::string cached_state_; |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 class ChromeSystemResources : public invalidation::SystemResources { | 119 class SyncSystemResources : public invalidation::SystemResources { |
| 120 public: | 120 public: |
| 121 ChromeSystemResources(scoped_ptr<notifier::PushClient> push_client, | 121 SyncSystemResources(scoped_ptr<notifier::PushClient> push_client, |
| 122 StateWriter* state_writer); | 122 StateWriter* state_writer); |
| 123 | 123 |
| 124 virtual ~ChromeSystemResources(); | 124 virtual ~SyncSystemResources(); |
| 125 | 125 |
| 126 // invalidation::SystemResources implementation. | 126 // invalidation::SystemResources implementation. |
| 127 virtual void Start() OVERRIDE; | 127 virtual void Start() OVERRIDE; |
| 128 virtual void Stop() OVERRIDE; | 128 virtual void Stop() OVERRIDE; |
| 129 virtual bool IsStarted() const OVERRIDE; | 129 virtual bool IsStarted() const OVERRIDE; |
| 130 virtual void set_platform(const std::string& platform); | 130 virtual void set_platform(const std::string& platform); |
| 131 virtual std::string platform() const OVERRIDE; | 131 virtual std::string platform() const OVERRIDE; |
| 132 virtual ChromeLogger* logger() OVERRIDE; | 132 virtual SyncLogger* logger() OVERRIDE; |
| 133 virtual ChromeStorage* storage() OVERRIDE; | 133 virtual SyncStorage* storage() OVERRIDE; |
| 134 virtual PushClientChannel* network() OVERRIDE; | 134 virtual PushClientChannel* network() OVERRIDE; |
| 135 virtual ChromeScheduler* internal_scheduler() OVERRIDE; | 135 virtual SyncInvalidationScheduler* internal_scheduler() OVERRIDE; |
| 136 virtual ChromeScheduler* listener_scheduler() OVERRIDE; | 136 virtual SyncInvalidationScheduler* listener_scheduler() OVERRIDE; |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 bool is_started_; | 139 bool is_started_; |
| 140 std::string platform_; | 140 std::string platform_; |
| 141 scoped_ptr<ChromeLogger> logger_; | 141 scoped_ptr<SyncLogger> logger_; |
| 142 scoped_ptr<ChromeScheduler> internal_scheduler_; | 142 scoped_ptr<SyncInvalidationScheduler> internal_scheduler_; |
| 143 scoped_ptr<ChromeScheduler> listener_scheduler_; | 143 scoped_ptr<SyncInvalidationScheduler> listener_scheduler_; |
| 144 scoped_ptr<ChromeStorage> storage_; | 144 scoped_ptr<SyncStorage> storage_; |
| 145 PushClientChannel push_client_channel_; | 145 PushClientChannel push_client_channel_; |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 } // namespace syncer | 148 } // namespace syncer |
| 149 | 149 |
| 150 #endif // SYNC_NOTIFIER_CHROME_SYSTEM_RESOURCES_H_ | 150 #endif // SYNC_NOTIFIER_SYNC_SYSTEM_RESOURCES_H_ |
| OLD | NEW |