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

Unified Diff: remoting/protocol/protocol_mock_objects.cc

Issue 19714002: Add serialization to PairingRegistry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: remoting/protocol/protocol_mock_objects.cc
diff --git a/remoting/protocol/protocol_mock_objects.cc b/remoting/protocol/protocol_mock_objects.cc
index f558769cc919d8e819872171ba6b233e70e3c1df..233a8d2316dfcc567a89d0c84fc2f39d3536cbb7 100644
--- a/remoting/protocol/protocol_mock_objects.cc
+++ b/remoting/protocol/protocol_mock_objects.cc
@@ -48,7 +48,8 @@ MockSessionManager::MockSessionManager() {}
MockSessionManager::~MockSessionManager() {}
-MockPairingRegistryDelegate::MockPairingRegistryDelegate() {
+MockPairingRegistryDelegate::MockPairingRegistryDelegate()
+ : run_save_callback_automatically_(true) {
}
MockPairingRegistryDelegate::~MockPairingRegistryDelegate() {
@@ -57,6 +58,20 @@ MockPairingRegistryDelegate::~MockPairingRegistryDelegate() {
void MockPairingRegistryDelegate::Save(
const std::string& pairings_json,
const PairingRegistry::SaveCallback& callback) {
+ DCHECK(load_callback_.is_null());
Lambros 2013/07/18 20:34:51 Use ASSERT_TRUE here and elsewhere instead of DCHE
Jamie 2013/07/18 22:44:56 Done.
+ DCHECK(save_callback_.is_null());
+ if (run_save_callback_automatically_) {
+ SetPairingsJsonAndRunCallback(pairings_json, callback);
+ } else {
+ save_callback_ = base::Bind(
+ &MockPairingRegistryDelegate::SetPairingsJsonAndRunCallback,
+ base::Unretained(this), pairings_json, callback);
+ }
+}
+
+void MockPairingRegistryDelegate::SetPairingsJsonAndRunCallback(
+ const std::string& pairings_json,
+ const PairingRegistry::SaveCallback& callback) {
pairings_json_ = pairings_json;
if (!callback.is_null()) {
callback.Run(true);
@@ -65,13 +80,22 @@ void MockPairingRegistryDelegate::Save(
void MockPairingRegistryDelegate::Load(
const PairingRegistry::LoadCallback& callback) {
+ DCHECK(load_callback_.is_null());
+ DCHECK(save_callback_.is_null());
load_callback_ = base::Bind(base::Bind(callback), pairings_json_);
Lambros 2013/07/18 20:34:51 optional: Remove inner base::Bind ?
}
void MockPairingRegistryDelegate::RunCallback() {
- DCHECK(!load_callback_.is_null());
- load_callback_.Run();
- load_callback_.Reset();
+ DCHECK(load_callback_.is_null() ^ save_callback_.is_null());
Lambros 2013/07/18 20:34:51 Split this up, otherwise the test output won't tel
Jamie 2013/07/18 22:44:56 Done.
+ if (!load_callback_.is_null()) {
+ base::Closure load_callback = load_callback_;
+ load_callback_.Reset();
+ load_callback.Run();
+ } else {
+ base::Closure save_callback = save_callback_;
+ save_callback_.Reset();
+ save_callback.Run();
+ }
}
} // namespace protocol
« remoting/protocol/protocol_mock_objects.h ('K') | « remoting/protocol/protocol_mock_objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698