Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.h

Issue 11744030: Try 2 [Media Gallery] Move chrome/browser/media_transfer_protocol code to src/device. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed gyp dependencies. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_MANAGER_H _
6 #define CHROME_BROWSER_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_MANAGER_H _
7
8 #include <string>
9 #include <vector>
10
11 #include "base/callback.h"
12 #include "build/build_config.h"
13
14 #if !defined(OS_LINUX)
15 #error "Only used on Linux and ChromeOS"
16 #endif
17
18 class MtpFileEntry;
19 class MtpStorageInfo;
20
21 namespace chrome {
22
23 // This class handles the interaction with mtpd.
24 // Other classes can add themselves as observers.
25 class MediaTransferProtocolManager {
26 public:
27 // A callback to handle the result of OpenStorage.
28 // The first argument is the returned handle.
29 // The second argument is true if there was an error.
30 typedef base::Callback<void(const std::string& handle,
31 bool error)> OpenStorageCallback;
32
33 // A callback to handle the result of CloseStorage.
34 // The argument is true if there was an error.
35 typedef base::Callback<void(bool error)> CloseStorageCallback;
36
37 // A callback to handle the result of ReadDirectoryByPath/Id.
38 // The first argument is a vector of file entries.
39 // The second argument is true if there was an error.
40 typedef base::Callback<void(const std::vector<MtpFileEntry>& file_entries,
41 bool error)> ReadDirectoryCallback;
42
43 // A callback to handle the result of ReadFileChunkByPath/Id.
44 // The first argument is a string containing the file data.
45 // The second argument is true if there was an error.
46 typedef base::Callback<void(const std::string& data,
47 bool error)> ReadFileCallback;
48
49 // A callback to handle the result of GetFileInfoByPath/Id.
50 // The first argument is a file entry.
51 // The second argument is true if there was an error.
52 typedef base::Callback<void(const MtpFileEntry& file_entry,
53 bool error)> GetFileInfoCallback;
54
55 // Implement this interface to be notified about MTP storage
56 // attachment / detachment events.
57 class Observer {
58 public:
59 virtual ~Observer() {}
60
61 // A function called after a MTP storage has been attached / detached.
62 virtual void StorageChanged(bool is_attached,
63 const std::string& storage_name) = 0;
64 };
65
66 virtual ~MediaTransferProtocolManager() {}
67
68 // Adds an observer.
69 virtual void AddObserver(Observer* observer) = 0;
70
71 // Removes an observer.
72 virtual void RemoveObserver(Observer* observer) = 0;
73
74 // Returns a vector of available MTP storages.
75 virtual const std::vector<std::string> GetStorages() const = 0;
76
77 // On success, returns the the metadata for |storage_name|.
78 // Otherwise returns NULL.
79 virtual const MtpStorageInfo* GetStorageInfo(
80 const std::string& storage_name) const = 0;
81
82 // Opens |storage_name| in |mode| and runs |callback|.
83 virtual void OpenStorage(const std::string& storage_name,
84 const std::string& mode,
85 const OpenStorageCallback& callback) = 0;
86
87 // Close |storage_handle| and runs |callback|.
88 virtual void CloseStorage(const std::string& storage_handle,
89 const CloseStorageCallback& callback) = 0;
90
91 // Reads directory entries from |path| on |storage_handle| and runs
92 // |callback|.
93 virtual void ReadDirectoryByPath(const std::string& storage_handle,
94 const std::string& path,
95 const ReadDirectoryCallback& callback) = 0;
96
97 // Reads directory entries from |file_id| on |storage_handle| and runs
98 // |callback|.
99 virtual void ReadDirectoryById(const std::string& storage_handle,
100 uint32 file_id,
101 const ReadDirectoryCallback& callback) = 0;
102
103 // Reads file data from |path| on |storage_handle| and runs |callback|.
104 // Reads |count| bytes of data starting at |offset|.
105 virtual void ReadFileChunkByPath(const std::string& storage_handle,
106 const std::string& path,
107 uint32 offset,
108 uint32 count,
109 const ReadFileCallback& callback) = 0;
110
111 // Reads file data from |file_id| on |storage_handle| and runs |callback|.
112 // Reads |count| bytes of data starting at |offset|.
113 virtual void ReadFileChunkById(const std::string& storage_handle,
114 uint32 file_id,
115 uint32 offset,
116 uint32 count,
117 const ReadFileCallback& callback) = 0;
118
119 // Gets the file metadata for |path| on |storage_handle| and runs |callback|.
120 virtual void GetFileInfoByPath(const std::string& storage_handle,
121 const std::string& path,
122 const GetFileInfoCallback& callback) = 0;
123
124 // Gets the file metadata for |file_id| on |storage_handle| and runs
125 // |callback|.
126 virtual void GetFileInfoById(const std::string& storage_handle,
127 uint32 file_id,
128 const GetFileInfoCallback& callback) = 0;
129
130 // Creates the global MediaTransferProtocolManager instance.
131 static void Initialize();
132
133 // Destroys the global MediaTransferProtocolManager instance if it exists.
134 static void Shutdown();
135
136 // Returns a pointer to the global MediaTransferProtocolManager instance.
137 // Initialize() should already have been called.
138 static MediaTransferProtocolManager* GetInstance();
139 };
140
141 } // namespace chrome
142
143 #endif // CHROME_BROWSER_MEDIA_TRANSFER_PROTOCOL_MEDIA_TRANSFER_PROTOCOL_MANAGE R_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698