OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "remoting/host/gcd_state_updater.h" | 5 #include "remoting/host/gcd_state_updater.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
12 #include "base/strings/stringize_macros.h" | 12 #include "base/strings/stringize_macros.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "remoting/base/constants.h" | 15 #include "remoting/base/constants.h" |
16 #include "remoting/base/logging.h" | 16 #include "remoting/base/logging.h" |
| 17 #include "remoting/signaling/signaling_address.h" |
17 | 18 |
18 namespace remoting { | 19 namespace remoting { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 const int64_t kTimerIntervalMinMs = 1000; | 23 const int64_t kTimerIntervalMinMs = 1000; |
23 const int64_t kTimerIntervalMaxMs = 5 * 60 * 1000; // 5 minutes | 24 const int64_t kTimerIntervalMaxMs = 5 * 60 * 1000; // 5 minutes |
24 | 25 |
25 } // namespace | 26 } // namespace |
26 | 27 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // Ignore all XMPP stanzas. | 73 // Ignore all XMPP stanzas. |
73 return false; | 74 return false; |
74 } | 75 } |
75 | 76 |
76 void GcdStateUpdater::OnPatchStateResult(GcdRestClient::Result result) { | 77 void GcdStateUpdater::OnPatchStateResult(GcdRestClient::Result result) { |
77 if (!timer_.IsRunning()) { | 78 if (!timer_.IsRunning()) { |
78 return; | 79 return; |
79 } | 80 } |
80 | 81 |
81 if (result == GcdRestClient::NETWORK_ERROR || | 82 if (result == GcdRestClient::NETWORK_ERROR || |
82 pending_request_jid_ != signal_strategy_->GetLocalJid()) { | 83 pending_request_jid_ != signal_strategy_->GetLocalAddress().jid()) { |
83 // Continue exponential backoff. | 84 // Continue exponential backoff. |
84 return; | 85 return; |
85 } | 86 } |
86 | 87 |
87 timer_.Stop(); | 88 timer_.Stop(); |
88 if (result == GcdRestClient::SUCCESS) { | 89 if (result == GcdRestClient::SUCCESS) { |
89 if (!on_update_successful_callback_.is_null()) { | 90 if (!on_update_successful_callback_.is_null()) { |
90 on_unknown_host_id_error_.Reset(); | 91 on_unknown_host_id_error_.Reset(); |
91 base::ResetAndReturn(&on_update_successful_callback_).Run(); | 92 base::ResetAndReturn(&on_update_successful_callback_).Run(); |
92 } | 93 } |
(...skipping 15 matching lines...) Expand all Loading... |
108 // This avoids having multiple outstanding requests, which would be | 109 // This avoids having multiple outstanding requests, which would be |
109 // a problem since there's no guarantee that the reqests will | 110 // a problem since there's no guarantee that the reqests will |
110 // complete in order. | 111 // complete in order. |
111 if (gcd_rest_client_->HasPendingRequest()) { | 112 if (gcd_rest_client_->HasPendingRequest()) { |
112 return; | 113 return; |
113 } | 114 } |
114 | 115 |
115 // Construct an update to the remote state. | 116 // Construct an update to the remote state. |
116 std::unique_ptr<base::DictionaryValue> patch(new base::DictionaryValue); | 117 std::unique_ptr<base::DictionaryValue> patch(new base::DictionaryValue); |
117 std::unique_ptr<base::DictionaryValue> base_state(new base::DictionaryValue); | 118 std::unique_ptr<base::DictionaryValue> base_state(new base::DictionaryValue); |
118 pending_request_jid_ = signal_strategy_->GetLocalJid(); | 119 pending_request_jid_ = signal_strategy_->GetLocalAddress().jid(); |
119 base_state->SetString("_jabberId", pending_request_jid_); | 120 base_state->SetString("_jabberId", pending_request_jid_); |
120 base_state->SetString("_hostVersion", STRINGIZE(VERSION)); | 121 base_state->SetString("_hostVersion", STRINGIZE(VERSION)); |
121 patch->Set("base", std::move(base_state)); | 122 patch->Set("base", std::move(base_state)); |
122 | 123 |
123 // Send the update to GCD. | 124 // Send the update to GCD. |
124 gcd_rest_client_->PatchState( | 125 gcd_rest_client_->PatchState( |
125 std::move(patch), | 126 std::move(patch), |
126 base::Bind(&GcdStateUpdater::OnPatchStateResult, base::Unretained(this))); | 127 base::Bind(&GcdStateUpdater::OnPatchStateResult, base::Unretained(this))); |
127 } | 128 } |
128 | 129 |
129 } // namespace remoting | 130 } // namespace remoting |
OLD | NEW |