1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_STORAGE_NOTIFICATIONS_H_
#define CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_STORAGE_NOTIFICATIONS_H_
#include "base/file_path.h"
#include "base/observer_list_threadsafe.h"
#include "base/string16.h"
#include "base/synchronization/lock.h"
class ChromeBrowserMainPartsLinux;
class ChromeBrowserMainPartsMac;
class MediaGalleriesPrivateApiTest;
namespace chrome {
class MediaFileSystemRegistryTest;
class RemovableStorageObserver;
// Base class for platform-specific instances watching for removable storage
// attachments/detachments.
class RemovableStorageNotifications {
public:
struct StorageInfo {
StorageInfo();
StorageInfo(const std::string& id,
const string16& device_name,
const base::FilePath::StringType& device_location);
// Unique device id - persists between device attachments.
std::string device_id;
// Human readable removable storage device name.
string16 name;
// Current attached removable storage device location.
base::FilePath::StringType location;
};
// This interface is provided to generators of storage notifications.
class Receiver {
public:
virtual ~Receiver();
virtual void ProcessAttach(const std::string& id,
const string16& name,
const base::FilePath::StringType& location) = 0;
virtual void ProcessDetach(const std::string& id) = 0;
};
// Returns a pointer to an object owned by the BrowserMainParts, with lifetime
// somewhat shorter than a process Singleton.
static RemovableStorageNotifications* GetInstance();
// Finds the device that contains |path| and populates |device_info|.
// Should be able to handle any path on the local system, not just removable
// storage. Returns false if unable to find the device.
virtual bool GetDeviceInfoForPath(
const base::FilePath& path,
StorageInfo* device_info) const = 0;
// Returns the storage size of the device present at |location|. If the
// device information is unavailable, returns zero.
virtual uint64 GetStorageSize(const std::string& location) const = 0;
#if defined(OS_WIN)
// Gets the MTP device storage information specified by |storage_device_id|.
// On success, returns true and fills in |device_location| with device
// interface details and |storage_object_id| with the string ID that
// uniquely identifies the object on the device. This ID need not be
// persistent across sessions.
virtual bool GetMTPStorageInfoFromDeviceId(
const std::string& storage_device_id,
string16* device_location,
string16* storage_object_id) const = 0;
#endif
// Returns information for attached removable storage.
std::vector<StorageInfo> GetAttachedStorage() const;
void AddObserver(RemovableStorageObserver* obs);
void RemoveObserver(RemovableStorageObserver* obs);
protected:
RemovableStorageNotifications();
virtual ~RemovableStorageNotifications();
// TODO(gbillock): Clean up ownerships and get rid of these friends.
friend class ::ChromeBrowserMainPartsLinux;
friend class ::ChromeBrowserMainPartsMac;
friend class ::MediaGalleriesPrivateApiTest;
friend class MediaFileSystemRegistryTest;
virtual Receiver* receiver() const;
private:
class ReceiverImpl;
friend class ReceiverImpl;
typedef std::map<std::string, StorageInfo> RemovableStorageMap;
void ProcessAttach(const StorageInfo& storage);
void ProcessDetach(const std::string& id);
scoped_ptr<Receiver> receiver_;
scoped_refptr<ObserverListThreadSafe<RemovableStorageObserver> >
observer_list_;
// For manipulating removable_storage_map_ structure.
mutable base::Lock storage_lock_;
// Map of all the attached removable storage devices.
RemovableStorageMap storage_map_;
};
} // namespace chrome
#endif // CHROME_BROWSER_SYSTEM_MONITOR_REMOVABLE_STORAGE_NOTIFICATIONS_H_
|