blob: f623d33ce3f49ded4e62907a95ac1e3a4c83423b [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
Sergei Datsenko3554b9e42018-12-18 05:49:118#include "base/component_export.h"
Arthur Sonzognid8468bb2023-04-21 19:36:499#include "base/memory/raw_ptr.h"
Sergei Datsenko3554b9e42018-12-18 05:49:1110#include "base/memory/weak_ptr.h"
11#include "base/time/clock.h"
Gabriel Charetted87f10f2022-03-31 00:44:2212#include "base/time/time.h"
Henrique Ferreiro197812962022-08-22 23:51:1013#include "chromeos/ash/components/drivefs/mojom/drivefs.mojom.h"
mlcuif8792b92024-08-12 09:58:2214#include "mojo/public/cpp/bindings/pending_receiver.h"
Sergei Datsenko3554b9e42018-12-18 05:49:1115
Robbie McElrathb0acd132019-02-05 18:11:3716namespace network {
17class NetworkConnectionTracker;
18}
19
Sergei Datsenko3554b9e42018-12-18 05:49:1120namespace drivefs {
21
22// Handles search queries to DriveFS.
Henrique Ferreiro197812962022-08-22 23:51:1023class COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_DRIVEFS) DriveFsSearch {
Sergei Datsenko3554b9e42018-12-18 05:49:1124 public:
Robbie McElrathb0acd132019-02-05 18:11:3725 DriveFsSearch(mojom::DriveFs* drivefs,
26 network::NetworkConnectionTracker* network_connection_tracker,
27 const base::Clock* clock);
Peter Boströmec31a042021-09-16 23:37:3428
29 DriveFsSearch(const DriveFsSearch&) = delete;
30 DriveFsSearch& operator=(const DriveFsSearch&) = delete;
31
Sergei Datsenko3554b9e42018-12-18 05:49:1132 ~DriveFsSearch();
33
34 // Starts DriveFs search query and returns whether it will be
35 // performed localy or remotely. Assumes DriveFS to be mounted.
36 mojom::QueryParameters::QuerySource PerformSearch(
37 mojom::QueryParametersPtr query,
38 mojom::SearchQuery::GetNextPageCallback callback);
39
mlcuif8792b92024-08-12 09:58:2240 // Used by `DriveFsSearchQuery`.
41 // TODO: b/357980197 - Move these out to a delegate interface, and consider
42 // abstracting away the offline / cached query adjustment.
43 bool IsOffline();
Sergei Datsenko3554b9e42018-12-18 05:49:1144
mlcuif8792b92024-08-12 09:58:2245 void UpdateLastSharedWithMeResponse();
46 bool WithinQueryCacheTtl();
47
48 void StartMojoSearchQuery(mojo::PendingReceiver<mojom::SearchQuery> query,
49 mojom::QueryParametersPtr query_params);
50
51 private:
Bartek Nowierski6b2b6f5a2024-01-08 06:42:5752 const raw_ptr<mojom::DriveFs, DanglingUntriaged> drivefs_;
53 const raw_ptr<network::NetworkConnectionTracker> network_connection_tracker_;
54 const raw_ptr<const base::Clock> clock_;
Sergei Datsenko3554b9e42018-12-18 05:49:1155 base::Time last_shared_with_me_response_;
56
Jeremy Roman47d432e2019-08-20 14:24:0057 base::WeakPtrFactory<DriveFsSearch> weak_ptr_factory_{this};
Sergei Datsenko3554b9e42018-12-18 05:49:1158};
59
60} // namespace drivefs
61
Henrique Ferreiro197812962022-08-22 23:51:1062#endif // CHROMEOS_ASH_COMPONENTS_DRIVEFS_DRIVEFS_SEARCH_H_