tpm_manager/trunks: Update libchrome APIs to r405848 am: 39e701593e
am: d5e311423c

Change-Id: Iae06c20630942760e6ca6846d4a96557b94722b4
diff --git a/tpm_manager/server/binder_service_test.cc b/tpm_manager/server/binder_service_test.cc
index 1415019..648f924 100644
--- a/tpm_manager/server/binder_service_test.cc
+++ b/tpm_manager/server/binder_service_test.cc
@@ -55,7 +55,10 @@
   base::Callback<void(const ResponseProtobufType&)> GetCallback(
       ResponseProtobufType* proto) {
     return base::Bind(
-        [proto](const ResponseProtobufType& response) { *proto = response; });
+        [](ResponseProtobufType* proto, const ResponseProtobufType& response) {
+          *proto = response;
+        },
+        base::Unretained(proto));
   }
 
  protected:
diff --git a/tpm_manager/server/tpm_manager_service_test.cc b/tpm_manager/server/tpm_manager_service_test.cc
index cd0d0f0..f23729a 100644
--- a/tpm_manager/server/tpm_manager_service_test.cc
+++ b/tpm_manager/server/tpm_manager_service_test.cc
@@ -63,9 +63,12 @@
   void RunServiceWorkerAndQuit() {
     // Run out the service worker loop by posting a new command and waiting for
     // the response.
-    auto callback = [this](const GetTpmStatusReply& reply) { Quit(); };
+    auto callback = [](decltype(this) test, const GetTpmStatusReply& reply) {
+      test->Quit();
+    };
     GetTpmStatusRequest request;
-    service_->GetTpmStatus(request, base::Bind(callback));
+    service_->GetTpmStatus(request,
+                           base::Bind(callback, base::Unretained(this)));
     Run();
   }
 
@@ -120,12 +123,12 @@
        TakeOwnershipAfterAutoInitialize) {
   EXPECT_CALL(mock_tpm_initializer_, InitializeTpm()).Times(AtLeast(2));
   SetupService();
-  auto callback = [this](const TakeOwnershipReply& reply) {
+  auto callback = [](decltype(this) test, const TakeOwnershipReply& reply) {
     EXPECT_EQ(STATUS_SUCCESS, reply.status());
-    Quit();
+    test->Quit();
   };
   TakeOwnershipRequest request;
-  service_->TakeOwnership(request, base::Bind(callback));
+  service_->TakeOwnership(request, base::Bind(callback, base::Unretained(this)));
   Run();
 }
 
@@ -149,7 +152,7 @@
   EXPECT_CALL(mock_local_data_store_, Read(_))
       .WillRepeatedly(DoAll(SetArgPointee<0>(local_data), Return(true)));
 
-  auto callback = [this](const GetTpmStatusReply& reply) {
+  auto callback = [](decltype(this) test, const GetTpmStatusReply& reply) {
     EXPECT_EQ(STATUS_SUCCESS, reply.status());
     EXPECT_TRUE(reply.enabled());
     EXPECT_TRUE(reply.owned());
@@ -158,16 +161,16 @@
     EXPECT_EQ(6, reply.dictionary_attack_threshold());
     EXPECT_TRUE(reply.dictionary_attack_lockout_in_effect());
     EXPECT_EQ(7, reply.dictionary_attack_lockout_seconds_remaining());
-    Quit();
+    test->Quit();
   };
   GetTpmStatusRequest request;
-  service_->GetTpmStatus(request, base::Bind(callback));
+  service_->GetTpmStatus(request, base::Bind(callback, base::Unretained(this)));
   Run();
 }
 
 TEST_F(TpmManagerServiceTest, GetTpmStatusLocalDataFailure) {
   EXPECT_CALL(mock_local_data_store_, Read(_)).WillRepeatedly(Return(false));
-  auto callback = [this](const GetTpmStatusReply& reply) {
+  auto callback = [](decltype(this) test, const GetTpmStatusReply& reply) {
     EXPECT_EQ(STATUS_SUCCESS, reply.status());
     EXPECT_TRUE(reply.enabled());
     EXPECT_TRUE(reply.owned());
@@ -176,10 +179,10 @@
     EXPECT_TRUE(reply.has_dictionary_attack_threshold());
     EXPECT_TRUE(reply.has_dictionary_attack_lockout_in_effect());
     EXPECT_TRUE(reply.has_dictionary_attack_lockout_seconds_remaining());
-    Quit();
+    test->Quit();
   };
   GetTpmStatusRequest request;
-  service_->GetTpmStatus(request, base::Bind(callback));
+  service_->GetTpmStatus(request, base::Bind(callback, base::Unretained(this)));
   Run();
 }
 
@@ -187,7 +190,7 @@
   EXPECT_CALL(mock_tpm_status_, IsTpmEnabled()).WillRepeatedly(Return(false));
   EXPECT_CALL(mock_tpm_status_, GetDictionaryAttackInfo(_, _, _, _))
       .WillRepeatedly(Return(false));
-  auto callback = [this](const GetTpmStatusReply& reply) {
+  auto callback = [](decltype(this) test, const GetTpmStatusReply& reply) {
     EXPECT_EQ(STATUS_SUCCESS, reply.status());
     EXPECT_FALSE(reply.enabled());
     EXPECT_TRUE(reply.owned());
@@ -196,69 +199,69 @@
     EXPECT_FALSE(reply.has_dictionary_attack_threshold());
     EXPECT_FALSE(reply.has_dictionary_attack_lockout_in_effect());
     EXPECT_FALSE(reply.has_dictionary_attack_lockout_seconds_remaining());
-    Quit();
+    test->Quit();
   };
   GetTpmStatusRequest request;
-  service_->GetTpmStatus(request, base::Bind(callback));
+  service_->GetTpmStatus(request, base::Bind(callback, base::Unretained(this)));
   Run();
 }
 
 TEST_F(TpmManagerServiceTest, TakeOwnershipSuccess) {
   // Make sure InitializeTpm doesn't get multiple calls.
   EXPECT_CALL(mock_tpm_initializer_, InitializeTpm()).Times(1);
-  auto callback = [this](const TakeOwnershipReply& reply) {
+  auto callback = [](decltype(this) test, const TakeOwnershipReply& reply) {
     EXPECT_EQ(STATUS_SUCCESS, reply.status());
-    Quit();
+    test->Quit();
   };
   TakeOwnershipRequest request;
-  service_->TakeOwnership(request, base::Bind(callback));
+  service_->TakeOwnership(request, base::Bind(callback, base::Unretained(this)));
   Run();
 }
 
 TEST_F(TpmManagerServiceTest, TakeOwnershipFailure) {
   EXPECT_CALL(mock_tpm_initializer_, InitializeTpm())
       .WillRepeatedly(Return(false));
-  auto callback = [this](const TakeOwnershipReply& reply) {
+  auto callback = [](decltype(this) test, const TakeOwnershipReply& reply) {
     EXPECT_EQ(STATUS_DEVICE_ERROR, reply.status());
-    Quit();
+    test->Quit();
   };
   TakeOwnershipRequest request;
-  service_->TakeOwnership(request, base::Bind(callback));
+  service_->TakeOwnership(request, base::Bind(callback, base::Unretained(this)));
   Run();
 }
 
 TEST_F(TpmManagerServiceTest, TakeOwnershipNoTpm) {
   EXPECT_CALL(mock_tpm_status_, IsTpmEnabled()).WillRepeatedly(Return(false));
-  auto callback = [this](const TakeOwnershipReply& reply) {
+  auto callback = [](decltype(this) test, const TakeOwnershipReply& reply) {
     EXPECT_EQ(STATUS_NOT_AVAILABLE, reply.status());
-    Quit();
+    test->Quit();
   };
   TakeOwnershipRequest request;
-  service_->TakeOwnership(request, base::Bind(callback));
+  service_->TakeOwnership(request, base::Bind(callback, base::Unretained(this)));
   Run();
 }
 
 TEST_F(TpmManagerServiceTest, RemoveOwnerDependencyReadFailure) {
   EXPECT_CALL(mock_local_data_store_, Read(_)).WillRepeatedly(Return(false));
-  auto callback = [this](const RemoveOwnerDependencyReply& reply) {
+  auto callback = [](decltype(this) test, const RemoveOwnerDependencyReply& reply) {
     EXPECT_EQ(STATUS_DEVICE_ERROR, reply.status());
-    Quit();
+    test->Quit();
   };
   RemoveOwnerDependencyRequest request;
   request.set_owner_dependency(kOwnerDependency);
-  service_->RemoveOwnerDependency(request, base::Bind(callback));
+  service_->RemoveOwnerDependency(request, base::Bind(callback, base::Unretained(this)));
   Run();
 }
 
 TEST_F(TpmManagerServiceTest, RemoveOwnerDependencyWriteFailure) {
   EXPECT_CALL(mock_local_data_store_, Write(_)).WillRepeatedly(Return(false));
-  auto callback = [this](const RemoveOwnerDependencyReply& reply) {
+  auto callback = [](decltype(this) test, const RemoveOwnerDependencyReply& reply) {
     EXPECT_EQ(STATUS_DEVICE_ERROR, reply.status());
-    Quit();
+    test->Quit();
   };
   RemoveOwnerDependencyRequest request;
   request.set_owner_dependency(kOwnerDependency);
-  service_->RemoveOwnerDependency(request, base::Bind(callback));
+  service_->RemoveOwnerDependency(request, base::Bind(callback, base::Unretained(this)));
   Run();
 }
 
@@ -271,17 +274,20 @@
       .WillOnce(DoAll(SetArgPointee<0>(local_data), Return(true)));
   EXPECT_CALL(mock_local_data_store_, Write(_))
       .WillOnce(DoAll(SaveArg<0>(&local_data), Return(true)));
-  auto callback = [this, &local_data](const RemoveOwnerDependencyReply& reply) {
+  auto callback = [](decltype(this) test, LocalData* local_data,
+                     const RemoveOwnerDependencyReply& reply) {
     EXPECT_EQ(STATUS_SUCCESS, reply.status());
-    EXPECT_EQ(1, local_data.owner_dependency_size());
-    EXPECT_EQ(kOtherDependency, local_data.owner_dependency(0));
-    EXPECT_TRUE(local_data.has_owner_password());
-    EXPECT_EQ(kOwnerPassword, local_data.owner_password());
-    Quit();
+    EXPECT_EQ(1, local_data->owner_dependency_size());
+    EXPECT_EQ(kOtherDependency, local_data->owner_dependency(0));
+    EXPECT_TRUE(local_data->has_owner_password());
+    EXPECT_EQ(kOwnerPassword, local_data->owner_password());
+    test->Quit();
   };
   RemoveOwnerDependencyRequest request;
   request.set_owner_dependency(kOwnerDependency);
-  service_->RemoveOwnerDependency(request, base::Bind(callback));
+  service_->RemoveOwnerDependency(request,
+                                  base::Bind(callback, base::Unretained(this),
+                                             base::Unretained(&local_data)));
   Run();
 }
 
@@ -293,15 +299,18 @@
       .WillOnce(DoAll(SetArgPointee<0>(local_data), Return(true)));
   EXPECT_CALL(mock_local_data_store_, Write(_))
       .WillOnce(DoAll(SaveArg<0>(&local_data), Return(true)));
-  auto callback = [this, &local_data](const RemoveOwnerDependencyReply& reply) {
+  auto callback = [](decltype(this) test, LocalData* local_data,
+                     const RemoveOwnerDependencyReply& reply) {
     EXPECT_EQ(STATUS_SUCCESS, reply.status());
-    EXPECT_EQ(0, local_data.owner_dependency_size());
-    EXPECT_FALSE(local_data.has_owner_password());
-    Quit();
+    EXPECT_EQ(0, local_data->owner_dependency_size());
+    EXPECT_FALSE(local_data->has_owner_password());
+    test->Quit();
   };
   RemoveOwnerDependencyRequest request;
   request.set_owner_dependency(kOwnerDependency);
-  service_->RemoveOwnerDependency(request, base::Bind(callback));
+  service_->RemoveOwnerDependency(request,
+                                  base::Bind(callback, base::Unretained(this),
+                                             base::Unretained(&local_data)));
   Run();
 }
 
@@ -313,17 +322,19 @@
       .WillOnce(DoAll(SetArgPointee<0>(local_data), Return(true)));
   EXPECT_CALL(mock_local_data_store_, Write(_))
       .WillOnce(DoAll(SaveArg<0>(&local_data), Return(true)));
-  auto callback = [this, &local_data](const RemoveOwnerDependencyReply& reply) {
+  auto callback = [](decltype(this) test, const LocalData& local_data,
+                     const RemoveOwnerDependencyReply& reply) {
     EXPECT_EQ(STATUS_SUCCESS, reply.status());
     EXPECT_EQ(1, local_data.owner_dependency_size());
     EXPECT_EQ(kOwnerDependency, local_data.owner_dependency(0));
     EXPECT_TRUE(local_data.has_owner_password());
     EXPECT_EQ(kOwnerPassword, local_data.owner_password());
-    Quit();
+    test->Quit();
   };
   RemoveOwnerDependencyRequest request;
   request.set_owner_dependency(kOtherDependency);
-  service_->RemoveOwnerDependency(request, base::Bind(callback));
+  service_->RemoveOwnerDependency(
+      request, base::Bind(callback, base::Unretained(this), local_data));
   Run();
 }
 
@@ -336,9 +347,9 @@
   EXPECT_CALL(mock_tpm_nvram_, DefineSpace(nvram_index, nvram_size, attributes,
                                            auth_value, policy))
       .WillRepeatedly(Return(NVRAM_RESULT_INVALID_PARAMETER));
-  auto callback = [this](const DefineSpaceReply& reply) {
+  auto callback = [](decltype(this) test, const DefineSpaceReply& reply) {
     EXPECT_EQ(NVRAM_RESULT_INVALID_PARAMETER, reply.result());
-    Quit();
+    test->Quit();
   };
   DefineSpaceRequest request;
   request.set_index(nvram_index);
@@ -346,7 +357,7 @@
   request.add_attributes(NVRAM_BOOT_WRITE_LOCK);
   request.set_policy(policy);
   request.set_authorization_value(auth_value);
-  service_->DefineSpace(request, base::Bind(callback));
+  service_->DefineSpace(request, base::Bind(callback, base::Unretained(this)));
   Run();
 }
 
@@ -356,12 +367,12 @@
   auto define_callback = [](const DefineSpaceReply& reply) {
     EXPECT_EQ(NVRAM_RESULT_SUCCESS, reply.result());
   };
-  auto list_callback = [nvram_index](const ListSpacesReply& reply) {
+  auto list_callback = [](uint32_t nvram_index, const ListSpacesReply& reply) {
     EXPECT_EQ(NVRAM_RESULT_SUCCESS, reply.result());
     EXPECT_EQ(1, reply.index_list_size());
     EXPECT_EQ(nvram_index, reply.index_list(0));
   };
-  auto info_callback = [nvram_size](const GetSpaceInfoReply& reply) {
+  auto info_callback = [](uint32_t nvram_size, const GetSpaceInfoReply& reply) {
     EXPECT_EQ(NVRAM_RESULT_SUCCESS, reply.result());
     EXPECT_EQ(nvram_size, reply.size());
   };
@@ -370,20 +381,20 @@
   define_request.set_size(nvram_size);
   service_->DefineSpace(define_request, base::Bind(define_callback));
   ListSpacesRequest list_request;
-  service_->ListSpaces(list_request, base::Bind(list_callback));
+  service_->ListSpaces(list_request, base::Bind(list_callback, nvram_index));
   GetSpaceInfoRequest info_request;
   info_request.set_index(nvram_index);
-  service_->GetSpaceInfo(info_request, base::Bind(info_callback));
+  service_->GetSpaceInfo(info_request, base::Bind(info_callback, nvram_size));
   RunServiceWorkerAndQuit();
 }
 
 TEST_F(TpmManagerServiceTest, DestroyUnitializedNvram) {
-  auto callback = [this](const DestroySpaceReply& reply) {
+  auto callback = [](decltype(this) test, const DestroySpaceReply& reply) {
     EXPECT_EQ(NVRAM_RESULT_SPACE_DOES_NOT_EXIST, reply.result());
-    Quit();
+    test->Quit();
   };
   DestroySpaceRequest request;
-  service_->DestroySpace(request, base::Bind(callback));
+  service_->DestroySpace(request, base::Bind(callback, base::Unretained(this)));
   Run();
 }
 
@@ -481,12 +492,12 @@
 }
 
 TEST_F(TpmManagerServiceTest, ReadUninitializedNvram) {
-  auto callback = [this](const ReadSpaceReply& reply) {
+  auto callback = [](decltype(this) test, const ReadSpaceReply& reply) {
     EXPECT_EQ(NVRAM_RESULT_SPACE_DOES_NOT_EXIST, reply.result());
-    Quit();
+    test->Quit();
   };
   ReadSpaceRequest request;
-  service_->ReadSpace(request, base::Bind(callback));
+  service_->ReadSpace(request, base::Bind(callback, base::Unretained(this)));
   Run();
 }
 
@@ -499,7 +510,8 @@
   auto write_callback = [](const WriteSpaceReply& reply) {
     EXPECT_EQ(NVRAM_RESULT_SUCCESS, reply.result());
   };
-  auto read_callback = [nvram_data](const ReadSpaceReply& reply) {
+  auto read_callback = [](const std::string& nvram_data,
+                          const ReadSpaceReply& reply) {
     EXPECT_EQ(NVRAM_RESULT_SUCCESS, reply.result());
     EXPECT_EQ(nvram_data, reply.data());
   };
@@ -513,7 +525,7 @@
   service_->WriteSpace(write_request, base::Bind(write_callback));
   ReadSpaceRequest read_request;
   read_request.set_index(nvram_index);
-  service_->ReadSpace(read_request, base::Bind(read_callback));
+  service_->ReadSpace(read_request, base::Bind(read_callback, nvram_data));
   RunServiceWorkerAndQuit();
 }
 
diff --git a/trunks/background_command_transceiver.cc b/trunks/background_command_transceiver.cc
index 4a62e7d..51858ca 100644
--- a/trunks/background_command_transceiver.cc
+++ b/trunks/background_command_transceiver.cc
@@ -78,8 +78,9 @@
     const std::string& command) {
   if (task_runner_.get()) {
     std::string response;
-    base::WaitableEvent response_ready(true,    // manual_reset
-                                       false);  // initially_signaled
+    base::WaitableEvent response_ready(
+        base::WaitableEvent::ResetPolicy::MANUAL,
+        base::WaitableEvent::InitialState::NOT_SIGNALED);
     ResponseCallback callback =
         base::Bind(&AssignAndSignal, &response, &response_ready);
     // Use SendCommandTask instead of binding to next_transceiver_ directly to
diff --git a/trunks/tpm_state_impl.cc b/trunks/tpm_state_impl.cc
index e453cae..358f3e2 100644
--- a/trunks/tpm_state_impl.cc
+++ b/trunks/tpm_state_impl.cc
@@ -224,8 +224,8 @@
 }
 
 TPM_RC TpmStateImpl::CacheTpmProperties() {
-  CapabilityCallback callback =
-      base::Bind([this](const TPMU_CAPABILITIES& capability_data) {
+  CapabilityCallback callback = base::Bind(
+      [](TpmStateImpl* impl, const TPMU_CAPABILITIES& capability_data) {
         uint32_t next_property = 0;
         for (uint32_t i = 0;
              i < capability_data.tpm_properties.count && i < MAX_TPM_PROPERTIES;
@@ -234,11 +234,11 @@
               capability_data.tpm_properties.tpm_property[i];
           VLOG(1) << "TPM Property 0x" << std::hex << property.property
                   << " = 0x" << property.value;
-          tpm_properties_[property.property] = property.value;
+          impl->tpm_properties_[property.property] = property.value;
           next_property = property.property + 1;
         }
         return next_property;
-      });
+      }, base::Unretained(this));
   if (tpm_properties_.empty()) {
     TPM_RC result = GetCapability(callback, TPM_CAP_TPM_PROPERTIES, PT_FIXED,
                                   MAX_TPM_PROPERTIES);
@@ -251,8 +251,8 @@
 }
 
 TPM_RC TpmStateImpl::CacheAlgorithmProperties() {
-  CapabilityCallback callback =
-      base::Bind([this](const TPMU_CAPABILITIES& capability_data) {
+  CapabilityCallback callback = base::Bind(
+      [](TpmStateImpl* impl, const TPMU_CAPABILITIES& capability_data) {
         uint32_t next_property = 0;
         for (uint32_t i = 0;
              i < capability_data.algorithms.count && i < MAX_CAP_ALGS; ++i) {
@@ -260,11 +260,11 @@
               capability_data.algorithms.alg_properties[i];
           VLOG(1) << "Algorithm Properties 0x" << std::hex << property.alg
                   << " = 0x" << property.alg_properties;
-          algorithm_properties_[property.alg] = property.alg_properties;
+          impl->algorithm_properties_[property.alg] = property.alg_properties;
           next_property = property.alg + 1;
         }
         return next_property;
-      });
+      }, base::Unretained(this));
   if (algorithm_properties_.empty()) {
     return GetCapability(callback, TPM_CAP_ALGS, TPM_ALG_FIRST, MAX_CAP_ALGS);
   }
diff --git a/trunks/trunks_client_test.cc b/trunks/trunks_client_test.cc
index 74b4305..371e16c 100644
--- a/trunks/trunks_client_test.cc
+++ b/trunks/trunks_client_test.cc
@@ -832,7 +832,8 @@
     return false;
   }
   // Setup auto-cleanup of the NVRAM space.
-  auto cleanup = [&session, &owner_password, &utility, index]() {
+  auto cleanup = [](HmacSession* session, const std::string& owner_password,
+                    TpmUtility* utility, uint32_t index) {
     session->SetEntityAuthorizationValue(owner_password);
     TPM_RC result = utility->DestroyNVSpace(index, session->GetDelegate());
     if (result != TPM_RC_SUCCESS) {
@@ -851,7 +852,8 @@
    private:
     base::Closure callback_;
     bool cancel_ = false;
-  } scoper(base::Bind(cleanup));
+  } scoper(base::Bind(cleanup, base::Unretained(session.get()), owner_password,
+                      base::Unretained(utility.get()), index));
 
   session->SetEntityAuthorizationValue(owner_password);
   result = utility->WriteNVSpace(index, 0, nv_data, true /*owner*/,