Repository: electron/electron (language: cpp)

Issue:
`avoidClosingConnections` option on `session.clearData()` doesn't work without `dataTypes`
### Preflight Checklist

- [x] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [x] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [x] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a bug report that matches the one I want to file, without success.

### Electron Version

34.0.0-beta.6

### What operating system(s) are you using?

macOS

### Operating System Version

macOS Sequoia 15.1.1

### What arch are you using?

arm64 (including Apple Silicon)

### Last Known Working Electron version

_No response_

### Expected Behavior

`avoidClosingConnections` is `false` by default (as the [docs](https://www.electronjs.org/docs/latest/api/session#sescleardataoptions) say), even when `dataTypes` is not set.

### Actual Behavior

`avoidClosingConnections` only takes effect when `dataTypes` is set.

If `dataTypes` is not set, `session.clearData()` behaves as if `avoidClosingConnections` was set to `true` (no matter what its actual value is).

**Code:**

The data type mask is set to `~0ULL` here (i.e. `111111...`): https://github.com/electron/electron/blob/9f1e23c405847c2773231347b7604731741b0034/shell/browser/api/electron_api_session.cc#L1312

`avoidClosingConnections` will try to set a bit in the data type mask to 1 here: https://github.com/electron/electron/blob/9f1e23c405847c2773231347b7604731741b0034/shell/browser/api/electron_api_session.cc#L1325-L1330

This only takes effect if `dataTypes` is set here: https://github.com/electron/electron/blob/9f1e23c405847c2773231347b7604731741b0034/shell/browser/api/electron_api_session.cc#L1320-L1323

Otherwise, that bit is already 1.

**Changes necessary:**

* Either fix the default behavior (preferred).
* Or update the docs.

### Testcase Gist URL

https://gist.github.com/9fcc98d6a6a69f935d365df7ea741276

### Additional Information

I do not use this function in my code without specifying `dataTypes`, so I do not care much if this is fixed. I just noticed it while reading the code. If it doesn't get fixed, we should update the docs though.


Discussion / hints:

Fix patch:
diff --git a/shell/browser/api/electron_api_session.cc b/shell/browser/api/electron_api_session.cc
index e72a309caa9e5..ae705c4fa5e67 100644
--- a/shell/browser/api/electron_api_session.cc
+++ b/shell/browser/api/electron_api_session.cc
@@ -160,7 +160,8 @@ uint32_t GetQuotaMask(const std::vector<std::string>& quota_types) {
   return quota_mask;
 }
 
-constexpr BrowsingDataRemover::DataType kClearDataTypeAll = ~0ULL;
+constexpr BrowsingDataRemover::DataType kClearDataTypeAll =
+    ~0ULL & ~BrowsingDataRemover::DATA_TYPE_AVOID_CLOSING_CONNECTIONS;
 constexpr BrowsingDataRemover::OriginType kClearOriginTypeAll =
     BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB |
     BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB;


Test patch: