| OLD | NEW |
| 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 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h" | 5 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "base/bind.h" | 7 #include "base/bind.h" |
| 10 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/stl_util.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "chromeos/dbus/session_manager_client.h" | 11 #include "chromeos/dbus/session_manager_client.h" |
| 13 | 12 |
| 14 namespace policy { | 13 namespace policy { |
| 15 | 14 |
| 16 namespace { | 15 namespace { |
| 17 | 16 |
| 18 // Refresh interval for state keys. There's a quantized time component in | 17 // Refresh interval for state keys. There's a quantized time component in |
| 19 // state key generation, so they rotate over time. The quantum size is pretty | 18 // state key generation, so they rotate over time. The quantum size is pretty |
| 20 // coarse though (currently 2^23 seconds), so simply polling for a new state | 19 // coarse though (currently 2^23 seconds), so simply polling for a new state |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 68 } |
| 70 | 69 |
| 71 void ServerBackedStateKeysBroker::StoreStateKeys( | 70 void ServerBackedStateKeysBroker::StoreStateKeys( |
| 72 const std::vector<std::string>& state_keys) { | 71 const std::vector<std::string>& state_keys) { |
| 73 bool send_notification = !initial_retrieval_completed_; | 72 bool send_notification = !initial_retrieval_completed_; |
| 74 | 73 |
| 75 requested_ = false; | 74 requested_ = false; |
| 76 initial_retrieval_completed_ = true; | 75 initial_retrieval_completed_ = true; |
| 77 if (state_keys.empty()) { | 76 if (state_keys.empty()) { |
| 78 LOG(WARNING) << "Failed to obtain server-backed state keys."; | 77 LOG(WARNING) << "Failed to obtain server-backed state keys."; |
| 79 } else if (state_keys.end() != | 78 } else if (base::ContainsValue(state_keys, std::string())) { |
| 80 std::find(state_keys.begin(), state_keys.end(), std::string())) { | |
| 81 LOG(WARNING) << "Bad state keys."; | 79 LOG(WARNING) << "Bad state keys."; |
| 82 } else { | 80 } else { |
| 83 send_notification |= state_keys_ != state_keys; | 81 send_notification |= state_keys_ != state_keys; |
| 84 state_keys_ = state_keys; | 82 state_keys_ = state_keys; |
| 85 } | 83 } |
| 86 | 84 |
| 87 if (send_notification) | 85 if (send_notification) |
| 88 update_callbacks_.Notify(); | 86 update_callbacks_.Notify(); |
| 89 | 87 |
| 90 std::vector<StateKeysCallback> callbacks; | 88 std::vector<StateKeysCallback> callbacks; |
| 91 request_callbacks_.swap(callbacks); | 89 request_callbacks_.swap(callbacks); |
| 92 for (std::vector<StateKeysCallback>::const_iterator callback( | 90 for (std::vector<StateKeysCallback>::const_iterator callback( |
| 93 callbacks.begin()); | 91 callbacks.begin()); |
| 94 callback != callbacks.end(); | 92 callback != callbacks.end(); |
| 95 ++callback) { | 93 ++callback) { |
| 96 if (!callback->is_null()) | 94 if (!callback->is_null()) |
| 97 callback->Run(state_keys_); | 95 callback->Run(state_keys_); |
| 98 } | 96 } |
| 99 | 97 |
| 100 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 98 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 101 FROM_HERE, | 99 FROM_HERE, |
| 102 base::Bind(&ServerBackedStateKeysBroker::FetchStateKeys, | 100 base::Bind(&ServerBackedStateKeysBroker::FetchStateKeys, |
| 103 weak_factory_.GetWeakPtr()), | 101 weak_factory_.GetWeakPtr()), |
| 104 kPollInterval); | 102 kPollInterval); |
| 105 } | 103 } |
| 106 | 104 |
| 107 } // namespace policy | 105 } // namespace policy |
| OLD | NEW |