Home | History | Annotate | Download | only in storage_monitor
      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 
      5 #ifndef COMPONENTS_STORAGE_MONITOR_TEST_STORAGE_MONITOR_H_
      6 #define COMPONENTS_STORAGE_MONITOR_TEST_STORAGE_MONITOR_H_
      7 
      8 #include <string>
      9 
     10 #include "components/storage_monitor/storage_monitor.h"
     11 
     12 namespace storage_monitor {
     13 
     14 class TestStorageMonitor : public StorageMonitor {
     15  public:
     16   TestStorageMonitor();
     17   virtual ~TestStorageMonitor();
     18 
     19   virtual void Init() OVERRIDE;
     20 
     21   void MarkInitialized();
     22 
     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 
     29   // Create and initialize a new TestStorageMonitor and install it
     30   // as the StorageMonitor singleton. TestStorageMonitor is returned for
     31   // convenience. Use |Destroy| to delete the singleton.
     32   static TestStorageMonitor* CreateForBrowserTests();
     33 
     34   // Synchronously initialize the current storage monitor.
     35   static void SyncInitialize();
     36 
     37   virtual bool GetStorageInfoForPath(
     38       const base::FilePath& path,
     39       StorageInfo* device_info) const OVERRIDE;
     40 
     41 #if defined(OS_WIN)
     42   virtual bool GetMTPStorageInfoFromDeviceId(
     43       const std::string& storage_device_id,
     44       base::string16* device_location,
     45       base::string16* storage_object_id) const OVERRIDE;
     46 #endif
     47 
     48 #if defined(OS_LINUX)
     49   virtual device::MediaTransferProtocolManager*
     50       media_transfer_protocol_manager() OVERRIDE;
     51 #endif
     52 
     53   virtual Receiver* receiver() const OVERRIDE;
     54 
     55   virtual void EjectDevice(
     56       const std::string& device_id,
     57       base::Callback<void(StorageMonitor::EjectStatus)> callback)
     58       OVERRIDE;
     59 
     60   const std::string& ejected_device() const { return ejected_device_; }
     61 
     62   bool init_called() const { return init_called_; }
     63 
     64  private:
     65   // Whether TestStorageMonitor::Init() has been called for not.
     66   bool init_called_;
     67 
     68   // The last device to be ejected.
     69   std::string ejected_device_;
     70 
     71 #if defined(OS_LINUX)
     72   scoped_ptr<device::MediaTransferProtocolManager>
     73       media_transfer_protocol_manager_;
     74 #endif
     75 };
     76 
     77 }  // namespace storage_monitor
     78 
     79 #endif  // COMPONENTS_STORAGE_MONITOR_TEST_STORAGE_MONITOR_H_
     80