| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_INVALIDATION_SYNC_SYSTEM_RESOURCES_H_ | 9 #ifndef COMPONENTS_INVALIDATION_SYNC_SYSTEM_RESOURCES_H_ |
| 10 #define COMPONENTS_INVALIDATION_SYNC_SYSTEM_RESOURCES_H_ | 10 #define COMPONENTS_INVALIDATION_SYNC_SYSTEM_RESOURCES_H_ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 class GCMNetworkChannelDelegate; | 30 class GCMNetworkChannelDelegate; |
| 31 | 31 |
| 32 class SyncLogger : public invalidation::Logger { | 32 class SyncLogger : public invalidation::Logger { |
| 33 public: | 33 public: |
| 34 SyncLogger(); | 34 SyncLogger(); |
| 35 | 35 |
| 36 virtual ~SyncLogger(); | 36 virtual ~SyncLogger(); |
| 37 | 37 |
| 38 // invalidation::Logger implementation. | 38 // invalidation::Logger implementation. |
| 39 virtual void Log(LogLevel level, const char* file, int line, | 39 virtual void Log(LogLevel level, const char* file, int line, |
| 40 const char* format, ...) OVERRIDE; | 40 const char* format, ...) override; |
| 41 | 41 |
| 42 virtual void SetSystemResources( | 42 virtual void SetSystemResources( |
| 43 invalidation::SystemResources* resources) OVERRIDE; | 43 invalidation::SystemResources* resources) override; |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class SyncInvalidationScheduler : public invalidation::Scheduler { | 46 class SyncInvalidationScheduler : public invalidation::Scheduler { |
| 47 public: | 47 public: |
| 48 SyncInvalidationScheduler(); | 48 SyncInvalidationScheduler(); |
| 49 | 49 |
| 50 virtual ~SyncInvalidationScheduler(); | 50 virtual ~SyncInvalidationScheduler(); |
| 51 | 51 |
| 52 // Start and stop the scheduler. | 52 // Start and stop the scheduler. |
| 53 void Start(); | 53 void Start(); |
| 54 void Stop(); | 54 void Stop(); |
| 55 | 55 |
| 56 // invalidation::Scheduler implementation. | 56 // invalidation::Scheduler implementation. |
| 57 virtual void Schedule(invalidation::TimeDelta delay, | 57 virtual void Schedule(invalidation::TimeDelta delay, |
| 58 invalidation::Closure* task) OVERRIDE; | 58 invalidation::Closure* task) override; |
| 59 | 59 |
| 60 virtual bool IsRunningOnThread() const OVERRIDE; | 60 virtual bool IsRunningOnThread() const override; |
| 61 | 61 |
| 62 virtual invalidation::Time GetCurrentTime() const OVERRIDE; | 62 virtual invalidation::Time GetCurrentTime() const override; |
| 63 | 63 |
| 64 virtual void SetSystemResources( | 64 virtual void SetSystemResources( |
| 65 invalidation::SystemResources* resources) OVERRIDE; | 65 invalidation::SystemResources* resources) override; |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 // Runs the task, deletes it, and removes it from |posted_tasks_|. | 68 // Runs the task, deletes it, and removes it from |posted_tasks_|. |
| 69 void RunPostedTask(invalidation::Closure* task); | 69 void RunPostedTask(invalidation::Closure* task); |
| 70 | 70 |
| 71 // Holds all posted tasks that have not yet been run. | 71 // Holds all posted tasks that have not yet been run. |
| 72 std::set<invalidation::Closure*> posted_tasks_; | 72 std::set<invalidation::Closure*> posted_tasks_; |
| 73 | 73 |
| 74 const base::MessageLoop* created_on_loop_; | 74 const base::MessageLoop* created_on_loop_; |
| 75 bool is_started_; | 75 bool is_started_; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 SyncNetworkChannel(); | 100 SyncNetworkChannel(); |
| 101 | 101 |
| 102 virtual ~SyncNetworkChannel(); | 102 virtual ~SyncNetworkChannel(); |
| 103 | 103 |
| 104 // invalidation::NetworkChannel implementation. | 104 // invalidation::NetworkChannel implementation. |
| 105 // SyncNetworkChannel doesn't implement SendMessage. It is responsibility of | 105 // SyncNetworkChannel doesn't implement SendMessage. It is responsibility of |
| 106 // subclass to implement it. | 106 // subclass to implement it. |
| 107 virtual void SetMessageReceiver( | 107 virtual void SetMessageReceiver( |
| 108 invalidation::MessageCallback* incoming_receiver) OVERRIDE; | 108 invalidation::MessageCallback* incoming_receiver) override; |
| 109 virtual void AddNetworkStatusReceiver( | 109 virtual void AddNetworkStatusReceiver( |
| 110 invalidation::NetworkStatusCallback* network_status_receiver) OVERRIDE; | 110 invalidation::NetworkStatusCallback* network_status_receiver) override; |
| 111 virtual void SetSystemResources( | 111 virtual void SetSystemResources( |
| 112 invalidation::SystemResources* resources) OVERRIDE; | 112 invalidation::SystemResources* resources) override; |
| 113 | 113 |
| 114 // Subclass should implement UpdateCredentials to pass new token to channel | 114 // Subclass should implement UpdateCredentials to pass new token to channel |
| 115 // library. | 115 // library. |
| 116 virtual void UpdateCredentials(const std::string& email, | 116 virtual void UpdateCredentials(const std::string& email, |
| 117 const std::string& token) = 0; | 117 const std::string& token) = 0; |
| 118 | 118 |
| 119 // Return value from GetInvalidationClientType will be passed to | 119 // Return value from GetInvalidationClientType will be passed to |
| 120 // invalidation::CreateInvalidationClient. Subclass should return one of the | 120 // invalidation::CreateInvalidationClient. Subclass should return one of the |
| 121 // values from ipc::invalidation::ClientType enum from types.proto. | 121 // values from ipc::invalidation::ClientType enum from types.proto. |
| 122 virtual int GetInvalidationClientType() = 0; | 122 virtual int GetInvalidationClientType() = 0; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 SyncStorage(StateWriter* state_writer, invalidation::Scheduler* scheduler); | 179 SyncStorage(StateWriter* state_writer, invalidation::Scheduler* scheduler); |
| 180 | 180 |
| 181 virtual ~SyncStorage(); | 181 virtual ~SyncStorage(); |
| 182 | 182 |
| 183 void SetInitialState(const std::string& value) { | 183 void SetInitialState(const std::string& value) { |
| 184 cached_state_ = value; | 184 cached_state_ = value; |
| 185 } | 185 } |
| 186 | 186 |
| 187 // invalidation::Storage implementation. | 187 // invalidation::Storage implementation. |
| 188 virtual void WriteKey(const std::string& key, const std::string& value, | 188 virtual void WriteKey(const std::string& key, const std::string& value, |
| 189 invalidation::WriteKeyCallback* done) OVERRIDE; | 189 invalidation::WriteKeyCallback* done) override; |
| 190 | 190 |
| 191 virtual void ReadKey(const std::string& key, | 191 virtual void ReadKey(const std::string& key, |
| 192 invalidation::ReadKeyCallback* done) OVERRIDE; | 192 invalidation::ReadKeyCallback* done) override; |
| 193 | 193 |
| 194 virtual void DeleteKey(const std::string& key, | 194 virtual void DeleteKey(const std::string& key, |
| 195 invalidation::DeleteKeyCallback* done) OVERRIDE; | 195 invalidation::DeleteKeyCallback* done) override; |
| 196 | 196 |
| 197 virtual void ReadAllKeys( | 197 virtual void ReadAllKeys( |
| 198 invalidation::ReadAllKeysCallback* key_callback) OVERRIDE; | 198 invalidation::ReadAllKeysCallback* key_callback) override; |
| 199 | 199 |
| 200 virtual void SetSystemResources( | 200 virtual void SetSystemResources( |
| 201 invalidation::SystemResources* resources) OVERRIDE; | 201 invalidation::SystemResources* resources) override; |
| 202 | 202 |
| 203 private: | 203 private: |
| 204 // Runs the given storage callback with SUCCESS status and deletes it. | 204 // Runs the given storage callback with SUCCESS status and deletes it. |
| 205 void RunAndDeleteWriteKeyCallback( | 205 void RunAndDeleteWriteKeyCallback( |
| 206 invalidation::WriteKeyCallback* callback); | 206 invalidation::WriteKeyCallback* callback); |
| 207 | 207 |
| 208 // Runs the given callback with the given value and deletes it. | 208 // Runs the given callback with the given value and deletes it. |
| 209 void RunAndDeleteReadKeyCallback( | 209 void RunAndDeleteReadKeyCallback( |
| 210 invalidation::ReadKeyCallback* callback, const std::string& value); | 210 invalidation::ReadKeyCallback* callback, const std::string& value); |
| 211 | 211 |
| 212 StateWriter* state_writer_; | 212 StateWriter* state_writer_; |
| 213 invalidation::Scheduler* scheduler_; | 213 invalidation::Scheduler* scheduler_; |
| 214 std::string cached_state_; | 214 std::string cached_state_; |
| 215 }; | 215 }; |
| 216 | 216 |
| 217 class INVALIDATION_EXPORT_PRIVATE SyncSystemResources | 217 class INVALIDATION_EXPORT_PRIVATE SyncSystemResources |
| 218 : public NON_EXPORTED_BASE(invalidation::SystemResources) { | 218 : public NON_EXPORTED_BASE(invalidation::SystemResources) { |
| 219 public: | 219 public: |
| 220 SyncSystemResources(SyncNetworkChannel* sync_network_channel, | 220 SyncSystemResources(SyncNetworkChannel* sync_network_channel, |
| 221 StateWriter* state_writer); | 221 StateWriter* state_writer); |
| 222 | 222 |
| 223 virtual ~SyncSystemResources(); | 223 virtual ~SyncSystemResources(); |
| 224 | 224 |
| 225 // invalidation::SystemResources implementation. | 225 // invalidation::SystemResources implementation. |
| 226 virtual void Start() OVERRIDE; | 226 virtual void Start() override; |
| 227 virtual void Stop() OVERRIDE; | 227 virtual void Stop() override; |
| 228 virtual bool IsStarted() const OVERRIDE; | 228 virtual bool IsStarted() const override; |
| 229 virtual void set_platform(const std::string& platform); | 229 virtual void set_platform(const std::string& platform); |
| 230 virtual std::string platform() const OVERRIDE; | 230 virtual std::string platform() const override; |
| 231 virtual SyncLogger* logger() OVERRIDE; | 231 virtual SyncLogger* logger() override; |
| 232 virtual SyncStorage* storage() OVERRIDE; | 232 virtual SyncStorage* storage() override; |
| 233 virtual SyncNetworkChannel* network() OVERRIDE; | 233 virtual SyncNetworkChannel* network() override; |
| 234 virtual SyncInvalidationScheduler* internal_scheduler() OVERRIDE; | 234 virtual SyncInvalidationScheduler* internal_scheduler() override; |
| 235 virtual SyncInvalidationScheduler* listener_scheduler() OVERRIDE; | 235 virtual SyncInvalidationScheduler* listener_scheduler() override; |
| 236 | 236 |
| 237 private: | 237 private: |
| 238 bool is_started_; | 238 bool is_started_; |
| 239 std::string platform_; | 239 std::string platform_; |
| 240 scoped_ptr<SyncLogger> logger_; | 240 scoped_ptr<SyncLogger> logger_; |
| 241 scoped_ptr<SyncInvalidationScheduler> internal_scheduler_; | 241 scoped_ptr<SyncInvalidationScheduler> internal_scheduler_; |
| 242 scoped_ptr<SyncInvalidationScheduler> listener_scheduler_; | 242 scoped_ptr<SyncInvalidationScheduler> listener_scheduler_; |
| 243 scoped_ptr<SyncStorage> storage_; | 243 scoped_ptr<SyncStorage> storage_; |
| 244 // sync_network_channel_ is owned by SyncInvalidationListener. | 244 // sync_network_channel_ is owned by SyncInvalidationListener. |
| 245 SyncNetworkChannel* sync_network_channel_; | 245 SyncNetworkChannel* sync_network_channel_; |
| 246 }; | 246 }; |
| 247 | 247 |
| 248 } // namespace syncer | 248 } // namespace syncer |
| 249 | 249 |
| 250 #endif // COMPONENTS_INVALIDATION_SYNC_SYSTEM_RESOURCES_H_ | 250 #endif // COMPONENTS_INVALIDATION_SYNC_SYSTEM_RESOURCES_H_ |
| OLD | NEW |