extensions: Fix sessions API getRecentlyClosed() bug on desktop Android [chromium/src : main]

0 views
Skip to first unread message

James Cook (Gerrit)

unread,
Feb 18, 2026, 5:24:19 PM (2 days ago) Feb 18
to Zoraiz Naeem, Achuith Bhandarkar, Chromium LUCI CQ, chromium...@chromium.org, chromium-a...@chromium.org, extension...@chromium.org
Attention needed from Zoraiz Naeem

James Cook added 1 comment

Patchset-level comments
File-level comment, Patchset 2 (Latest):
James Cook . resolved

Zoraiz, please take a look. Just a bug I noticed in passing. Thanks!

Open in Gerrit

Related details

Attention is currently required from:
  • Zoraiz Naeem
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Ib6295d9f29dc9c7fdbcd75064ef01bb688cd6f07
Gerrit-Change-Number: 7590176
Gerrit-PatchSet: 2
Gerrit-Owner: James Cook <jame...@chromium.org>
Gerrit-Reviewer: James Cook <jame...@chromium.org>
Gerrit-Reviewer: Zoraiz Naeem <zorai...@chromium.org>
Gerrit-CC: Achuith Bhandarkar <ach...@chromium.org>
Gerrit-Attention: Zoraiz Naeem <zorai...@chromium.org>
Gerrit-Comment-Date: Wed, 18 Feb 2026 22:24:09 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Zoraiz Naeem (Gerrit)

unread,
Feb 18, 2026, 5:49:04 PM (2 days ago) Feb 18
to James Cook, Achuith Bhandarkar, Chromium LUCI CQ, chromium...@chromium.org, chromium-a...@chromium.org, extension...@chromium.org
Attention needed from James Cook

Zoraiz Naeem added 1 comment

File chrome/browser/extensions/api/sessions/sessions_api.cc
Line 355, Patchset 2 (Latest): // to check again as Java can add at most one window.
Zoraiz Naeem . unresolved

The second part of the comment is not entirely clear to me. No need to check what?

Open in Gerrit

Related details

Attention is currently required from:
  • James Cook
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Ib6295d9f29dc9c7fdbcd75064ef01bb688cd6f07
    Gerrit-Change-Number: 7590176
    Gerrit-PatchSet: 2
    Gerrit-Owner: James Cook <jame...@chromium.org>
    Gerrit-Reviewer: James Cook <jame...@chromium.org>
    Gerrit-Reviewer: Zoraiz Naeem <zorai...@chromium.org>
    Gerrit-CC: Achuith Bhandarkar <ach...@chromium.org>
    Gerrit-Attention: James Cook <jame...@chromium.org>
    Gerrit-Comment-Date: Wed, 18 Feb 2026 22:48:55 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    James Cook (Gerrit)

    unread,
    Feb 18, 2026, 6:05:07 PM (2 days ago) Feb 18
    to Zoraiz Naeem, Achuith Bhandarkar, Chromium LUCI CQ, chromium...@chromium.org, chromium-a...@chromium.org, extension...@chromium.org
    Attention needed from Zoraiz Naeem

    James Cook added 2 comments

    Patchset-level comments
    File-level comment, Patchset 3 (Latest):
    James Cook . resolved

    Zoraiz, please take another look.

    File chrome/browser/extensions/api/sessions/sessions_api.cc
    Line 355, Patchset 2: // to check again as Java can add at most one window.
    Zoraiz Naeem . resolved

    The second part of the comment is not entirely clear to me. No need to check what?

    James Cook

    Updated.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Zoraiz Naeem
    Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: Ib6295d9f29dc9c7fdbcd75064ef01bb688cd6f07
      Gerrit-Change-Number: 7590176
      Gerrit-PatchSet: 3
      Gerrit-Owner: James Cook <jame...@chromium.org>
      Gerrit-Reviewer: James Cook <jame...@chromium.org>
      Gerrit-Reviewer: Zoraiz Naeem <zorai...@chromium.org>
      Gerrit-CC: Achuith Bhandarkar <ach...@chromium.org>
      Gerrit-Attention: Zoraiz Naeem <zorai...@chromium.org>
      Gerrit-Comment-Date: Wed, 18 Feb 2026 23:04:58 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Zoraiz Naeem <zorai...@chromium.org>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Zoraiz Naeem (Gerrit)

      unread,
      Feb 18, 2026, 6:09:59 PM (2 days ago) Feb 18
      to James Cook, Achuith Bhandarkar, Chromium LUCI CQ, chromium...@chromium.org, chromium-a...@chromium.org, extension...@chromium.org
      Attention needed from James Cook

      Zoraiz Naeem voted and added 1 comment

      Votes added by Zoraiz Naeem

      Code-Review+1

      1 comment

      Patchset-level comments
      Zoraiz Naeem . resolved

      lgtm!

      Open in Gerrit

      Related details

      Attention is currently required from:
      • James Cook
      Submit Requirements:
        • requirement satisfiedCode-Coverage
        • requirement satisfiedCode-Owners
        • requirement satisfiedCode-Review
        • requirement satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: chromium/src
        Gerrit-Branch: main
        Gerrit-Change-Id: Ib6295d9f29dc9c7fdbcd75064ef01bb688cd6f07
        Gerrit-Change-Number: 7590176
        Gerrit-PatchSet: 3
        Gerrit-Owner: James Cook <jame...@chromium.org>
        Gerrit-Reviewer: James Cook <jame...@chromium.org>
        Gerrit-Reviewer: Zoraiz Naeem <zorai...@chromium.org>
        Gerrit-CC: Achuith Bhandarkar <ach...@chromium.org>
        Gerrit-Attention: James Cook <jame...@chromium.org>
        Gerrit-Comment-Date: Wed, 18 Feb 2026 23:09:50 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: Yes
        satisfied_requirement
        open
        diffy

        Achuith Bhandarkar (Gerrit)

        unread,
        Feb 18, 2026, 6:30:48 PM (2 days ago) Feb 18
        to James Cook, Zoraiz Naeem, Chromium LUCI CQ, chromium...@chromium.org, chromium-a...@chromium.org, extension...@chromium.org
        Attention needed from James Cook

        Achuith Bhandarkar added 4 comments

        Patchset-level comments
        Achuith Bhandarkar . resolved

        I could be wrong below, could you please check?

        File chrome/browser/extensions/api/sessions/sessions_api.cc
        Line 313, Patchset 3 (Latest): max_results >= 0 &&
        Achuith Bhandarkar . unresolved

        I believe we can drop this check since size_t is always positive

        Line 356, Patchset 3 (Latest): if (result_.size() == max_results) {
        Achuith Bhandarkar . unresolved

        Does this early return create a problem? If `result_` is filled to `max_results` with tabs from the `TabRestoreService`, this will return before querying for a potentially more recently closed window from the Java side.

        Since the API should return the most recently closed sessions, this could lead to incorrect results. For example, if `maxResults` is 1, a tab was recently closed, and then a window was closed (making it the most recent item), this implementation would return the tab without ever checking for the window.

        A potential solution would be to perform the trimming *after* the window from the Java side has been added. You could store `max_results` as a member variable, and then `OnRecentlyClosedWindowOrTabCallback` could trim `result_` to the correct size before calling `Respond()`.

        File chrome/browser/extensions/api/sessions/sessions_apitest.cc
        Line 771, Patchset 3 (Latest): // Querying with a maxResults limit of 1 should return 1 tab and not the
        Achuith Bhandarkar . unresolved

        This test case seems to be asserting incorrect behavior. In this test, a window is closed after a tab, making the window the most recently closed session. Therefore, a call to `getRecentlyClosed` with `maxResults: 1` should return the window, not the tab.

        This test appears to validate the new logic in `sessions_api.cc` which may fail to fetch the window if the results list is already full of tabs. Since the API is documented to return sessions sorted by recency, this test should probably be changed to assert the correct behavior (i.e., that the window is returned).

        Open in Gerrit

        Related details

        Attention is currently required from:
        • James Cook
        Submit Requirements:
          • requirement satisfiedCode-Coverage
          • requirement satisfiedCode-Owners
          • requirement satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement satisfiedReview-Enforcement
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: chromium/src
          Gerrit-Branch: main
          Gerrit-Change-Id: Ib6295d9f29dc9c7fdbcd75064ef01bb688cd6f07
          Gerrit-Change-Number: 7590176
          Gerrit-PatchSet: 3
          Gerrit-Owner: James Cook <jame...@chromium.org>
          Gerrit-Reviewer: James Cook <jame...@chromium.org>
          Gerrit-Reviewer: Zoraiz Naeem <zorai...@chromium.org>
          Gerrit-CC: Achuith Bhandarkar <ach...@chromium.org>
          Gerrit-Attention: James Cook <jame...@chromium.org>
          Gerrit-Comment-Date: Wed, 18 Feb 2026 23:30:41 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: No
          satisfied_requirement
          unsatisfied_requirement
          open
          diffy

          James Cook (Gerrit)

          unread,
          Feb 19, 2026, 8:12:23 PM (5 hours ago) Feb 19
          to Achuith Bhandarkar, Calder Kitagawa, Zoraiz Naeem, Chromium LUCI CQ, chromium...@chromium.org, chromium-a...@chromium.org, extension...@chromium.org
          Attention needed from Achuith Bhandarkar and Calder Kitagawa

          James Cook added 6 comments

          Patchset-level comments
          File-level comment, Patchset 11 (Latest):
          James Cook . resolved

          Achuith, please take another look.

          Calder, could you take a look at *android* and sessions_api.cc (for JNI). I have some failing tests (only on the bots!) and need some directional advice on how I'm passing a pair items from Java to C++. Thanks!

          Zoraiz to CC, just FYI

          File chrome/android/java/src/org/chromium/chrome/browser/RecentlyClosedEntriesManager.java
          Line 75, Patchset 11 (Latest): public static class TabModelAndTimestamp {
          James Cook . unresolved

          Calder, I now need the getRecentlyClosedWindow() JNI method to take a JniCallback with both a TabModel and a timestamp, but JniCallback only takes one parameter. So I created this class, which I unpack by hand on the C++ side.

          Is there a better way to do this? If so please let me know (and I'll need some hand-holding, I'm not very good with Java or JNI).

          File chrome/browser/extensions/api/sessions/sessions_api.cc
          Line 263, Patchset 11 (Latest): CHECK(tab_model_field_id);
          James Cook . unresolved

          Calder, this CHECK fails, but only on the bots. Locally everything works fine. Am I doing something wrong? Are class paths different somehow?

          Line 313, Patchset 3: max_results >= 0 &&
          Achuith Bhandarkar . resolved

          I believe we can drop this check since size_t is always positive

          James Cook

          Done

          Line 356, Patchset 3: if (result_.size() == max_results) {
          Achuith Bhandarkar . resolved

          Does this early return create a problem? If `result_` is filled to `max_results` with tabs from the `TabRestoreService`, this will return before querying for a potentially more recently closed window from the Java side.

          Since the API should return the most recently closed sessions, this could lead to incorrect results. For example, if `maxResults` is 1, a tab was recently closed, and then a window was closed (making it the most recent item), this implementation would return the tab without ever checking for the window.

          A potential solution would be to perform the trimming *after* the window from the Java side has been added. You could store `max_results` as a member variable, and then `OnRecentlyClosedWindowOrTabCallback` could trim `result_` to the correct size before calling `Respond()`.

          James Cook

          Done. I now add the window (if there is one). If I added one, I sort the results by time and truncate the list if necessary.

          File chrome/browser/extensions/api/sessions/sessions_apitest.cc
          Line 771, Patchset 3: // Querying with a maxResults limit of 1 should return 1 tab and not the
          Achuith Bhandarkar . resolved

          This test case seems to be asserting incorrect behavior. In this test, a window is closed after a tab, making the window the most recently closed session. Therefore, a call to `getRecentlyClosed` with `maxResults: 1` should return the window, not the tab.

          This test appears to validate the new logic in `sessions_api.cc` which may fail to fetch the window if the results list is already full of tabs. Since the API is documented to return sessions sorted by recency, this test should probably be changed to assert the correct behavior (i.e., that the window is returned).

          James Cook

          Done

          Open in Gerrit

          Related details

          Attention is currently required from:
          • Achuith Bhandarkar
          • Calder Kitagawa
          Submit Requirements:
          • requirement satisfiedCode-Coverage
          • requirement is not satisfiedCode-Owners
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: chromium/src
          Gerrit-Branch: main
          Gerrit-Change-Id: Ib6295d9f29dc9c7fdbcd75064ef01bb688cd6f07
          Gerrit-Change-Number: 7590176
          Gerrit-PatchSet: 11
          Gerrit-Owner: James Cook <jame...@chromium.org>
          Gerrit-Reviewer: Achuith Bhandarkar <ach...@chromium.org>
          Gerrit-Reviewer: Calder Kitagawa <ckit...@chromium.org>
          Gerrit-Reviewer: James Cook <jame...@chromium.org>
          Gerrit-CC: Zoraiz Naeem <zorai...@chromium.org>
          Gerrit-Attention: Achuith Bhandarkar <ach...@chromium.org>
          Gerrit-Attention: Calder Kitagawa <ckit...@chromium.org>
          Gerrit-Comment-Date: Fri, 20 Feb 2026 01:12:17 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: No
          Comment-In-Reply-To: Achuith Bhandarkar <ach...@chromium.org>
          satisfied_requirement
          unsatisfied_requirement
          open
          diffy

          Achuith Bhandarkar (Gerrit)

          unread,
          Feb 19, 2026, 8:44:30 PM (5 hours ago) Feb 19
          to James Cook, Calder Kitagawa, Zoraiz Naeem, Chromium LUCI CQ, chromium...@chromium.org, chromium-a...@chromium.org, extension...@chromium.org
          Attention needed from Calder Kitagawa and James Cook

          Achuith Bhandarkar added 1 comment

          File chrome/browser/extensions/api/sessions/sessions_api.cc
          Line 432, Patchset 11 (Latest): base::android::JavaRef<jobject>::CreateLeaky(env, tab_model);
          Achuith Bhandarkar . unresolved

          My Java is also pretty weak. Is it possible to use
          `base::android::ScopedJavaLocalRef<jobject> j_tab_model(env, tab_model);`

          instead of the leaky reference to delete j_tab_model? Also in `SessionsRestoreFunction::OnGetRecentlyClosedWindow`.

          Open in Gerrit

          Related details

          Attention is currently required from:
          • Calder Kitagawa
          • James Cook
          Submit Requirements:
          • requirement satisfiedCode-Coverage
          • requirement is not satisfiedCode-Owners
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: chromium/src
          Gerrit-Branch: main
          Gerrit-Change-Id: Ib6295d9f29dc9c7fdbcd75064ef01bb688cd6f07
          Gerrit-Change-Number: 7590176
          Gerrit-PatchSet: 11
          Gerrit-Owner: James Cook <jame...@chromium.org>
          Gerrit-Reviewer: Achuith Bhandarkar <ach...@chromium.org>
          Gerrit-Reviewer: Calder Kitagawa <ckit...@chromium.org>
          Gerrit-Reviewer: James Cook <jame...@chromium.org>
          Gerrit-CC: Zoraiz Naeem <zorai...@chromium.org>
          Gerrit-Attention: James Cook <jame...@chromium.org>
          Gerrit-Attention: Calder Kitagawa <ckit...@chromium.org>
          Gerrit-Comment-Date: Fri, 20 Feb 2026 01:44:23 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: No
          satisfied_requirement
          unsatisfied_requirement
          open
          diffy

          Achuith Bhandarkar (Gerrit)

          unread,
          Feb 19, 2026, 8:45:16 PM (5 hours ago) Feb 19
          to James Cook, Calder Kitagawa, Zoraiz Naeem, Chromium LUCI CQ, chromium...@chromium.org, chromium-a...@chromium.org, extension...@chromium.org
          Attention needed from Calder Kitagawa and James Cook

          Achuith Bhandarkar voted and added 1 comment

          Votes added by Achuith Bhandarkar

          Code-Review+1

          1 comment

          Patchset-level comments
          Achuith Bhandarkar . resolved

          lgtm modulo Calder's feedback

          Open in Gerrit

          Related details

          Attention is currently required from:
          • Calder Kitagawa
          • James Cook
          Submit Requirements:
            • requirement satisfiedCode-Coverage
            • requirement is not satisfiedCode-Owners
            • requirement satisfiedCode-Review
            • requirement is not satisfiedNo-Unresolved-Comments
            • requirement satisfiedReview-Enforcement
            Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
            Gerrit-MessageType: comment
            Gerrit-Project: chromium/src
            Gerrit-Branch: main
            Gerrit-Change-Id: Ib6295d9f29dc9c7fdbcd75064ef01bb688cd6f07
            Gerrit-Change-Number: 7590176
            Gerrit-PatchSet: 11
            Gerrit-Owner: James Cook <jame...@chromium.org>
            Gerrit-Reviewer: Achuith Bhandarkar <ach...@chromium.org>
            Gerrit-Reviewer: Calder Kitagawa <ckit...@chromium.org>
            Gerrit-Reviewer: James Cook <jame...@chromium.org>
            Gerrit-CC: Zoraiz Naeem <zorai...@chromium.org>
            Gerrit-Attention: James Cook <jame...@chromium.org>
            Gerrit-Attention: Calder Kitagawa <ckit...@chromium.org>
            Gerrit-Comment-Date: Fri, 20 Feb 2026 01:45:09 +0000
            Gerrit-HasComments: Yes
            Gerrit-Has-Labels: Yes
            satisfied_requirement
            unsatisfied_requirement
            open
            diffy
            Reply all
            Reply to author
            Forward
            0 new messages