ios/chrome/browser/intelligence/zero_state_suggestions/README.md
The Zero-State Suggestions module provides contextual prompt suggestions (such as query chips or Gemini command shortcuts) for a given web state in Chrome for iOS. It serves as an asynchronous bridge between iOS navigation events, Mojo IPC interfaces, and the Chromium Optimization Guide backend.
When a page is eligible for suggestions, this component can be queried to fetch suggestions tailored specifically to the current page's context.
graph TD
A[GeminiTabHelper] -->|Mojo IPC| B[ZeroStateSuggestionsServiceImpl]
B -->|Asynchronously Fetches| C[PageContextWrapper]
B -->|Executes LLM Model| D[OptimizationGuideService]
Below is the sequence of operations triggered when suggestions are requested for the current page:
sequenceDiagram
autonumber
participant Client as GeminiTabHelper
participant Mojo as ZeroStateSuggestionsServiceImpl
participant Wrapper as PageContextWrapper
participant OptGuide as OptimizationGuideService
Client->>Mojo: FetchZeroStateSuggestions()
alt Ongoing request for SAME page
Mojo->>Mojo: Chains callback via RunChainedCallbacks()
else New request for DIFFERENT page
Mojo->>Mojo: CancelOngoingRequests() (Invalidates weak pointers)
end
Mojo->>Wrapper: initWithWebState:completionCallback:
Note over Wrapper: Extracts page URL, Title & innerText async
Wrapper-->>Mojo: OnPageContextGenerated(proto::PageContext)
Mojo->>OptGuide: ExecuteModel(kZeroStateSuggestions, request)
Note over OptGuide: 5-second timeout (kModelExecutionTimeout)
OptGuide-->>Mojo: OnZeroStateSuggestionsResponse(result, entry)
Mojo-->>Client: Run pending callback(s) with suggestion proto / error
Note over Client: Caches suggestion labels in memory for current GURL
Each file in the zero-state suggestions directory has a distinct, single responsibility:
ai::ZeroStateSuggestionsServiceImpl class, which inherits from ai::mojom::ZeroStateSuggestionsService. It defines the service interface, public callbacks, Mojo receiver management, and weak pointer factories.PageContextWrapper.OptimizationGuideService with model execution timeout parameters (5 seconds).RunChainedCallbacks).PageContextWrapper).FakeOptimizationGuideService to simulate successful model execution yields and error returns.web::WebState is destroyed before suggestions could be retrieved.