buffet: Improve VLOG(1) for cloud request

Cloud request/responses were already logged in buffet when log level
1 was set. However it is still difficult to track request-response
pairs when OAuth2 requests were made when refreshing access tokens.

Made sure we log the request ID of refresh access token and also when
we receive success/error response, log the matching request ID to
match it with the corresponding request.

BUG=None
TEST=`FEATURES=test emerge-link buffet`

Change-Id: I03e92aa471f79556fc5118d88498624a74db7fbc
Reviewed-on: https://chromium-review.googlesource.com/285747
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/device_registration_info.cc b/buffet/device_registration_info.cc
index 2cd8c2c..c4c0112 100644
--- a/buffet/device_registration_info.cc
+++ b/buffet/device_registration_info.cc
@@ -212,7 +212,7 @@
     chromeos::ErrorPtr* error) const {
   const bool have_credentials = HaveRegistrationCredentials();
 
-  VLOG(1) << "Device registration record "
+  VLOG(2) << "Device registration record "
           << ((have_credentials) ? "found" : "not found.");
   if (!have_credentials)
     chromeos::Error::AddTo(error, FROM_HERE, kErrorDomainGCD,
@@ -266,6 +266,7 @@
   auto on_refresh_error = [shared_error_callback](
       chromeos::http::RequestID id,
       const chromeos::Error* error) {
+    VLOG(1) << "Refresh access token request with ID " << id << " failed";
     shared_error_callback->Run(error);
   };
 
@@ -276,12 +277,14 @@
     {"grant_type", "refresh_token"},
   };
 
-  chromeos::http::PostFormData(
+  chromeos::http::RequestID request_id = chromeos::http::PostFormData(
       GetOAuthURL("token"), form_data, {}, transport_,
       base::Bind(&DeviceRegistrationInfo::OnRefreshAccessTokenSuccess,
                  weak_factory_.GetWeakPtr(),
                  success_callback, shared_error_callback),
       base::Bind(on_refresh_error));
+  VLOG(1) << "Refresh access token request dispatched. Request ID = "
+          << request_id;
 }
 
 void DeviceRegistrationInfo::OnRefreshAccessTokenSuccess(
@@ -289,6 +292,7 @@
     const std::shared_ptr<CloudRequestErrorCallback>& error_callback,
     chromeos::http::RequestID id,
     std::unique_ptr<chromeos::http::Response> response) {
+  VLOG(1) << "Refresh access token request with ID " << id << " completed";
   chromeos::ErrorPtr error;
   auto json = ParseOAuthResponse(response.get(), &error);
   if (!json) {
@@ -860,7 +864,7 @@
     const base::DictionaryValue& json) {
   const base::ListValue* commands{nullptr};
   if (!json.GetList("commands", &commands)) {
-    VLOG(1) << "No commands in the response.";
+    VLOG(2) << "No commands in the response.";
   }
   const base::ListValue empty;
   callback.Run(commands ? *commands : empty);