| 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_CHROME_SYSTEM_RESOURCES_H_ |
| 10 #define SYNC_NOTIFIER_CHROME_SYSTEM_RESOURCES_H_ | 10 #define SYNC_NOTIFIER_CHROME_SYSTEM_RESOURCES_H_ |
| 11 #pragma once | 11 #pragma once |
| 12 | 12 |
| 13 #include <set> | 13 #include <set> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 20 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
| 21 #include "base/threading/non_thread_safe.h" | 21 #include "base/threading/non_thread_safe.h" |
| 22 #include "google/cacheinvalidation/include/system-resources.h" | 22 #include "google/cacheinvalidation/include/system-resources.h" |
| 23 #include "sync/notifier/push_client_channel.h" |
| 23 #include "sync/notifier/state_writer.h" | 24 #include "sync/notifier/state_writer.h" |
| 24 | 25 |
| 26 namespace notifier { |
| 27 class PushClient; |
| 28 } // namespace notifier |
| 29 |
| 25 namespace sync_notifier { | 30 namespace sync_notifier { |
| 26 | 31 |
| 27 class CacheInvalidationPacketHandler; | |
| 28 | |
| 29 class ChromeLogger : public invalidation::Logger { | 32 class ChromeLogger : public invalidation::Logger { |
| 30 public: | 33 public: |
| 31 ChromeLogger(); | 34 ChromeLogger(); |
| 32 | 35 |
| 33 virtual ~ChromeLogger(); | 36 virtual ~ChromeLogger(); |
| 34 | 37 |
| 35 // invalidation::Logger implementation. | 38 // invalidation::Logger implementation. |
| 36 virtual void Log(LogLevel level, const char* file, int line, | 39 virtual void Log(LogLevel level, const char* file, int line, |
| 37 const char* format, ...) OVERRIDE; | 40 const char* format, ...) OVERRIDE; |
| 38 | 41 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 110 |
| 108 // Runs the given callback with the given value and deletes it. | 111 // Runs the given callback with the given value and deletes it. |
| 109 void RunAndDeleteReadKeyCallback( | 112 void RunAndDeleteReadKeyCallback( |
| 110 invalidation::ReadKeyCallback* callback, const std::string& value); | 113 invalidation::ReadKeyCallback* callback, const std::string& value); |
| 111 | 114 |
| 112 StateWriter* state_writer_; | 115 StateWriter* state_writer_; |
| 113 invalidation::Scheduler* scheduler_; | 116 invalidation::Scheduler* scheduler_; |
| 114 std::string cached_state_; | 117 std::string cached_state_; |
| 115 }; | 118 }; |
| 116 | 119 |
| 117 class ChromeNetwork : public invalidation::NetworkChannel { | |
| 118 public: | |
| 119 ChromeNetwork(); | |
| 120 | |
| 121 virtual ~ChromeNetwork(); | |
| 122 | |
| 123 void UpdatePacketHandler(CacheInvalidationPacketHandler* packet_handler); | |
| 124 | |
| 125 // invalidation::NetworkChannel implementation. | |
| 126 virtual void SendMessage(const std::string& outgoing_message) OVERRIDE; | |
| 127 | |
| 128 virtual void SetMessageReceiver( | |
| 129 invalidation::MessageCallback* incoming_receiver) OVERRIDE; | |
| 130 | |
| 131 virtual void AddNetworkStatusReceiver( | |
| 132 invalidation::NetworkStatusCallback* network_status_receiver) OVERRIDE; | |
| 133 | |
| 134 virtual void SetSystemResources( | |
| 135 invalidation::SystemResources* resources) OVERRIDE; | |
| 136 | |
| 137 private: | |
| 138 void HandleInboundMessage(const std::string& incoming_message); | |
| 139 | |
| 140 CacheInvalidationPacketHandler* packet_handler_; | |
| 141 scoped_ptr<invalidation::MessageCallback> incoming_receiver_; | |
| 142 std::vector<invalidation::NetworkStatusCallback*> network_status_receivers_; | |
| 143 base::WeakPtrFactory<ChromeNetwork> weak_factory_; | |
| 144 }; | |
| 145 | |
| 146 class ChromeSystemResources : public invalidation::SystemResources { | 120 class ChromeSystemResources : public invalidation::SystemResources { |
| 147 public: | 121 public: |
| 148 explicit ChromeSystemResources(StateWriter* state_writer); | 122 ChromeSystemResources(scoped_ptr<notifier::PushClient> push_client, |
| 123 StateWriter* state_writer); |
| 149 | 124 |
| 150 virtual ~ChromeSystemResources(); | 125 virtual ~ChromeSystemResources(); |
| 151 | 126 |
| 152 // invalidation::SystemResources implementation. | 127 // invalidation::SystemResources implementation. |
| 153 virtual void Start() OVERRIDE; | 128 virtual void Start() OVERRIDE; |
| 154 virtual void Stop() OVERRIDE; | 129 virtual void Stop() OVERRIDE; |
| 155 virtual bool IsStarted() const OVERRIDE; | 130 virtual bool IsStarted() const OVERRIDE; |
| 156 virtual void set_platform(const std::string& platform); | 131 virtual void set_platform(const std::string& platform); |
| 157 virtual std::string platform() const OVERRIDE; | 132 virtual std::string platform() const OVERRIDE; |
| 158 virtual ChromeLogger* logger() OVERRIDE; | 133 virtual ChromeLogger* logger() OVERRIDE; |
| 159 virtual ChromeStorage* storage() OVERRIDE; | 134 virtual ChromeStorage* storage() OVERRIDE; |
| 160 virtual ChromeNetwork* network() OVERRIDE; | 135 virtual PushClientChannel* network() OVERRIDE; |
| 161 virtual ChromeScheduler* internal_scheduler() OVERRIDE; | 136 virtual ChromeScheduler* internal_scheduler() OVERRIDE; |
| 162 virtual ChromeScheduler* listener_scheduler() OVERRIDE; | 137 virtual ChromeScheduler* listener_scheduler() OVERRIDE; |
| 163 | 138 |
| 164 private: | 139 private: |
| 165 bool is_started_; | 140 bool is_started_; |
| 166 std::string platform_; | 141 std::string platform_; |
| 167 scoped_ptr<ChromeLogger> logger_; | 142 scoped_ptr<ChromeLogger> logger_; |
| 168 scoped_ptr<ChromeScheduler> internal_scheduler_; | 143 scoped_ptr<ChromeScheduler> internal_scheduler_; |
| 169 scoped_ptr<ChromeScheduler> listener_scheduler_; | 144 scoped_ptr<ChromeScheduler> listener_scheduler_; |
| 170 scoped_ptr<ChromeStorage> storage_; | 145 scoped_ptr<ChromeStorage> storage_; |
| 171 scoped_ptr<ChromeNetwork> network_; | 146 PushClientChannel push_client_channel_; |
| 172 }; | 147 }; |
| 173 | 148 |
| 174 } // namespace sync_notifier | 149 } // namespace sync_notifier |
| 175 | 150 |
| 176 #endif // SYNC_NOTIFIER_CHROME_SYSTEM_RESOURCES_H_ | 151 #endif // SYNC_NOTIFIER_CHROME_SYSTEM_RESOURCES_H_ |
| OLD | NEW |