[TaskScheduler]: Migrate off of AssertBlockingAllowedDeprecated in /sql
base::AssertBlockingAllowedDeprecated is deprecated in favor of
ScopedBlockingCall, which serves as a precise annotation of
the scope that may/will block.
Please make sure of the following:
- ScopedBlockingCall is instantiated in a scope with minimal CPU usage.
If this is not the case, ScopedBlockingCall should be instantiated
closer to the blocking call. See scoped_blocking_call.h for more
info. Please let me know when/where the blocking call happens if this needs
to be changed.
- Parameter |blocking_type| matches expectation:
MAY_BLOCK: The call might block (e.g. file I/O that might hit in memory cache).
WILL_BLOCK: The call will definitely block (e.g. cache already checked and now pinging
server synchronously).
See BlockingType for more info. While I assumed MAY_BLOCK by default, that might
not be the best fit if we know that this callsite is guaranteed to block.
- The ScopedBlockingCall's scope covers the entirety of the blocking operation
previously asserted against by the AssertBlockingAllowed().
- Calls to blocking //base APIs don't need to be annotated
with ScopedBlockingCall. All blocking //base APIs (e.g. base::ReadFileToString, base::File::Read,
base::SysInfo::AmountOfFreeDiskSpace, base::WaitableEvent::Wait, etc.) have their
own internal annotations.
Refer to the top-level CL if necessary :
https://chromium-review.googlesource.com/c/chromium/src/+/1338391
Please CQ if LGTY!
This CL was uploaded by git cl split.
[email protected]
Bug: 903957
Change-Id: Ia7d71b3bc2536dad0e6adc669aebe36addfd7fd0
Reviewed-on: https://chromium-review.googlesource.com/c/1365805
Commit-Queue: Victor Costan <[email protected]>
Reviewed-by: Victor Costan <[email protected]>
Reviewed-by: Chris Mumford <[email protected]>
Cr-Commit-Position: refs/heads/master@{#629836}
diff --git a/sql/database.h b/sql/database.h
index f4b6b29..4ea5d77 100644
--- a/sql/database.h
+++ b/sql/database.h
@@ -20,9 +20,9 @@
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
+#include "base/optional.h"
#include "base/sequence_checker.h"
#include "base/threading/scoped_blocking_call.h"
-#include "base/threading/thread_restrictions.h"
#include "base/time/tick_clock.h"
#include "sql/internal_api_token.h"
#include "sql/statement_id.h"
@@ -554,12 +554,12 @@
// |forced| indicates that orderly-shutdown checks should not apply.
void CloseInternal(bool forced);
- // Check whether the current thread is allowed to make IO calls, but only
- // if database wasn't open in memory. Function is inlined to be a no-op in
- // official build.
- void AssertIOAllowed() const {
+ // Construct a ScopedBlockingCall to annotate IO calls, but only if
+ // database wasn't open in memory.
+ void InitScopedBlockingCall(
+ base::Optional<base::ScopedBlockingCall>* scoped_blocking_call) const {
if (!in_memory_)
- base::AssertBlockingAllowedDeprecated();
+ scoped_blocking_call->emplace(base::BlockingType::MAY_BLOCK);
}
// Internal helper for Does*Exist() functions.
@@ -622,11 +622,12 @@
// orderly-shutdown checks should apply (see Database::RazeAndClose()).
void Close(bool forced);
- // Check whether the current thread is allowed to make IO calls, but only
- // if database wasn't open in memory.
- void AssertIOAllowed() const {
+ // Construct a ScopedBlockingCall to annotate IO calls, but only if
+ // database wasn't open in memory.
+ void InitScopedBlockingCall(
+ base::Optional<base::ScopedBlockingCall>* scoped_blocking_call) const {
if (database_)
- database_->AssertIOAllowed();
+ database_->InitScopedBlockingCall(scoped_blocking_call);
}
private: