Don't preload rarely seen large images
[chromium-blink-merge.git] / components / invalidation / impl / push_client_channel.h
blob85a2fd3c16c668269de78f1e2c4354714ec32a06
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_INVALIDATION_IMPL_PUSH_CLIENT_CHANNEL_H_
6 #define COMPONENTS_INVALIDATION_IMPL_PUSH_CLIENT_CHANNEL_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "components/invalidation/impl/sync_system_resources.h"
14 #include "components/invalidation/public/invalidation_export.h"
15 #include "jingle/notifier/listener/push_client_observer.h"
17 namespace notifier {
18 class PushClient;
19 } // namespace notifier
21 namespace syncer {
23 // A PushClientChannel is an implementation of NetworkChannel that
24 // routes messages through a PushClient.
25 class INVALIDATION_EXPORT_PRIVATE PushClientChannel
26 : public SyncNetworkChannel,
27 public NON_EXPORTED_BASE(notifier::PushClientObserver) {
28 public:
29 // |push_client| is guaranteed to be destroyed only when this object
30 // is destroyed.
31 explicit PushClientChannel(scoped_ptr<notifier::PushClient> push_client);
33 ~PushClientChannel() override;
35 // invalidation::NetworkChannel implementation.
36 void SendMessage(const std::string& message) override;
37 void RequestDetailedStatus(
38 base::Callback<void(const base::DictionaryValue&)> callback) override;
40 // SyncNetworkChannel implementation.
41 // If not connected, connects with the given credentials. If
42 // already connected, the next connection attempt will use the given
43 // credentials.
44 void UpdateCredentials(const std::string& email,
45 const std::string& token) override;
46 int GetInvalidationClientType() override;
48 // notifier::PushClient::Observer implementation.
49 void OnNotificationsEnabled() override;
50 void OnNotificationsDisabled(
51 notifier::NotificationsDisabledReason reason) override;
52 void OnIncomingNotification(
53 const notifier::Notification& notification) override;
55 const std::string& GetServiceContextForTest() const;
57 int64 GetSchedulingHashForTest() const;
59 static std::string EncodeMessageForTest(const std::string& message,
60 const std::string& service_context,
61 int64 scheduling_hash);
63 static bool DecodeMessageForTest(const std::string& notification,
64 std::string* message,
65 std::string* service_context,
66 int64* scheduling_hash);
68 private:
69 static void EncodeMessage(std::string* encoded_message,
70 const std::string& message,
71 const std::string& service_context,
72 int64 scheduling_hash);
73 static bool DecodeMessage(const std::string& data,
74 std::string* message,
75 std::string* service_context,
76 int64* scheduling_hash);
77 scoped_ptr<base::DictionaryValue> CollectDebugData() const;
79 scoped_ptr<notifier::PushClient> push_client_;
80 std::string service_context_;
81 int64 scheduling_hash_;
83 // This count is saved for displaying statatistics.
84 int sent_messages_count_;
86 DISALLOW_COPY_AND_ASSIGN(PushClientChannel);
89 } // namespace syncer
91 #endif // COMPONENTS_INVALIDATION_IMPL_PUSH_CLIENT_CHANNEL_H_