drivefs_search: Split search logic into separate query class

This is in preparation for allowing cancellation of DriveFS search
queries.

At the moment, all queries made by `DriveFsSearch::PerformSearch` are
never cancelled, as the `drivefs::mojom::SearchQuery` (now wrapped in a
`drivefs::DriveFsSearchQuery`) are "smuggled into" the `GetNextPage`
callback, ensuring that it will live until `GetNextPage` is called.

In a future CL (https://crrev.com/c/5769158), we will return this
`DriveFsSearchQuery` class so callers can cancel any search queries by
destroying the `DriveFsSearchQuery` if needed.

This query class currently takes in a pointer to the parent
`DriveFsSearch`, which is difficult to test - the tests would be
near-identical to the existing tests in `drivefs_search_unittest.cc`. A
future CL (https://crrev.com/c/5769157) will refactor this to take in a
pointer to a delegate instead, and introduce tests.

Bug: b:357980197
Change-Id: I6a6a21004a571f1053e631dd4c6a813c61ef3ce4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5769156
Reviewed-by: Austin Tankiang <[email protected]>
Commit-Queue: Michael Cui <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1340285}
diff --git a/chromeos/ash/components/drivefs/drivefs_search.h b/chromeos/ash/components/drivefs/drivefs_search.h
index fbcdb82..f623d33 100644
--- a/chromeos/ash/components/drivefs/drivefs_search.h
+++ b/chromeos/ash/components/drivefs/drivefs_search.h
@@ -5,18 +5,13 @@
 #ifndef CHROMEOS_ASH_COMPONENTS_DRIVEFS_DRIVEFS_SEARCH_H_
 #define CHROMEOS_ASH_COMPONENTS_DRIVEFS_DRIVEFS_SEARCH_H_
 
-#include <memory>
-#include <optional>
-#include <string>
-#include <vector>
-
 #include "base/component_export.h"
 #include "base/memory/raw_ptr.h"
 #include "base/memory/weak_ptr.h"
 #include "base/time/clock.h"
 #include "base/time/time.h"
 #include "chromeos/ash/components/drivefs/mojom/drivefs.mojom.h"
-#include "mojo/public/cpp/bindings/remote.h"
+#include "mojo/public/cpp/bindings/pending_receiver.h"
 
 namespace network {
 class NetworkConnectionTracker;
@@ -42,14 +37,18 @@
       mojom::QueryParametersPtr query,
       mojom::SearchQuery::GetNextPageCallback callback);
 
- private:
-  void OnSearchDriveFs(
-      mojo::Remote<drivefs::mojom::SearchQuery> search,
-      drivefs::mojom::QueryParametersPtr query,
-      mojom::SearchQuery::GetNextPageCallback callback,
-      drive::FileError error,
-      std::optional<std::vector<drivefs::mojom::QueryItemPtr>> items);
+  // Used by `DriveFsSearchQuery`.
+  // TODO: b/357980197 - Move these out to a delegate interface, and consider
+  // abstracting away the offline / cached query adjustment.
+  bool IsOffline();
 
+  void UpdateLastSharedWithMeResponse();
+  bool WithinQueryCacheTtl();
+
+  void StartMojoSearchQuery(mojo::PendingReceiver<mojom::SearchQuery> query,
+                            mojom::QueryParametersPtr query_params);
+
+ private:
   const raw_ptr<mojom::DriveFs, DanglingUntriaged> drivefs_;
   const raw_ptr<network::NetworkConnectionTracker> network_connection_tracker_;
   const raw_ptr<const base::Clock> clock_;