test_storage_monitor.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 2014 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 COMPONENTS_STORAGE_MONITOR_TEST_STORAGE_MONITOR_H_
  5. #define COMPONENTS_STORAGE_MONITOR_TEST_STORAGE_MONITOR_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "build/build_config.h"
  10. #include "build/chromeos_buildflags.h"
  11. #include "components/storage_monitor/storage_monitor.h"
  12. #if BUILDFLAG(IS_CHROMEOS_ASH)
  13. #include "mojo/public/cpp/bindings/remote.h"
  14. #include "services/device/public/mojom/mtp_manager.mojom.h"
  15. #endif
  16. namespace storage_monitor {
  17. class TestStorageMonitor : public StorageMonitor {
  18. public:
  19. TestStorageMonitor();
  20. ~TestStorageMonitor() override;
  21. void Init() override;
  22. void MarkInitialized();
  23. // Create and initialize a new TestStorageMonitor and install it
  24. // as the StorageMonitor singleton. If there is a StorageMonitor instance
  25. // already in place, NULL is returned, otherwise the TestStorageMonitor
  26. // instance is returned. Use |Destroy| to delete the singleton.
  27. static TestStorageMonitor* CreateAndInstall();
  28. // Create and initialize a new TestStorageMonitor and install it
  29. // as the StorageMonitor singleton. TestStorageMonitor is returned for
  30. // convenience. Use |Destroy| to delete the singleton.
  31. static TestStorageMonitor* CreateForBrowserTests();
  32. // Synchronously initialize the current storage monitor.
  33. static void SyncInitialize();
  34. bool GetStorageInfoForPath(const base::FilePath& path,
  35. StorageInfo* device_info) const override;
  36. #if BUILDFLAG(IS_WIN)
  37. bool GetMTPStorageInfoFromDeviceId(
  38. const std::string& storage_device_id,
  39. std::wstring* device_location,
  40. std::wstring* storage_object_id) const override;
  41. #endif
  42. #if BUILDFLAG(IS_CHROMEOS_ASH)
  43. device::mojom::MtpManager* media_transfer_protocol_manager() override;
  44. #endif
  45. Receiver* receiver() const override;
  46. void EjectDevice(
  47. const std::string& device_id,
  48. base::OnceCallback<void(StorageMonitor::EjectStatus)> callback) override;
  49. const std::string& ejected_device() const { return ejected_device_; }
  50. void AddRemovablePath(const base::FilePath& path);
  51. bool init_called() const { return init_called_; }
  52. private:
  53. // Whether TestStorageMonitor::Init() has been called for not.
  54. bool init_called_;
  55. // The last device to be ejected.
  56. std::string ejected_device_;
  57. // Paths considered for testing purposes to be on removable storage.
  58. std::vector<base::FilePath> removable_paths_;
  59. #if BUILDFLAG(IS_CHROMEOS_ASH)
  60. mojo::Remote<device::mojom::MtpManager> media_transfer_protocol_manager_;
  61. #endif
  62. };
  63. } // namespace storage_monitor
  64. #endif // COMPONENTS_STORAGE_MONITOR_TEST_STORAGE_MONITOR_H_