drivefs_search.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_COMPONENTS_DRIVEFS_DRIVEFS_SEARCH_H_
  5. #define ASH_COMPONENTS_DRIVEFS_DRIVEFS_SEARCH_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "ash/components/drivefs/mojom/drivefs.mojom.h"
  10. #include "base/component_export.h"
  11. #include "base/memory/weak_ptr.h"
  12. #include "base/time/clock.h"
  13. #include "base/time/time.h"
  14. #include "mojo/public/cpp/bindings/remote.h"
  15. #include "third_party/abseil-cpp/absl/types/optional.h"
  16. namespace network {
  17. class NetworkConnectionTracker;
  18. }
  19. namespace drivefs {
  20. // Handles search queries to DriveFS.
  21. class COMPONENT_EXPORT(DRIVEFS) DriveFsSearch {
  22. public:
  23. DriveFsSearch(mojom::DriveFs* drivefs,
  24. network::NetworkConnectionTracker* network_connection_tracker,
  25. const base::Clock* clock);
  26. DriveFsSearch(const DriveFsSearch&) = delete;
  27. DriveFsSearch& operator=(const DriveFsSearch&) = delete;
  28. ~DriveFsSearch();
  29. // Starts DriveFs search query and returns whether it will be
  30. // performed localy or remotely. Assumes DriveFS to be mounted.
  31. mojom::QueryParameters::QuerySource PerformSearch(
  32. mojom::QueryParametersPtr query,
  33. mojom::SearchQuery::GetNextPageCallback callback);
  34. private:
  35. void OnSearchDriveFs(
  36. mojo::Remote<drivefs::mojom::SearchQuery> search,
  37. drivefs::mojom::QueryParametersPtr query,
  38. mojom::SearchQuery::GetNextPageCallback callback,
  39. drive::FileError error,
  40. absl::optional<std::vector<drivefs::mojom::QueryItemPtr>> items);
  41. mojom::DriveFs* const drivefs_;
  42. network::NetworkConnectionTracker* const network_connection_tracker_;
  43. const base::Clock* const clock_;
  44. base::Time last_shared_with_me_response_;
  45. base::WeakPtrFactory<DriveFsSearch> weak_ptr_factory_{this};
  46. };
  47. } // namespace drivefs
  48. #endif // ASH_COMPONENTS_DRIVEFS_DRIVEFS_SEARCH_H_