Don't preload rarely seen large images
[chromium-blink-merge.git] / components / copresence / copresence_manager_impl.h
blob0fc32807e5569798cef2a4952e9fe581dd9d8c23
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_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_
6 #define COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_
8 #include <google/protobuf/repeated_field.h>
10 #include <string>
11 #include <vector>
13 #include "base/cancelable_callback.h"
14 #include "base/macros.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "components/copresence/copresence_state_impl.h"
17 #include "components/copresence/public/copresence_manager.h"
18 #include "components/copresence/timed_map.h"
20 namespace audio_modem {
21 struct AudioToken;
24 namespace base {
25 class Timer;
28 namespace net {
29 class URLContextGetter;
32 namespace copresence {
34 class DirectiveHandler;
35 class GCMHandler;
36 class ReportRequest;
37 class RpcHandler;
38 class SubscribedMessage;
40 // The implementation for CopresenceManager. Responsible primarily for
41 // client-side initialization. The RpcHandler handles all the details
42 // of interacting with the server.
43 // TODO(ckehoe, rkc): Add tests for this class.
44 class CopresenceManagerImpl : public CopresenceManager {
45 public:
46 // The delegate is owned by the caller, and must outlive the manager.
47 explicit CopresenceManagerImpl(CopresenceDelegate* delegate);
49 ~CopresenceManagerImpl() override;
51 // CopresenceManager overrides.
52 CopresenceState* state() override;
53 void ExecuteReportRequest(const ReportRequest& request,
54 const std::string& app_id,
55 const std::string& auth_token,
56 const StatusCallback& callback) override;
58 private:
59 // Complete initialization when Whispernet is available.
60 void WhispernetInitComplete(bool success);
62 // Handle tokens decoded by Whispernet.
63 // TODO(ckehoe): Replace AudioToken with ReceivedToken.
64 void ReceivedTokens(const std::vector<audio_modem::AudioToken>& tokens);
66 // Verifies that we can hear the audio we're playing.
67 // This gets called every kAudioCheckIntervalMs milliseconds.
68 void AudioCheck();
70 // This gets called every kPollTimerIntervalMs milliseconds
71 // to poll the server for new messages.
72 void PollForMessages();
74 // Send SubscribedMessages to the appropriate clients.
75 void DispatchMessages(
76 const google::protobuf::RepeatedPtrField<SubscribedMessage>&
77 subscribed_messages);
79 // Belongs to the caller.
80 CopresenceDelegate* const delegate_;
82 // We use a CancelableCallback here because Whispernet
83 // does not provide a way to unregister its init callback.
84 base::CancelableCallback<void(bool)> whispernet_init_callback_;
86 bool init_failed_;
88 // The RpcHandler makes calls to the other objects here, so it must come last.
89 scoped_ptr<CopresenceStateImpl> state_;
90 scoped_ptr<DirectiveHandler> directive_handler_;
91 scoped_ptr<GCMHandler> gcm_handler_;
92 scoped_ptr<RpcHandler> rpc_handler_;
94 scoped_ptr<base::Timer> poll_timer_;
95 scoped_ptr<base::Timer> audio_check_timer_;
97 TimedMap<std::string, google::protobuf::RepeatedPtrField<SubscribedMessage>>
98 queued_messages_by_token_;
100 DISALLOW_COPY_AND_ASSIGN(CopresenceManagerImpl);
103 } // namespace copresence
105 #endif // COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_