@@ -78,28 +78,47 @@ std::size_t DefaultConnectionPoolSize() {
7878#define GOOGLE_CLOUD_CPP_STORAGE_DEFAULT_DOWNLOAD_STALL_TIMEOUT 120
7979#endif // GOOGLE_CLOUD_CPP_STORAGE_DEFAULT_DOWNLOAD_STALL_TIMEOUT
8080
81+ // Define the defaults using a pre-processor macro, this allows the application
82+ // developers to change the defaults for their application by compiling with
83+ // different values.
84+ #ifndef STORAGE_CLIENT_DEFAULT_MAXIMUM_RETRY_PERIOD
85+ #define STORAGE_CLIENT_DEFAULT_MAXIMUM_RETRY_PERIOD std::chrono::minutes (15 )
86+ #endif // STORAGE_CLIENT_DEFAULT_MAXIMUM_RETRY_PERIOD
87+
88+ #ifndef STORAGE_CLIENT_DEFAULT_INITIAL_BACKOFF_DELAY
89+ #define STORAGE_CLIENT_DEFAULT_INITIAL_BACKOFF_DELAY std::chrono::seconds (1 )
90+ #endif // STORAGE_CLIENT_DEFAULT_INITIAL_BACKOFF_DELAY
91+
92+ #ifndef STORAGE_CLIENT_DEFAULT_MAXIMUM_BACKOFF_DELAY
93+ #define STORAGE_CLIENT_DEFAULT_MAXIMUM_BACKOFF_DELAY std::chrono::minutes (5 )
94+ #endif // STORAGE_CLIENT_DEFAULT_MAXIMUM_BACKOFF_DELAY
95+
96+ #ifndef STORAGE_CLIENT_DEFAULT_BACKOFF_SCALING
97+ #define STORAGE_CLIENT_DEFAULT_BACKOFF_SCALING 2.0
98+ #endif // STORAGE_CLIENT_DEFAULT_BACKOFF_SCALING
99+
81100} // namespace
82101
83102namespace internal {
84103
85104std::string JsonEndpoint (Options const & options) {
86- return GetEmulator ().value_or (options.get <GcsRestEndpointOption >()) +
105+ return GetEmulator ().value_or (options.get <RestEndpointOption >()) +
87106 " /storage/" + options.get <TargetApiVersionOption>();
88107}
89108
90109std::string JsonUploadEndpoint (Options const & options) {
91- return GetEmulator ().value_or (options.get <GcsRestEndpointOption >()) +
110+ return GetEmulator ().value_or (options.get <RestEndpointOption >()) +
92111 " /upload/storage/" + options.get <TargetApiVersionOption>();
93112}
94113
95114std::string XmlEndpoint (Options const & options) {
96- return GetEmulator ().value_or (options.get <GcsRestEndpointOption >());
115+ return GetEmulator ().value_or (options.get <RestEndpointOption >());
97116}
98117
99118std::string IamEndpoint (Options const & options) {
100119 auto emulator = GetEmulator ();
101120 if (emulator) return *emulator + " /iamapi" ;
102- return options.get <GcsIamEndpointOption >();
121+ return options.get <IamEndpointOption >();
103122}
104123
105124Options MakeOptions (ClientOptions o) {
@@ -112,13 +131,28 @@ ClientOptions MakeBackwardsCompatibleClientOptions(Options opts) {
112131 return ClientOptions (std::move (opts));
113132}
114133
134+ Options ApplyPolicy (Options opts, RetryPolicy const & p) {
135+ opts.set <RetryPolicyOption>(p.clone ());
136+ return opts;
137+ }
138+
139+ Options ApplyPolicy (Options opts, BackoffPolicy const & p) {
140+ opts.set <BackoffPolicyOption>(p.clone ());
141+ return opts;
142+ }
143+
144+ Options ApplyPolicy (Options opts, IdempotencyPolicy const & p) {
145+ opts.set <IdempotencyPolicyOption>(p.clone ());
146+ return opts;
147+ }
148+
115149Options DefaultOptions (std::shared_ptr<oauth2::Credentials> credentials,
116150 Options opts) {
117151 auto o =
118152 Options{}
119153 .set <Oauth2CredentialsOption>(std::move (credentials))
120- .set <GcsRestEndpointOption >(" https://storage.googleapis.com" )
121- .set <GcsIamEndpointOption >(" https://iamcredentials.googleapis.com/v1" )
154+ .set <RestEndpointOption >(" https://storage.googleapis.com" )
155+ .set <IamEndpointOption >(" https://iamcredentials.googleapis.com/v1" )
122156 .set <TargetApiVersionOption>(" v1" )
123157 .set <ConnectionPoolSizeOption>(DefaultConnectionPoolSize ())
124158 .set <DownloadBufferSizeOption>(
@@ -132,13 +166,24 @@ Options DefaultOptions(std::shared_ptr<oauth2::Credentials> credentials,
132166 .set <MaximumCurlSocketRecvSizeOption>(0 )
133167 .set <MaximumCurlSocketSendSizeOption>(0 )
134168 .set <DownloadStallTimeoutOption>(std::chrono::seconds (
135- GOOGLE_CLOUD_CPP_STORAGE_DEFAULT_DOWNLOAD_STALL_TIMEOUT));
169+ GOOGLE_CLOUD_CPP_STORAGE_DEFAULT_DOWNLOAD_STALL_TIMEOUT))
170+ .set <RetryPolicyOption>(
171+ LimitedTimeRetryPolicy (
172+ STORAGE_CLIENT_DEFAULT_MAXIMUM_RETRY_PERIOD)
173+ .clone ())
174+ .set <BackoffPolicyOption>(
175+ ExponentialBackoffPolicy (
176+ STORAGE_CLIENT_DEFAULT_INITIAL_BACKOFF_DELAY,
177+ STORAGE_CLIENT_DEFAULT_MAXIMUM_BACKOFF_DELAY,
178+ STORAGE_CLIENT_DEFAULT_BACKOFF_SCALING)
179+ .clone ())
180+ .set <IdempotencyPolicyOption>(AlwaysRetryIdempotencyPolicy ().clone ());
136181
137182 o = google::cloud::internal::MergeOptions (std::move (opts), std::move (o));
138183 auto emulator = GetEmulator ();
139184 if (emulator.has_value ()) {
140- o.set <GcsRestEndpointOption >(*emulator).set <GcsIamEndpointOption>(
141- *emulator + " /iamapi" );
185+ o.set <RestEndpointOption >(*emulator).set <IamEndpointOption>(*emulator +
186+ " /iamapi" );
142187 }
143188
144189 auto tracing =
0 commit comments