| Code-Review | +1 |
void ExtensionsUrlOverrideRegistryManager::OnUrlOverrideDisabled(Why doesn't this have incognito_enabled? Does disable always affect both if present?
std::unique_ptr<Observer> observer_;Does this need to be a unique ptr? Isn't this observer's lifetime exactly identical to the tracker? Can't it just be a member (not a ptr)?
bool GetAndSetIncognitoStatus(const Extension& extension);Nit: I'd call this cache.
// Updates the override counts for the given `overrides` by `overrides_delta`.Nit: Newline for consistency?
registrar_->AddObserver(&*observer_);Why not `observer_.get()`?
const URLOverrides::URLOverrideMap& overrides) {Do we only get each override registered once? Do we not have to be idempotent?
std::string chrome_url_path = std::string(page_override_pair.first);Same as elsewhere, we shouldn't need to make a new string here. Maybe `chrome_url_path` should be a `const std::string&`?
auto it = override_map_.try_emplace(chrome_url_path).first;I don't understand why we don't either std::move or just directly pass page_override_pair.first here.
auto it = override_map_.try_emplace(chrome_url_path).first;All this usage of try_emplace feels surprising to me. You could just check the try_emplace(...).second, but I guess it doesn't really simplify. Nevermind.
IncognitoInfo::IsSplitMode(&extension) &&What exactly does this mean? If this is true, it means the extension gets to run in both regular and incog browsing modes?
util::IsIncognitoEnabled(extension.id(), profile_);Erm what? How's this different from IsSplitMode? Does this only return true when the profile is incognito?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
void ExtensionsUrlOverrideRegistryManager::OnUrlOverrideDisabled(Why doesn't this have incognito_enabled? Does disable always affect both if present?
Yes, that's exactly it! If the incognito status changes, we will call OnUrlOverrideEnabled with the applicable incognito status. I'll update the comments to further elaborate on this point
Does this need to be a unique ptr? Isn't this observer's lifetime exactly identical to the tracker? Can't it just be a member (not a ptr)?
I got pointer brain and forgot this was an option. Removing the ptr!
bool GetAndSetIncognitoStatus(const Extension& extension);Nit: I'd call this cache.
Done
// Updates the override counts for the given `overrides` by `overrides_delta`.Fiaz MuhammadNit: Newline for consistency?
Done
Fiaz MuhammadTests?
I'll need to figure out how to set up the BUILD.gn for this so I'll do this in a follow-up!
registrar_->AddObserver(&*observer_);Fiaz MuhammadWhy not `observer_.get()`?
I somehow forgot this was an option... thanks for reminding me!
Do we only get each override registered once? Do we not have to be idempotent?
The observer guarantees that each override registration/unregistration will be called once for each URL override status change, so we don't need to make this idempotent.
When the incognito status changes, the observer methods OnExtensionOverrideRemoved and then OnExtensionOverrideAdded will be called sequentially!
std::string chrome_url_path = std::string(page_override_pair.first);Same as elsewhere, we shouldn't need to make a new string here. Maybe `chrome_url_path` should be a `const std::string&`?
Done
auto it = override_map_.try_emplace(chrome_url_path).first;Fiaz MuhammadI don't understand why we don't either std::move or just directly pass page_override_pair.first here.
Done
What exactly does this mean? If this is true, it means the extension gets to run in both regular and incog browsing modes?
Split mode is an extensions manifest flag that has the property of allowing for URL Overrides even in incognito mode.
When split mode is enabled, we run extension in a separate instance in incognito, which is the only case URL overrides are acceptable.
See https://chromium-review.googlesource.com/c/chromium/src/+/6897267/comment/178fceb6_2b817ec7/
Erm what? How's this different from IsSplitMode? Does this only return true when the profile is incognito?
No, it tells us whether the extension is enabled for use in incognito mode. So the extension may be in split mode, but the user may not have given permission for it to run in incognito.
IsIncognitoEnabled checks for the latter!
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +2 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +2 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
1 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: chrome/browser/android/extensions/extensions_url_override_state_tracker_impl.h
Insertions: 3, Deletions: 2.
@@ -63,6 +63,7 @@
// deactivated.
void OnUrlOverrideDeactivated(const Extension& extension,
const URLOverrides::URLOverrideMap& overrides);
+
// Updates the override counts for the given `overrides` by `overrides_delta`.
// `overrides_delta` is 1 for registration / activation and -1 for
// deactivation. Notifies observers if the state of an override changes.
@@ -72,12 +73,12 @@
void EnsureOverridesInitialized(
const URLOverrides::URLOverrideMap& overrides);
- bool GetAndSetIncognitoStatus(const Extension& extension);
+ bool GetAndCacheIncognitoStatus(const Extension& extension);
base::flat_map<std::string, bool> extension_id_to_incognito_status_;
base::flat_map<std::string, IncognitoStatusToOverrideCount> override_map_;
- std::unique_ptr<Observer> observer_;
+ Observer observer_;
raw_ptr<ExtensionWebUIOverrideRegistrar> registrar_;
raw_ptr<StateListener> listener_;
```
```
The name of the file: chrome/browser/android/extensions/extensions_url_override_state_tracker.h
Insertions: 3, Deletions: 2.
@@ -16,8 +16,9 @@
class StateListener {
public:
// To be called when overrides now exist for this chrome URL path.
- // This will be called again when URL overrides are enabled in
- // incognito mode.
+ // `incognito_enabled` refers to whether this URL Override is enabled for
+ // use in incognito. This can also be called again when the
+ // incognito_enabled status of this override changes.
virtual void OnUrlOverrideEnabled(const std::string& chrome_url_path,
bool incognito_enabled) = 0;
```
```
The name of the file: chrome/browser/android/extensions/extensions_url_override_state_tracker_impl.cc
Insertions: 12, Deletions: 11.
@@ -8,7 +8,6 @@
#include "base/notreached.h"
#include "chrome/browser/android/extensions/extensions_url_override_state_tracker.h"
-#include "chrome/common/url_constants.h"
#include "extensions/browser/extension_util.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_handlers/incognito_info.h"
@@ -36,29 +35,27 @@
const Extension& extension) {
const URLOverrides::URLOverrideMap& overrides =
URLOverrides::GetChromeURLOverrides(&extension);
- state_tracker_->OnUrlOverrideRegistered(extension, overrides);
+ state_tracker_->OnUrlOverrideDeactivated(extension, overrides);
}
// ExtensionUrlOverrideStateTrackerImpl Implementation.
ExtensionUrlOverrideStateTrackerImpl::ExtensionUrlOverrideStateTrackerImpl(
Profile* profile,
StateListener* listener)
- : listener_(listener), profile_(profile) {
- observer_ =
- std::make_unique<ExtensionUrlOverrideStateTrackerImpl::Observer>(this);
+ : observer_(this), listener_(listener), profile_(profile) {
registrar_ =
ExtensionWebUIOverrideRegistrar::GetFactoryInstance()->Get(profile_);
- registrar_->AddObserver(&*observer_);
+ registrar_->AddObserver(&observer_);
}
ExtensionUrlOverrideStateTrackerImpl::~ExtensionUrlOverrideStateTrackerImpl() {
- registrar_->RemoveObserver(&*observer_);
+ registrar_->RemoveObserver(&observer_);
}
void ExtensionUrlOverrideStateTrackerImpl::OnUrlOverrideRegistered(
const Extension& extension,
const URLOverrides::URLOverrideMap& overrides) {
- GetAndSetIncognitoStatus(extension);
+ GetAndCacheIncognitoStatus(extension);
UpdateOverrides(extension, overrides, 1);
}
void ExtensionUrlOverrideStateTrackerImpl::OnUrlOverrideDeactivated(
@@ -76,22 +73,26 @@
bool incognito_override_allowed =
extension_id_to_incognito_status_[extension.id()];
for (const auto& page_override_pair : overrides) {
- std::string chrome_url_path = std::string(page_override_pair.first);
+ const std::string& chrome_url_path = page_override_pair.first;
auto override_it = override_map_.find(chrome_url_path);
if (override_it == override_map_.end()) {
NOTREACHED() << "Override map missing entry for initialized override";
}
+
IncognitoStatusToOverrideCount& counts = override_it->second;
int prev_regular_overrides_count = counts[false];
int prev_incognito_overrides_count = counts[true];
counts[false] += overrides_delta;
+
if (incognito_override_allowed) {
counts[true] += overrides_delta;
}
+
int new_regular_overrides_count = counts[false];
int new_incognito_overrides_count = counts[true];
DCHECK_GE(new_regular_overrides_count, 0);
DCHECK_GE(new_incognito_overrides_count, 0);
+
bool was_enabled = prev_regular_overrides_count > 0;
bool is_enabled = new_regular_overrides_count > 0;
if (!was_enabled && is_enabled) {
@@ -113,7 +114,7 @@
void ExtensionUrlOverrideStateTrackerImpl::EnsureOverridesInitialized(
const URLOverrides::URLOverrideMap& overrides) {
for (const auto& page_override_pair : overrides) {
- std::string chrome_url_path = std::string(page_override_pair.first);
+ const std::string& chrome_url_path = page_override_pair.first;
auto it = override_map_.try_emplace(chrome_url_path).first;
IncognitoStatusToOverrideCount& counts = it->second;
counts.try_emplace(true, 0);
@@ -121,7 +122,7 @@
}
}
-bool ExtensionUrlOverrideStateTrackerImpl::GetAndSetIncognitoStatus(
+bool ExtensionUrlOverrideStateTrackerImpl::GetAndCacheIncognitoStatus(
const Extension& extension) {
bool incognito_override_allowed =
IncognitoInfo::IsSplitMode(&extension) &&
```
```
The name of the file: chrome/browser/android/extensions/BUILD.gn
Insertions: 14, Deletions: 2.
@@ -3,6 +3,7 @@
# found in the LICENSE file.
import("//build/config/android/rules.gni")
+import("//extensions/buildflags/buildflags.gni")
import("//third_party/jni_zero/jni_zero.gni")
source_set("android") {
@@ -10,8 +11,6 @@
"extensions_url_override_registry_manager.cc",
"extensions_url_override_registry_manager.h",
"extensions_url_override_state_tracker.h",
- "extensions_url_override_state_tracker_impl.cc",
- "extensions_url_override_state_tracker_impl.h",
]
deps = [
@@ -19,8 +18,21 @@
"//base",
"//chrome/browser/profiles:profile",
"//content/public/browser",
+ "//extensions/buildflags",
"//third_party/jni_zero",
]
+
+ if (enable_extensions) {
+ sources += [
+ "extensions_url_override_state_tracker_impl.cc",
+ "extensions_url_override_state_tracker_impl.h",
+ ]
+
+ deps += [
+ "//extensions/browser:browser_sources",
+ "//extensions/common",
+ ]
+ }
}
generate_jni("jni_headers") {
```
[URL Override] Extensions URL Overrides State Tracking
- Creates several classes to manage state tracking.
- Managers own a state tracker, which performs state tracking on their
behalf. The state tracker observers the
ExtensionsWebUiRegistrar.
- URL Override State tracking is done separately for incognito-enabled
extensions.
- Only initialize state tracker if extensions are enabled.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |