blob: 7afbadcc357376fee4e9f62db1c1c3eab3be9051 [file] [log] [blame]
Avi Drissmane4714ce92022-09-12 21:41:581// Copyright 2018 The Chromium Authors
Sergei Datsenko3554b9e42018-12-18 05:49:112// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Henrique Ferreiro197812962022-08-22 23:51:105#ifndef CHROMEOS_ASH_COMPONENTS_DRIVEFS_DRIVEFS_SEARCH_H_
6#define CHROMEOS_ASH_COMPONENTS_DRIVEFS_DRIVEFS_SEARCH_H_
Sergei Datsenko3554b9e42018-12-18 05:49:117
mlcui3da57da52024-08-14 07:16:478#include <memory>
9
Sergei Datsenko3554b9e42018-12-18 05:49:1110#include "base/component_export.h"
Arthur Sonzognid8468bb2023-04-21 19:36:4911#include "base/memory/raw_ptr.h"
Sergei Datsenko3554b9e42018-12-18 05:49:1112#include "base/memory/weak_ptr.h"
13#include "base/time/clock.h"
Gabriel Charetted87f10f2022-03-31 00:44:2214#include "base/time/time.h"
mlcuif7101ed2024-08-12 09:58:3215#include "chromeos/ash/components/drivefs/drivefs_search_query_delegate.h"
Henrique Ferreiro197812962022-08-22 23:51:1016#include "chromeos/ash/components/drivefs/mojom/drivefs.mojom.h"
mlcuif8792b92024-08-12 09:58:2217#include "mojo/public/cpp/bindings/pending_receiver.h"
Sergei Datsenko3554b9e42018-12-18 05:49:1118
Robbie McElrathb0acd132019-02-05 18:11:3719namespace network {
20class NetworkConnectionTracker;
21}
22
Sergei Datsenko3554b9e42018-12-18 05:49:1123namespace drivefs {
24
mlcui3da57da52024-08-14 07:16:4725class DriveFsSearchQuery;
26
Sergei Datsenko3554b9e42018-12-18 05:49:1127// Handles search queries to DriveFS.
mlcuif7101ed2024-08-12 09:58:3228class COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_DRIVEFS) DriveFsSearch
29 : public DriveFsSearchQueryDelegate {
Sergei Datsenko3554b9e42018-12-18 05:49:1130 public:
Robbie McElrathb0acd132019-02-05 18:11:3731 DriveFsSearch(mojom::DriveFs* drivefs,
32 network::NetworkConnectionTracker* network_connection_tracker,
33 const base::Clock* clock);
Peter Boströmec31a042021-09-16 23:37:3434
35 DriveFsSearch(const DriveFsSearch&) = delete;
36 DriveFsSearch& operator=(const DriveFsSearch&) = delete;
37
mlcuif7101ed2024-08-12 09:58:3238 ~DriveFsSearch() override;
Sergei Datsenko3554b9e42018-12-18 05:49:1139
mlcui3da57da52024-08-14 07:16:4740 // Starts a new query, but does not call `GetNextPage`.
41 // The returned `DriveFsSearchQuery` can be destructed at any time to stop any
42 // in-flight `GetNextPage` calls.
43 std::unique_ptr<DriveFsSearchQuery> CreateQuery(
44 mojom::QueryParametersPtr query_params);
45
Sergei Datsenko3554b9e42018-12-18 05:49:1146 // Starts DriveFs search query and returns whether it will be
47 // performed localy or remotely. Assumes DriveFS to be mounted.
48 mojom::QueryParameters::QuerySource PerformSearch(
49 mojom::QueryParametersPtr query,
50 mojom::SearchQuery::GetNextPageCallback callback);
51
mlcuif7101ed2024-08-12 09:58:3252 // `DriveFsSearchQueryDelegate` overrides:
53 bool IsOffline() override;
Sergei Datsenko3554b9e42018-12-18 05:49:1154
mlcuif7101ed2024-08-12 09:58:3255 void UpdateLastSharedWithMeResponse() override;
56 bool WithinQueryCacheTtl() override;
mlcuif8792b92024-08-12 09:58:2257
58 void StartMojoSearchQuery(mojo::PendingReceiver<mojom::SearchQuery> query,
mlcuif7101ed2024-08-12 09:58:3259 mojom::QueryParametersPtr query_params) override;
mlcuif8792b92024-08-12 09:58:2260
61 private:
Bartek Nowierski6b2b6f5a2024-01-08 06:42:5762 const raw_ptr<mojom::DriveFs, DanglingUntriaged> drivefs_;
63 const raw_ptr<network::NetworkConnectionTracker> network_connection_tracker_;
64 const raw_ptr<const base::Clock> clock_;
Sergei Datsenko3554b9e42018-12-18 05:49:1165 base::Time last_shared_with_me_response_;
66
Jeremy Roman47d432e2019-08-20 14:24:0067 base::WeakPtrFactory<DriveFsSearch> weak_ptr_factory_{this};
Sergei Datsenko3554b9e42018-12-18 05:49:1168};
69
70} // namespace drivefs
71
Henrique Ferreiro197812962022-08-22 23:51:1072#endif // CHROMEOS_ASH_COMPONENTS_DRIVEFS_DRIVEFS_SEARCH_H_