Home | History | Annotate | Download | only in storage
      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 CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_VOLUME_LISTER_H_
      6 #define CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_VOLUME_LISTER_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/callback.h"
     12 #include "base/files/file_path.h"
     13 #include "base/memory/weak_ptr.h"
     14 
     15 #if defined(ENABLE_SERVICE_DISCOVERY)
     16 #include "chrome/browser/local_discovery/privet_device_lister.h"
     17 #include "chrome/browser/local_discovery/service_discovery_shared_client.h"
     18 #endif
     19 
     20 namespace local_discovery {
     21 
     22 // This class will eventually list all of the user's Privet storage devices,
     23 // but during prototyping phase searches the local network for Privet storage
     24 // devices.
     25 #if defined(ENABLE_SERVICE_DISCOVERY)
     26 class PrivetVolumeLister : public PrivetDeviceLister::Delegate {
     27 #else
     28 class PrivetVolumeLister {
     29 #endif
     30  public:
     31   struct VolumeInfo {
     32     std::string volume_id;
     33     std::string volume_label;
     34     base::FilePath volume_path;
     35   };
     36 
     37   typedef std::vector<VolumeInfo> VolumeList;
     38   typedef base::Callback<void(const VolumeList&)> ResultCallback;
     39 
     40   explicit PrivetVolumeLister(const ResultCallback& callback);
     41   virtual ~PrivetVolumeLister();
     42 
     43   void Start();
     44 
     45   const std::vector<VolumeInfo>& volume_list() const {
     46     return canonical_volume_list_;
     47   }
     48 
     49 #if defined(ENABLE_SERVICE_DISCOVERY)
     50   virtual void DeviceChanged(bool added,
     51                              const std::string& name,
     52                              const DeviceDescription& description) OVERRIDE;
     53   virtual void DeviceRemoved(const std::string& name) OVERRIDE;
     54   virtual void DeviceCacheFlushed() OVERRIDE;
     55 #endif
     56 
     57  private:
     58 #if defined(ENABLE_SERVICE_DISCOVERY)
     59   void FinishSearch();
     60 
     61   scoped_refptr<ServiceDiscoverySharedClient> service_discovery_client_;
     62   scoped_ptr<PrivetDeviceLister> privet_lister_;
     63 #endif
     64 
     65   std::vector<VolumeInfo> available_volumes_;
     66   std::vector<VolumeInfo> canonical_volume_list_;
     67   ResultCallback callback_;
     68   base::WeakPtrFactory<PrivetVolumeLister> weak_factory_;
     69 };
     70 
     71 }  // namespace local_discovery
     72 
     73 #endif  // CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_VOLUME_LISTER_H_
     74