| 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 15 matching lines...) Expand all Loading... |
| 26 #include "jingle/notifier/base/notifier_options.h" | 26 #include "jingle/notifier/base/notifier_options.h" |
| 27 | 27 |
| 28 namespace syncer { | 28 namespace syncer { |
| 29 | 29 |
| 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 ~SyncLogger() override; |
| 37 | 37 |
| 38 // invalidation::Logger implementation. | 38 // invalidation::Logger implementation. |
| 39 virtual void Log(LogLevel level, const char* file, int line, | 39 void Log(LogLevel level, |
| 40 const char* format, ...) override; | 40 const char* file, |
| 41 int line, |
| 42 const char* format, |
| 43 ...) override; |
| 41 | 44 |
| 42 virtual void SetSystemResources( | 45 void SetSystemResources(invalidation::SystemResources* resources) override; |
| 43 invalidation::SystemResources* resources) override; | |
| 44 }; | 46 }; |
| 45 | 47 |
| 46 class SyncInvalidationScheduler : public invalidation::Scheduler { | 48 class SyncInvalidationScheduler : public invalidation::Scheduler { |
| 47 public: | 49 public: |
| 48 SyncInvalidationScheduler(); | 50 SyncInvalidationScheduler(); |
| 49 | 51 |
| 50 virtual ~SyncInvalidationScheduler(); | 52 ~SyncInvalidationScheduler() override; |
| 51 | 53 |
| 52 // Start and stop the scheduler. | 54 // Start and stop the scheduler. |
| 53 void Start(); | 55 void Start(); |
| 54 void Stop(); | 56 void Stop(); |
| 55 | 57 |
| 56 // invalidation::Scheduler implementation. | 58 // invalidation::Scheduler implementation. |
| 57 virtual void Schedule(invalidation::TimeDelta delay, | 59 void Schedule(invalidation::TimeDelta delay, |
| 58 invalidation::Closure* task) override; | 60 invalidation::Closure* task) override; |
| 59 | 61 |
| 60 virtual bool IsRunningOnThread() const override; | 62 bool IsRunningOnThread() const override; |
| 61 | 63 |
| 62 virtual invalidation::Time GetCurrentTime() const override; | 64 invalidation::Time GetCurrentTime() const override; |
| 63 | 65 |
| 64 virtual void SetSystemResources( | 66 void SetSystemResources(invalidation::SystemResources* resources) override; |
| 65 invalidation::SystemResources* resources) override; | |
| 66 | 67 |
| 67 private: | 68 private: |
| 68 // Runs the task, deletes it, and removes it from |posted_tasks_|. | 69 // Runs the task, deletes it, and removes it from |posted_tasks_|. |
| 69 void RunPostedTask(invalidation::Closure* task); | 70 void RunPostedTask(invalidation::Closure* task); |
| 70 | 71 |
| 71 // Holds all posted tasks that have not yet been run. | 72 // Holds all posted tasks that have not yet been run. |
| 72 std::set<invalidation::Closure*> posted_tasks_; | 73 std::set<invalidation::Closure*> posted_tasks_; |
| 73 | 74 |
| 74 const base::MessageLoop* created_on_loop_; | 75 const base::MessageLoop* created_on_loop_; |
| 75 bool is_started_; | 76 bool is_started_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 92 // Called when network channel state changes. Possible states are: | 93 // Called when network channel state changes. Possible states are: |
| 93 // - INVALIDATIONS_ENABLED : connection is established and working | 94 // - INVALIDATIONS_ENABLED : connection is established and working |
| 94 // - TRANSIENT_INVALIDATION_ERROR : no network, connection lost, etc. | 95 // - TRANSIENT_INVALIDATION_ERROR : no network, connection lost, etc. |
| 95 // - INVALIDATION_CREDENTIALS_REJECTED : Issues with auth token | 96 // - INVALIDATION_CREDENTIALS_REJECTED : Issues with auth token |
| 96 virtual void OnNetworkChannelStateChanged( | 97 virtual void OnNetworkChannelStateChanged( |
| 97 InvalidatorState invalidator_state) = 0; | 98 InvalidatorState invalidator_state) = 0; |
| 98 }; | 99 }; |
| 99 | 100 |
| 100 SyncNetworkChannel(); | 101 SyncNetworkChannel(); |
| 101 | 102 |
| 102 virtual ~SyncNetworkChannel(); | 103 ~SyncNetworkChannel() override; |
| 103 | 104 |
| 104 // invalidation::NetworkChannel implementation. | 105 // invalidation::NetworkChannel implementation. |
| 105 // SyncNetworkChannel doesn't implement SendMessage. It is responsibility of | 106 // SyncNetworkChannel doesn't implement SendMessage. It is responsibility of |
| 106 // subclass to implement it. | 107 // subclass to implement it. |
| 107 virtual void SetMessageReceiver( | 108 void SetMessageReceiver( |
| 108 invalidation::MessageCallback* incoming_receiver) override; | 109 invalidation::MessageCallback* incoming_receiver) override; |
| 109 virtual void AddNetworkStatusReceiver( | 110 void AddNetworkStatusReceiver( |
| 110 invalidation::NetworkStatusCallback* network_status_receiver) override; | 111 invalidation::NetworkStatusCallback* network_status_receiver) override; |
| 111 virtual void SetSystemResources( | 112 void SetSystemResources(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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 171 |
| 172 int received_messages_count_; | 172 int received_messages_count_; |
| 173 | 173 |
| 174 ObserverList<Observer> observers_; | 174 ObserverList<Observer> observers_; |
| 175 }; | 175 }; |
| 176 | 176 |
| 177 class SyncStorage : public invalidation::Storage { | 177 class SyncStorage : public invalidation::Storage { |
| 178 public: | 178 public: |
| 179 SyncStorage(StateWriter* state_writer, invalidation::Scheduler* scheduler); | 179 SyncStorage(StateWriter* state_writer, invalidation::Scheduler* scheduler); |
| 180 | 180 |
| 181 virtual ~SyncStorage(); | 181 ~SyncStorage() override; |
| 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 void WriteKey(const std::string& key, |
| 189 invalidation::WriteKeyCallback* done) override; | 189 const std::string& value, |
| 190 invalidation::WriteKeyCallback* done) override; |
| 190 | 191 |
| 191 virtual void ReadKey(const std::string& key, | 192 void ReadKey(const std::string& key, |
| 192 invalidation::ReadKeyCallback* done) override; | 193 invalidation::ReadKeyCallback* done) override; |
| 193 | 194 |
| 194 virtual void DeleteKey(const std::string& key, | 195 void DeleteKey(const std::string& key, |
| 195 invalidation::DeleteKeyCallback* done) override; | 196 invalidation::DeleteKeyCallback* done) override; |
| 196 | 197 |
| 197 virtual void ReadAllKeys( | 198 void ReadAllKeys(invalidation::ReadAllKeysCallback* key_callback) override; |
| 198 invalidation::ReadAllKeysCallback* key_callback) override; | |
| 199 | 199 |
| 200 virtual void SetSystemResources( | 200 void SetSystemResources(invalidation::SystemResources* resources) override; |
| 201 invalidation::SystemResources* resources) override; | |
| 202 | 201 |
| 203 private: | 202 private: |
| 204 // Runs the given storage callback with SUCCESS status and deletes it. | 203 // Runs the given storage callback with SUCCESS status and deletes it. |
| 205 void RunAndDeleteWriteKeyCallback( | 204 void RunAndDeleteWriteKeyCallback( |
| 206 invalidation::WriteKeyCallback* callback); | 205 invalidation::WriteKeyCallback* callback); |
| 207 | 206 |
| 208 // Runs the given callback with the given value and deletes it. | 207 // Runs the given callback with the given value and deletes it. |
| 209 void RunAndDeleteReadKeyCallback( | 208 void RunAndDeleteReadKeyCallback( |
| 210 invalidation::ReadKeyCallback* callback, const std::string& value); | 209 invalidation::ReadKeyCallback* callback, const std::string& value); |
| 211 | 210 |
| 212 StateWriter* state_writer_; | 211 StateWriter* state_writer_; |
| 213 invalidation::Scheduler* scheduler_; | 212 invalidation::Scheduler* scheduler_; |
| 214 std::string cached_state_; | 213 std::string cached_state_; |
| 215 }; | 214 }; |
| 216 | 215 |
| 217 class INVALIDATION_EXPORT_PRIVATE SyncSystemResources | 216 class INVALIDATION_EXPORT_PRIVATE SyncSystemResources |
| 218 : public NON_EXPORTED_BASE(invalidation::SystemResources) { | 217 : public NON_EXPORTED_BASE(invalidation::SystemResources) { |
| 219 public: | 218 public: |
| 220 SyncSystemResources(SyncNetworkChannel* sync_network_channel, | 219 SyncSystemResources(SyncNetworkChannel* sync_network_channel, |
| 221 StateWriter* state_writer); | 220 StateWriter* state_writer); |
| 222 | 221 |
| 223 virtual ~SyncSystemResources(); | 222 ~SyncSystemResources() override; |
| 224 | 223 |
| 225 // invalidation::SystemResources implementation. | 224 // invalidation::SystemResources implementation. |
| 226 virtual void Start() override; | 225 void Start() override; |
| 227 virtual void Stop() override; | 226 void Stop() override; |
| 228 virtual bool IsStarted() const override; | 227 bool IsStarted() const override; |
| 229 virtual void set_platform(const std::string& platform); | 228 virtual void set_platform(const std::string& platform); |
| 230 virtual std::string platform() const override; | 229 std::string platform() const override; |
| 231 virtual SyncLogger* logger() override; | 230 SyncLogger* logger() override; |
| 232 virtual SyncStorage* storage() override; | 231 SyncStorage* storage() override; |
| 233 virtual SyncNetworkChannel* network() override; | 232 SyncNetworkChannel* network() override; |
| 234 virtual SyncInvalidationScheduler* internal_scheduler() override; | 233 SyncInvalidationScheduler* internal_scheduler() override; |
| 235 virtual SyncInvalidationScheduler* listener_scheduler() override; | 234 SyncInvalidationScheduler* listener_scheduler() override; |
| 236 | 235 |
| 237 private: | 236 private: |
| 238 bool is_started_; | 237 bool is_started_; |
| 239 std::string platform_; | 238 std::string platform_; |
| 240 scoped_ptr<SyncLogger> logger_; | 239 scoped_ptr<SyncLogger> logger_; |
| 241 scoped_ptr<SyncInvalidationScheduler> internal_scheduler_; | 240 scoped_ptr<SyncInvalidationScheduler> internal_scheduler_; |
| 242 scoped_ptr<SyncInvalidationScheduler> listener_scheduler_; | 241 scoped_ptr<SyncInvalidationScheduler> listener_scheduler_; |
| 243 scoped_ptr<SyncStorage> storage_; | 242 scoped_ptr<SyncStorage> storage_; |
| 244 // sync_network_channel_ is owned by SyncInvalidationListener. | 243 // sync_network_channel_ is owned by SyncInvalidationListener. |
| 245 SyncNetworkChannel* sync_network_channel_; | 244 SyncNetworkChannel* sync_network_channel_; |
| 246 }; | 245 }; |
| 247 | 246 |
| 248 } // namespace syncer | 247 } // namespace syncer |
| 249 | 248 |
| 250 #endif // COMPONENTS_INVALIDATION_SYNC_SYSTEM_RESOURCES_H_ | 249 #endif // COMPONENTS_INVALIDATION_SYNC_SYSTEM_RESOURCES_H_ |
| OLD | NEW |