| 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> |
| 10 |
| 9 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 10 #include "base/strings/stringize_macros.h" | 12 #include "base/strings/stringize_macros.h" |
| 11 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 12 #include "base/values.h" | 14 #include "base/values.h" |
| 13 #include "remoting/base/constants.h" | 15 #include "remoting/base/constants.h" |
| 14 #include "remoting/base/logging.h" | 16 #include "remoting/base/logging.h" |
| 15 | 17 |
| 16 namespace remoting { | 18 namespace remoting { |
| 17 | 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 const int64_t kTimerIntervalMinMs = 1000; | 22 const int64_t kTimerIntervalMinMs = 1000; |
| 21 const int64_t kTimerIntervalMaxMs = 5 * 60 * 1000; // 5 minutes | 23 const int64_t kTimerIntervalMaxMs = 5 * 60 * 1000; // 5 minutes |
| 22 | 24 |
| 23 } // namespace | 25 } // namespace |
| 24 | 26 |
| 25 GcdStateUpdater::GcdStateUpdater( | 27 GcdStateUpdater::GcdStateUpdater( |
| 26 const base::Closure& on_update_successful_callback, | 28 const base::Closure& on_update_successful_callback, |
| 27 const base::Closure& on_unknown_host_id_error, | 29 const base::Closure& on_unknown_host_id_error, |
| 28 SignalStrategy* signal_strategy, | 30 SignalStrategy* signal_strategy, |
| 29 scoped_ptr<GcdRestClient> gcd_rest_client) | 31 scoped_ptr<GcdRestClient> gcd_rest_client) |
| 30 : on_update_successful_callback_(on_update_successful_callback), | 32 : on_update_successful_callback_(on_update_successful_callback), |
| 31 on_unknown_host_id_error_(on_unknown_host_id_error), | 33 on_unknown_host_id_error_(on_unknown_host_id_error), |
| 32 signal_strategy_(signal_strategy), | 34 signal_strategy_(signal_strategy), |
| 33 gcd_rest_client_(gcd_rest_client.Pass()) { | 35 gcd_rest_client_(std::move(gcd_rest_client)) { |
| 34 DCHECK(signal_strategy_); | 36 DCHECK(signal_strategy_); |
| 35 DCHECK(thread_checker_.CalledOnValidThread()); | 37 DCHECK(thread_checker_.CalledOnValidThread()); |
| 36 | 38 |
| 37 signal_strategy_->AddListener(this); | 39 signal_strategy_->AddListener(this); |
| 38 | 40 |
| 39 // Update state if the |signal_strategy_| is already connected. | 41 // Update state if the |signal_strategy_| is already connected. |
| 40 OnSignalStrategyStateChange(signal_strategy_->GetState()); | 42 OnSignalStrategyStateChange(signal_strategy_->GetState()); |
| 41 } | 43 } |
| 42 | 44 |
| 43 GcdStateUpdater::~GcdStateUpdater() { | 45 GcdStateUpdater::~GcdStateUpdater() { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 if (gcd_rest_client_->HasPendingRequest()) { | 111 if (gcd_rest_client_->HasPendingRequest()) { |
| 110 return; | 112 return; |
| 111 } | 113 } |
| 112 | 114 |
| 113 // Construct an update to the remote state. | 115 // Construct an update to the remote state. |
| 114 scoped_ptr<base::DictionaryValue> patch(new base::DictionaryValue); | 116 scoped_ptr<base::DictionaryValue> patch(new base::DictionaryValue); |
| 115 scoped_ptr<base::DictionaryValue> base_state(new base::DictionaryValue); | 117 scoped_ptr<base::DictionaryValue> base_state(new base::DictionaryValue); |
| 116 pending_request_jid_ = signal_strategy_->GetLocalJid(); | 118 pending_request_jid_ = signal_strategy_->GetLocalJid(); |
| 117 base_state->SetString("_jabberId", pending_request_jid_); | 119 base_state->SetString("_jabberId", pending_request_jid_); |
| 118 base_state->SetString("_hostVersion", STRINGIZE(VERSION)); | 120 base_state->SetString("_hostVersion", STRINGIZE(VERSION)); |
| 119 patch->Set("base", base_state.Pass()); | 121 patch->Set("base", std::move(base_state)); |
| 120 | 122 |
| 121 // Send the update to GCD. | 123 // Send the update to GCD. |
| 122 gcd_rest_client_->PatchState( | 124 gcd_rest_client_->PatchState( |
| 123 patch.Pass(), | 125 std::move(patch), |
| 124 base::Bind(&GcdStateUpdater::OnPatchStateResult, base::Unretained(this))); | 126 base::Bind(&GcdStateUpdater::OnPatchStateResult, base::Unretained(this))); |
| 125 } | 127 } |
| 126 | 128 |
| 127 } // namespace remoting | 129 } // namespace remoting |
| OLD | NEW |