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

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: Reviewer feedback. 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
« no previous file with comments | « remoting/protocol/protocol_mock_objects.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..efde603d18e14f3e85caf5f6ea3593a537362e1c 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) {
+ EXPECT_TRUE(load_callback_.is_null());
+ EXPECT_TRUE(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,25 @@ void MockPairingRegistryDelegate::Save(
void MockPairingRegistryDelegate::Load(
const PairingRegistry::LoadCallback& callback) {
- load_callback_ = base::Bind(base::Bind(callback), pairings_json_);
+ EXPECT_TRUE(load_callback_.is_null());
+ EXPECT_TRUE(save_callback_.is_null());
+ load_callback_ = base::Bind(callback, pairings_json_);
}
void MockPairingRegistryDelegate::RunCallback() {
- DCHECK(!load_callback_.is_null());
- load_callback_.Run();
- load_callback_.Reset();
+ if (!load_callback_.is_null()) {
+ EXPECT_TRUE(save_callback_.is_null());
+ base::Closure load_callback = load_callback_;
+ load_callback_.Reset();
+ load_callback.Run();
+ } else if (!save_callback_.is_null()) {
+ EXPECT_TRUE(load_callback_.is_null());
+ base::Closure save_callback = save_callback_;
+ save_callback_.Reset();
+ save_callback.Run();
+ } else {
+ ADD_FAILURE() << "RunCallback called without any callbacks set.";
+ }
}
} // namespace protocol
« no previous file with comments | « remoting/protocol/protocol_mock_objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698