Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: components/copresence/copresence_manager_impl.h

Issue 813553002: Adding support for pre-sent messages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@state
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/copresence/copresence_manager_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_ 5 #ifndef COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_
6 #define COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_ 6 #define COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_
7 7
8 #include <google/protobuf/repeated_field.h>
9
8 #include <string> 10 #include <string>
9 #include <vector> 11 #include <vector>
10 12
11 #include "base/cancelable_callback.h" 13 #include "base/cancelable_callback.h"
12 #include "base/macros.h" 14 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
14 #include "components/copresence/copresence_state_impl.h" 16 #include "components/copresence/copresence_state_impl.h"
15 #include "components/copresence/public/copresence_manager.h" 17 #include "components/copresence/public/copresence_manager.h"
18 #include "components/copresence/timed_map.h"
16 19
17 namespace base { 20 namespace base {
18 class Timer; 21 class Timer;
19 } 22 }
20 23
21 namespace net { 24 namespace net {
22 class URLContextGetter; 25 class URLContextGetter;
23 } 26 }
24 27
25 namespace copresence { 28 namespace copresence {
26 29
27 class DirectiveHandler; 30 class DirectiveHandler;
28 class GCMHandler; 31 class GCMHandler;
29 class ReportRequest; 32 class ReportRequest;
30 class RpcHandler; 33 class RpcHandler;
34 class SubscribedMessage;
31 class WhispernetClient; 35 class WhispernetClient;
32 36
33 // The implementation for CopresenceManager. Responsible primarily for 37 // The implementation for CopresenceManager. Responsible primarily for
34 // client-side initialization. The RpcHandler handles all the details 38 // client-side initialization. The RpcHandler handles all the details
35 // of interacting with the server. 39 // of interacting with the server.
36 // TODO(rkc): Add tests for this class. 40 // TODO(ckehoe, rkc): Add tests for this class.
37 class CopresenceManagerImpl : public CopresenceManager { 41 class CopresenceManagerImpl : public CopresenceManager {
38 public: 42 public:
39 // The delegate is owned by the caller, and must outlive the manager. 43 // The delegate is owned by the caller, and must outlive the manager.
40 explicit CopresenceManagerImpl(CopresenceDelegate* delegate); 44 explicit CopresenceManagerImpl(CopresenceDelegate* delegate);
41 45
42 ~CopresenceManagerImpl() override; 46 ~CopresenceManagerImpl() override;
43 47
44 // CopresenceManager overrides. 48 // CopresenceManager overrides.
45 CopresenceState* state() override; 49 CopresenceState* state() override;
46 void ExecuteReportRequest(const ReportRequest& request, 50 void ExecuteReportRequest(const ReportRequest& request,
47 const std::string& app_id, 51 const std::string& app_id,
48 const std::string& auth_token, 52 const std::string& auth_token,
49 const StatusCallback& callback) override; 53 const StatusCallback& callback) override;
50 54
51 private: 55 private:
56 // Complete initialization when Whispernet is available.
52 void WhispernetInitComplete(bool success); 57 void WhispernetInitComplete(bool success);
53 58
54 // Handle tokens decoded by Whispernet. 59 // Handle tokens decoded by Whispernet.
55 // TODO(ckehoe): Replace AudioToken with ReceivedToken. 60 // TODO(ckehoe): Replace AudioToken with ReceivedToken.
56 void ReceivedTokens(const std::vector<AudioToken>& tokens); 61 void ReceivedTokens(const std::vector<AudioToken>& tokens);
57 62
58 // This function will be called every kPollTimerIntervalMs milliseconds 63 // Verifies that we can hear the audio we're playing.
64 // This gets called every kAudioCheckIntervalMs milliseconds.
65 void AudioCheck();
66
67 // This gets called every kPollTimerIntervalMs milliseconds
59 // to poll the server for new messages. 68 // to poll the server for new messages.
60 void PollForMessages(); 69 void PollForMessages();
61 70
62 // Verify that we can hear the audio we're playing 71 // Send SubscribedMessages to the appropriate clients.
63 // every kAudioCheckIntervalMs milliseconds. 72 void DispatchMessages(
64 void AudioCheck(); 73 const google::protobuf::RepeatedPtrField<SubscribedMessage>&
74 subscribed_messages);
65 75
66 // Belongs to the caller. 76 // Belongs to the caller.
67 CopresenceDelegate* const delegate_; 77 CopresenceDelegate* const delegate_;
68 78
69 // We use a CancelableCallback here because Whispernet 79 // We use a CancelableCallback here because Whispernet
70 // does not provide a way to unregister its init callback. 80 // does not provide a way to unregister its init callback.
71 base::CancelableCallback<void(bool)> whispernet_init_callback_; 81 base::CancelableCallback<void(bool)> whispernet_init_callback_;
72 82
73 bool init_failed_; 83 bool init_failed_;
74 84
75 // This order is required because each object 85 // This order is required because each object
76 // makes calls to those listed before it. 86 // makes calls to those listed before it.
77 scoped_ptr<CopresenceStateImpl> state_; 87 scoped_ptr<CopresenceStateImpl> state_;
78 scoped_ptr<RpcHandler> rpc_handler_; 88 scoped_ptr<RpcHandler> rpc_handler_;
79 scoped_ptr<DirectiveHandler> directive_handler_; 89 scoped_ptr<DirectiveHandler> directive_handler_;
80 scoped_ptr<GCMHandler> gcm_handler_; 90 scoped_ptr<GCMHandler> gcm_handler_;
81 91
82 scoped_ptr<base::Timer> poll_timer_; 92 scoped_ptr<base::Timer> poll_timer_;
83 scoped_ptr<base::Timer> audio_check_timer_; 93 scoped_ptr<base::Timer> audio_check_timer_;
84 94
95 TimedMap<std::string, google::protobuf::RepeatedPtrField<SubscribedMessage>>
96 queued_messages_by_token_;
97
85 DISALLOW_COPY_AND_ASSIGN(CopresenceManagerImpl); 98 DISALLOW_COPY_AND_ASSIGN(CopresenceManagerImpl);
86 }; 99 };
87 100
88 } // namespace copresence 101 } // namespace copresence
89 102
90 #endif // COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_ 103 #endif // COMPONENTS_COPRESENCE_COPRESENCE_MANAGER_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | components/copresence/copresence_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698