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

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: Fixing tests 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
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 <map>
8 #include <string> 9 #include <string>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/cancelable_callback.h" 12 #include "base/cancelable_callback.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "components/copresence/copresence_state_impl.h" 15 #include "components/copresence/copresence_state_impl.h"
15 #include "components/copresence/public/copresence_manager.h" 16 #include "components/copresence/public/copresence_manager.h"
16 17
17 namespace base { 18 namespace base {
18 class Timer; 19 class Timer;
19 } 20 }
20 21
21 namespace net { 22 namespace net {
22 class URLContextGetter; 23 class URLContextGetter;
23 } 24 }
24 25
25 namespace copresence { 26 namespace copresence {
26 27
27 class DirectiveHandler; 28 class DirectiveHandler;
28 class GCMHandler; 29 class GCMHandler;
29 class ReportRequest; 30 class ReportRequest;
30 class RpcHandler; 31 class RpcHandler;
32 class SubscribedMessage;
31 class WhispernetClient; 33 class WhispernetClient;
32 34
33 // The implementation for CopresenceManager. Responsible primarily for 35 // The implementation for CopresenceManager. Responsible primarily for
34 // client-side initialization. The RpcHandler handles all the details 36 // client-side initialization. The RpcHandler handles all the details
35 // of interacting with the server. 37 // of interacting with the server.
36 // TODO(rkc): Add tests for this class. 38 // TODO(rkc): Add tests for this class.
37 class CopresenceManagerImpl : public CopresenceManager { 39 class CopresenceManagerImpl : public CopresenceManager {
38 public: 40 public:
39 // The delegate is owned by the caller, and must outlive the manager. 41 // The delegate is owned by the caller, and must outlive the manager.
40 explicit CopresenceManagerImpl(CopresenceDelegate* delegate); 42 explicit CopresenceManagerImpl(CopresenceDelegate* delegate);
41 43
42 ~CopresenceManagerImpl() override; 44 ~CopresenceManagerImpl() override;
43 45
44 // CopresenceManager overrides. 46 // CopresenceManager overrides.
45 CopresenceState* state() override; 47 CopresenceState* state() override;
46 void ExecuteReportRequest(const ReportRequest& request, 48 void ExecuteReportRequest(const ReportRequest& request,
47 const std::string& app_id, 49 const std::string& app_id,
48 const std::string& auth_token, 50 const std::string& auth_token,
49 const StatusCallback& callback) override; 51 const StatusCallback& callback) override;
50 52
51 private: 53 private:
54 // Complete initialization when Whispernet is available.
52 void WhispernetInitComplete(bool success); 55 void WhispernetInitComplete(bool success);
53 56
54 // Handle tokens decoded by Whispernet. 57 // Handle tokens decoded by Whispernet.
55 // TODO(ckehoe): Replace AudioToken with ReceivedToken. 58 // TODO(ckehoe): Replace AudioToken with ReceivedToken.
56 void ReceivedTokens(const std::vector<AudioToken>& tokens); 59 void ReceivedTokens(const std::vector<AudioToken>& tokens);
57 60
58 // This function will be called every kPollTimerIntervalMs milliseconds 61 // Verifies that we can hear the audio we're playing.
62 // This gets called every kAudioCheckIntervalMs milliseconds.
63 void AudioCheck();
64
65 // This gets called every kPollTimerIntervalMs milliseconds
59 // to poll the server for new messages. 66 // to poll the server for new messages.
60 void PollForMessages(); 67 void PollForMessages();
61 68
62 // Verify that we can hear the audio we're playing 69 // Send SubscribedMessages to the appropriate clients. Can be called with
63 // every kAudioCheckIntervalMs milliseconds. 70 // a vector or anything that behaves like one, e.g. RepeatedPtrField.
64 void AudioCheck(); 71 template<typename IterableSubscribedMessages>
rkc 2015/01/07 21:31:43 Since we use a std::vector only in our own map, ca
Charlie 2015/01/07 22:06:07 Yes, but that's kind of hacky. This kind of templa
rkc 2015/01/07 23:06:10 Sure but we don't actually need this to be an iter
Charlie 2015/01/08 16:47:33 1. I don't think RepeatedPtrField is really intend
72 void DispatchMessages(const IterableSubscribedMessages& subscribed_messages);
65 73
66 // Belongs to the caller. 74 // Belongs to the caller.
67 CopresenceDelegate* const delegate_; 75 CopresenceDelegate* const delegate_;
68 76
69 // We use a CancelableCallback here because Whispernet 77 // We use a CancelableCallback here because Whispernet
70 // does not provide a way to unregister its init callback. 78 // does not provide a way to unregister its init callback.
71 base::CancelableCallback<void(bool)> whispernet_init_callback_; 79 base::CancelableCallback<void(bool)> whispernet_init_callback_;
72 80
73 bool init_failed_; 81 bool init_failed_;
74 82
75 // This order is required because each object 83 // This order is required because each object
76 // makes calls to those listed before it. 84 // makes calls to those listed before it.
77 scoped_ptr<CopresenceStateImpl> state_; 85 scoped_ptr<CopresenceStateImpl> state_;
78 scoped_ptr<RpcHandler> rpc_handler_; 86 scoped_ptr<RpcHandler> rpc_handler_;
79 scoped_ptr<DirectiveHandler> directive_handler_; 87 scoped_ptr<DirectiveHandler> directive_handler_;
80 scoped_ptr<GCMHandler> gcm_handler_; 88 scoped_ptr<GCMHandler> gcm_handler_;
81 89
82 scoped_ptr<base::Timer> poll_timer_; 90 scoped_ptr<base::Timer> poll_timer_;
83 scoped_ptr<base::Timer> audio_check_timer_; 91 scoped_ptr<base::Timer> audio_check_timer_;
84 92
93 // TODO(ckehoe): Expire queued messages after a certain time
94 // (e.g. 10 minutes),or limit how many we store.
95 std::map<std::string, std::vector<SubscribedMessage>>
rkc 2015/01/07 21:31:43 Why not use TimedMap?
Charlie 2015/01/07 22:06:07 It doesn't have quite the same functionality. map:
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') | components/copresence/copresence_manager_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698