forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[remoting][gRPC] Set a default deadline
This CL sets a default 30s timeout for gRPC requests if the caller didn't set it. Bug: 956424 Change-Id: I27a90a84cfc81d6763d24722d40b3cb06b931f65 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1590549 Commit-Queue: Joe Downing <joedow@chromium.org> Reviewed-by: Joe Downing <joedow@chromium.org> Cr-Commit-Position: refs/heads/master@{#655509}
- Loading branch information
Showing
5 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "remoting/base/grpc_support/grpc_util.h" | ||
|
||
#include <chrono> | ||
|
||
#include "third_party/grpc/src/include/grpcpp/client_context.h" | ||
|
||
namespace remoting { | ||
|
||
void SetDeadline(grpc::ClientContext* context, base::Time deadline) { | ||
context->set_deadline( | ||
std::chrono::system_clock::from_time_t(deadline.ToTimeT())); | ||
} | ||
|
||
base::Time GetDeadline(const grpc::ClientContext& context) { | ||
auto deadline_tp = context.deadline(); | ||
if (deadline_tp == std::chrono::system_clock::time_point::max()) { | ||
return base::Time::Max(); | ||
} | ||
return base::Time::FromTimeT( | ||
std::chrono::system_clock::to_time_t(deadline_tp)); | ||
} | ||
|
||
} // namespace remoting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef REMOTING_BASE_GRPC_SUPPORT_GRPC_UTIL_H_ | ||
#define REMOTING_BASE_GRPC_SUPPORT_GRPC_UTIL_H_ | ||
|
||
#include "base/time/time.h" | ||
|
||
namespace grpc { | ||
class ClientContext; | ||
} // namespace grpc | ||
|
||
namespace remoting { | ||
|
||
// Sets the deadline on |context|. | ||
void SetDeadline(grpc::ClientContext* context, base::Time deadline); | ||
|
||
// Gets the deadline in base::Time. Returns base::Time::Max if the deadline is | ||
// not set. | ||
base::Time GetDeadline(const grpc::ClientContext& context); | ||
|
||
} // namespace remoting | ||
|
||
#endif // REMOTING_BASE_GRPC_SUPPORT_GRPC_UTIL_H_ |