|
OLD | NEW |
---|---|
(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 #include "chromeos/dbus/mtpd_client.h" | |
6 | |
7 #include <map> | |
8 | |
9 #include "base/bind.h" | |
10 #include "base/stl_util.h" | |
11 #include "base/stringprintf.h" | |
12 #include "dbus/bus.h" | |
13 #include "dbus/message.h" | |
14 #include "dbus/object_path.h" | |
15 #include "dbus/object_proxy.h" | |
16 #include "third_party/cros_system_api/dbus/service_constants.h" | |
17 | |
18 namespace chromeos { | |
19 | |
20 namespace { | |
21 | |
22 // Pops a string value when |reader| is not NULL. | |
23 // Returns true when a value is popped, false otherwise. | |
24 bool MaybePopString(dbus::MessageReader* reader, std::string* value) { | |
25 if (!reader) | |
26 return false; | |
27 return reader->PopString(value); | |
28 } | |
29 | |
30 // Pops a uint16 value when |reader| is not NULL. | |
31 // Returns true when a value is popped, false otherwise. | |
32 bool MaybePopUint16(dbus::MessageReader* reader, uint16* value) { | |
33 if (!reader) | |
34 return false; | |
35 return reader->PopUint16(value); | |
36 } | |
37 | |
38 // Pops a uint32 value when |reader| is not NULL. | |
39 // Returns true when a value is popped, false otherwise. | |
40 bool MaybePopUint32(dbus::MessageReader* reader, uint32* value) { | |
41 if (!reader) | |
42 return false; | |
43 return reader->PopUint32(value); | |
44 } | |
45 | |
46 // Pops a uint64 value when |reader| is not NULL. | |
47 // Returns true when a value is popped, false otherwise. | |
48 bool MaybePopUint64(dbus::MessageReader* reader, uint64* value) { | |
49 if (!reader) | |
50 return false; | |
51 return reader->PopUint64(value); | |
52 } | |
53 | |
54 // Pops a int64 value when |reader| is not NULL. | |
55 // Returns true when a value is popped, false otherwise. | |
56 bool MaybePopInt64(dbus::MessageReader* reader, int64* value) { | |
57 if (!reader) | |
58 return false; | |
59 return reader->PopInt64(value); | |
60 } | |
61 | |
62 // The MTPDClient implementation. | |
63 class MTPDClientImpl : public MTPDClient { | |
64 public: | |
65 // TODO(thestig) Use mtpd::kMTPDServiceName and mtpd::kMTPDServicePath below. | |
66 explicit MTPDClientImpl(dbus::Bus* bus) | |
67 : proxy_(bus->GetObjectProxy( | |
68 "org.chromium.MTPD", | |
satorux1
2012/08/03 05:26:07
Constants like this should be defined in service_c
Lei Zhang
2012/08/03 06:29:30
I should have it fixed tomorrow once I get the con
| |
69 dbus::ObjectPath("/org/chromium/MTPD"))), | |
70 weak_ptr_factory_(this) { | |
71 } | |
72 | |
73 // MTPDClient override. | |
74 virtual void EnumerateStorage(const EnumerateStorageCallback& callback, | |
75 const ErrorCallback& error_callback) OVERRIDE { | |
76 // TODO(thestig) Use constants here. | |
77 dbus::MethodCall method_call("org.chromium.MTPD", "EnumerateStorage"); | |
78 proxy_->CallMethod( | |
79 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
80 base::Bind(&MTPDClientImpl::OnEnumerateStorage, | |
81 weak_ptr_factory_.GetWeakPtr(), | |
82 callback, | |
83 error_callback)); | |
84 } | |
85 | |
86 // MTPDClient override. | |
87 virtual void GetStorageInfo(const std::string& storage_name, | |
88 const GetStorageInfoCallback& callback, | |
89 const ErrorCallback& error_callback) OVERRIDE { | |
90 // TODO(thestig) Use constants here. | |
91 dbus::MethodCall method_call("org.chromium.MTPD", "GetStorageInfo"); | |
92 dbus::MessageWriter writer(&method_call); | |
93 writer.AppendString(storage_name); | |
94 proxy_->CallMethod(&method_call, | |
95 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
96 base::Bind(&MTPDClientImpl::OnGetStorageInfo, | |
97 weak_ptr_factory_.GetWeakPtr(), | |
98 storage_name, | |
99 callback, | |
100 error_callback)); | |
101 } | |
102 | |
103 // MTPDClient override. | |
104 virtual void OpenStorage(const std::string& storage_name, | |
105 OpenStorageMode mode, | |
106 const OpenStorageCallback& callback, | |
107 const ErrorCallback& error_callback) OVERRIDE { | |
108 // TODO(thestig) Use constants here. | |
109 dbus::MethodCall method_call("org.chromium.MTPD", "OpenStorage"); | |
110 dbus::MessageWriter writer(&method_call); | |
111 writer.AppendString(storage_name); | |
112 DCHECK_EQ(OPEN_STORAGE_MODE_READ_ONLY, mode); | |
113 // TODO(thestig) Use constants here. | |
114 writer.AppendString("readonly"); | |
115 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
116 base::Bind(&MTPDClientImpl::OnOpenStorage, | |
117 weak_ptr_factory_.GetWeakPtr(), | |
118 callback, | |
119 error_callback)); | |
120 } | |
121 | |
122 // MTPDClient override. | |
123 virtual void CloseStorage(const std::string& handle, | |
124 const CloseStorageCallback& callback, | |
125 const ErrorCallback& error_callback) OVERRIDE { | |
126 // TODO(thestig) Use constants here. | |
127 dbus::MethodCall method_call("org.chromium.MTPD", "CloseStorage"); | |
128 dbus::MessageWriter writer(&method_call); | |
129 writer.AppendString(handle); | |
130 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
131 base::Bind(&MTPDClientImpl::OnCloseStorage, | |
132 weak_ptr_factory_.GetWeakPtr(), | |
133 callback, | |
134 error_callback)); | |
135 } | |
136 | |
137 virtual void ReadDirectoryByPath( | |
satorux1
2012/08/03 05:26:07
// MTPDClient override.
Lei Zhang
2012/08/03 06:29:30
Done.
| |
138 const std::string& handle, | |
139 const std::string& path, | |
140 const ReadDirectoryCallback& callback, | |
141 const ErrorCallback& error_callback) OVERRIDE { | |
142 // TODO(thestig) Use constants here. | |
143 dbus::MethodCall method_call("org.chromium.MTPD", "ReadDirectoryByPath"); | |
144 dbus::MessageWriter writer(&method_call); | |
145 writer.AppendString(handle); | |
146 writer.AppendString(path); | |
147 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
148 base::Bind(&MTPDClientImpl::OnReadDirectory, | |
149 weak_ptr_factory_.GetWeakPtr(), | |
150 callback, | |
151 error_callback)); | |
152 } | |
153 | |
154 virtual void ReadDirectoryById( | |
satorux1
2012/08/03 05:26:07
// MTPDClient override.
Lei Zhang
2012/08/03 06:29:30
Done.
| |
155 const std::string& handle, | |
156 uint32 file_id, | |
157 const ReadDirectoryCallback& callback, | |
158 const ErrorCallback& error_callback) OVERRIDE { | |
159 // TODO(thestig) Use constants here. | |
160 dbus::MethodCall method_call("org.chromium.MTPD", "ReadDirectoryById"); | |
161 dbus::MessageWriter writer(&method_call); | |
162 writer.AppendString(handle); | |
163 writer.AppendUint32(file_id); | |
164 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
165 base::Bind(&MTPDClientImpl::OnReadDirectory, | |
166 weak_ptr_factory_.GetWeakPtr(), | |
167 callback, | |
168 error_callback)); | |
169 } | |
170 | |
171 // MTPDClient override. | |
172 virtual void ReadFileByPath(const std::string& handle, | |
173 const std::string& path, | |
174 const ReadFileCallback& callback, | |
175 const ErrorCallback& error_callback) OVERRIDE { | |
176 // TODO(thestig) Use constants here. | |
177 dbus::MethodCall method_call("org.chromium.MTPD", "ReadFileByPath"); | |
178 dbus::MessageWriter writer(&method_call); | |
179 writer.AppendString(handle); | |
180 writer.AppendString(path); | |
181 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
182 base::Bind(&MTPDClientImpl::OnReadFile, | |
183 weak_ptr_factory_.GetWeakPtr(), | |
184 callback, | |
185 error_callback)); | |
186 } | |
187 | |
188 // MTPDClient override. | |
189 virtual void ReadFileById(const std::string& handle, | |
190 uint32 file_id, | |
191 const ReadFileCallback& callback, | |
192 const ErrorCallback& error_callback) OVERRIDE { | |
193 // TODO(thestig) Use constants here. | |
194 dbus::MethodCall method_call("org.chromium.MTPD", "ReadFileById"); | |
195 dbus::MessageWriter writer(&method_call); | |
196 writer.AppendString(handle); | |
197 writer.AppendUint32(file_id); | |
198 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
199 base::Bind(&MTPDClientImpl::OnReadFile, | |
200 weak_ptr_factory_.GetWeakPtr(), | |
201 callback, | |
202 error_callback)); | |
203 } | |
204 | |
205 // MTPDClient override. | |
206 virtual void SetUpConnections( | |
207 const MTPStorageEventHandler& handler) OVERRIDE { | |
208 static const SignalEventTuple kSignalEventTuples[] = { | |
209 // TODO(thestig) Use constants. | |
210 { "MTPStorageAttached", true }, | |
211 { "MTPStorageDetached", false }, | |
212 }; | |
213 const size_t kNumSignalEventTuples = arraysize(kSignalEventTuples); | |
214 | |
215 for (size_t i = 0; i < kNumSignalEventTuples; ++i) { | |
216 // TODO(thestig) Use mtpd::kMTPDInterface here. | |
217 proxy_->ConnectToSignal( | |
218 "org.chromium.MTPD", | |
219 kSignalEventTuples[i].signal_name, | |
220 base::Bind(&MTPDClientImpl::OnMTPStorageSignal, | |
221 weak_ptr_factory_.GetWeakPtr(), | |
222 handler, | |
223 kSignalEventTuples[i].is_attach), | |
224 base::Bind(&MTPDClientImpl::OnSignalConnected, | |
225 weak_ptr_factory_.GetWeakPtr())); | |
226 } | |
227 } | |
228 | |
229 private: | |
230 // A struct to contain a pair of signal name and attachment event type. | |
231 // Used by SetUpConnections. | |
232 struct SignalEventTuple { | |
233 const char *signal_name; | |
234 bool is_attach; | |
235 }; | |
236 | |
237 // Handles the result of EnumerateStorage and calls |callback| or | |
238 // |error_callback|. | |
239 void OnEnumerateStorage(const EnumerateStorageCallback& callback, | |
240 const ErrorCallback& error_callback, | |
241 dbus::Response* response) { | |
242 if (!response) { | |
243 error_callback.Run(); | |
244 return; | |
245 } | |
246 dbus::MessageReader reader(response); | |
247 std::vector<std::string> storage_names; | |
248 if (!reader.PopArrayOfStrings(&storage_names)) { | |
249 LOG(ERROR) << "Invalid response: " << response->ToString(); | |
250 error_callback.Run(); | |
251 return; | |
252 } | |
253 callback.Run(storage_names); | |
254 } | |
255 | |
256 // Handles the result of GetStorageInfo and calls |callback| or | |
257 // |error_callback|. | |
258 void OnGetStorageInfo(const std::string& storage_name, | |
259 const GetStorageInfoCallback& callback, | |
260 const ErrorCallback& error_callback, | |
261 dbus::Response* response) { | |
262 if (!response) { | |
263 error_callback.Run(); | |
264 return; | |
265 } | |
266 StorageInfo storage_info(storage_name, response); | |
267 callback.Run(storage_info); | |
268 } | |
269 | |
270 // Handles the result of OpenStorage and calls |callback| or |error_callback|. | |
271 void OnOpenStorage(const OpenStorageCallback& callback, | |
272 const ErrorCallback& error_callback, | |
273 dbus::Response* response) { | |
274 if (!response) { | |
275 error_callback.Run(); | |
276 return; | |
277 } | |
278 dbus::MessageReader reader(response); | |
279 std::string handle; | |
280 if (!reader.PopString(&handle)) { | |
281 LOG(ERROR) << "Invalid response: " << response->ToString(); | |
282 error_callback.Run(); | |
283 return; | |
284 } | |
285 callback.Run(handle); | |
286 } | |
287 | |
288 // Handles the result of CloseStorage and calls |callback| or | |
289 // |error_callback|. | |
290 void OnCloseStorage(const CloseStorageCallback& callback, | |
291 const ErrorCallback& error_callback, | |
292 dbus::Response* response) { | |
293 if (!response) { | |
294 error_callback.Run(); | |
295 return; | |
296 } | |
297 callback.Run(); | |
298 } | |
299 | |
300 // Handles the result of ReadDirectoryByPath/Id and calls |callback| or | |
301 // |error_callback|. | |
302 void OnReadDirectory(const ReadDirectoryCallback& callback, | |
303 const ErrorCallback& error_callback, | |
304 dbus::Response* response) { | |
305 if (!response) { | |
306 error_callback.Run(); | |
307 return; | |
308 } | |
309 | |
310 std::vector<FileEntry> file_entries; | |
311 dbus::MessageReader response_reader(response); | |
312 dbus::MessageReader array_reader(response); | |
313 if (!response_reader.PopArray(&array_reader)) { | |
314 LOG(ERROR) << "Invalid response: " << response->ToString(); | |
315 error_callback.Run(); | |
316 return; | |
317 } | |
318 while (array_reader.HasMoreData()) { | |
319 FileEntry entry(response); | |
320 file_entries.push_back(entry); | |
321 } | |
322 callback.Run(file_entries); | |
323 } | |
324 | |
325 // Handles the result of ReadFileByPath/Id and calls |callback| or | |
326 // |error_callback|. | |
327 void OnReadFile(const ReadFileCallback& callback, | |
328 const ErrorCallback& error_callback, | |
329 dbus::Response* response) { | |
330 if (!response) { | |
331 error_callback.Run(); | |
332 return; | |
333 } | |
334 | |
335 uint8* data_bytes = NULL; | |
336 size_t data_length = 0; | |
337 dbus::MessageReader reader(response); | |
338 if (!reader.PopArrayOfBytes(&data_bytes, &data_length)) { | |
339 error_callback.Run(); | |
340 return; | |
341 } | |
342 std::string data(reinterpret_cast<const char*>(data_bytes), data_length); | |
343 callback.Run(data); | |
344 } | |
345 | |
346 // Handles MTPStorageAttached/Dettached signals and calls |handler|. | |
347 void OnMTPStorageSignal(MTPStorageEventHandler handler, | |
348 bool is_attach, | |
349 dbus::Signal* signal) { | |
350 dbus::MessageReader reader(signal); | |
351 std::string storage_name; | |
352 if (!reader.PopString(&storage_name)) { | |
353 LOG(ERROR) << "Invalid signal: " << signal->ToString(); | |
354 return; | |
355 } | |
356 DCHECK(!storage_name.empty()); | |
357 handler.Run(is_attach, storage_name); | |
358 } | |
359 | |
360 | |
361 // Handles the result of signal connection setup. | |
362 void OnSignalConnected(const std::string& interface, | |
363 const std::string& signal, | |
364 bool successed) { | |
365 LOG_IF(ERROR, !successed) << "Connect to " << interface << " " | |
366 << signal << " failed."; | |
367 } | |
368 | |
369 dbus::ObjectProxy* proxy_; | |
370 base::WeakPtrFactory<MTPDClientImpl> weak_ptr_factory_; | |
371 | |
372 DISALLOW_COPY_AND_ASSIGN(MTPDClientImpl); | |
373 }; | |
374 | |
375 // A stub implementaion of MTPDClient. | |
376 class MTPDClientStubImpl : public MTPDClient { | |
377 public: | |
378 MTPDClientStubImpl() {} | |
379 virtual ~MTPDClientStubImpl() {} | |
380 | |
381 virtual void EnumerateStorage( | |
382 const EnumerateStorageCallback& callback, | |
383 const ErrorCallback& error_callback) OVERRIDE {} | |
384 virtual void GetStorageInfo( | |
385 const std::string& storage_name, | |
386 const GetStorageInfoCallback& callback, | |
387 const ErrorCallback& error_callback) OVERRIDE {} | |
388 virtual void OpenStorage(const std::string& storage_name, | |
389 OpenStorageMode mode, | |
390 const OpenStorageCallback& callback, | |
391 const ErrorCallback& error_callback) OVERRIDE {} | |
392 virtual void CloseStorage(const std::string& handle, | |
393 const CloseStorageCallback& callback, | |
394 const ErrorCallback& error_callback) OVERRIDE {} | |
395 virtual void ReadDirectoryByPath( | |
396 const std::string& handle, | |
397 const std::string& path, | |
398 const ReadDirectoryCallback& callback, | |
399 const ErrorCallback& error_callback) OVERRIDE {} | |
400 virtual void ReadDirectoryById( | |
401 const std::string& handle, | |
402 uint32 file_id, | |
403 const ReadDirectoryCallback& callback, | |
404 const ErrorCallback& error_callback) OVERRIDE {} | |
405 virtual void ReadFileByPath(const std::string& handle, | |
406 const std::string& path, | |
407 const ReadFileCallback& callback, | |
408 const ErrorCallback& error_callback) OVERRIDE {} | |
409 virtual void ReadFileById(const std::string& handle, | |
410 uint32 file_id, | |
411 const ReadFileCallback& callback, | |
412 const ErrorCallback& error_callback) OVERRIDE {} | |
413 virtual void SetUpConnections( | |
414 const MTPStorageEventHandler& handler) OVERRIDE {} | |
415 | |
416 private: | |
417 DISALLOW_COPY_AND_ASSIGN(MTPDClientStubImpl); | |
418 }; | |
419 | |
420 } // namespace | |
421 | |
422 //////////////////////////////////////////////////////////////////////////////// | |
423 // StorageInfo | |
424 | |
425 StorageInfo::StorageInfo(const std::string& storage_name, | |
426 dbus::Response* response) | |
427 : vendor_id_(0), | |
428 product_id_(0), | |
429 device_flags_(0), | |
430 storage_name_(storage_name), | |
431 storage_type_(0), | |
432 filesystem_type_(0), | |
433 access_capability_(0), | |
434 max_capacity_(0), | |
435 free_space_in_bytes_(0), | |
436 free_space_in_objects_(0) { | |
437 InitializeFromResponse(response); | |
438 } | |
439 | |
440 StorageInfo::~StorageInfo() { | |
441 } | |
442 | |
443 // Initialize |this| from |response| given by the mtpd service. | |
satorux1
2012/08/03 05:26:07
Initializes
Lei Zhang
2012/08/03 06:29:30
Done.
| |
444 void StorageInfo::InitializeFromResponse(dbus::Response* response) { | |
445 dbus::MessageReader response_reader(response); | |
446 dbus::MessageReader array_reader(response); | |
447 if (!response_reader.PopArray(&array_reader)) { | |
448 LOG(ERROR) << "Invalid response: " << response->ToString(); | |
449 return; | |
450 } | |
451 // TODO(satorux): Rework this code using Protocol Buffers. crosbug.com/22626 | |
452 typedef std::map<std::string, dbus::MessageReader*> PropertiesMap; | |
453 PropertiesMap properties; | |
454 STLValueDeleter<PropertiesMap> properties_value_deleter(&properties); | |
455 while (array_reader.HasMoreData()) { | |
456 dbus::MessageReader* value_reader = new dbus::MessageReader(response); | |
457 dbus::MessageReader dict_entry_reader(response); | |
458 std::string key; | |
459 if (!array_reader.PopDictEntry(&dict_entry_reader) || | |
460 !dict_entry_reader.PopString(&key) || | |
461 !dict_entry_reader.PopVariant(value_reader)) { | |
462 LOG(ERROR) << "Invalid response: " << response->ToString(); | |
463 return; | |
464 } | |
465 properties[key] = value_reader; | |
466 } | |
467 // TODO(thestig) Add enums for fields below as appropriate. | |
468 MaybePopString(properties["Vendor"], &vendor_); | |
469 MaybePopString(properties["Product"], &product_); | |
470 MaybePopString(properties["StorageDescription"], &storage_description_); | |
471 MaybePopString(properties["VolumeIdentifier"], &volume_identifier_); | |
472 MaybePopUint16(properties["VendorId"], &vendor_id_); | |
473 MaybePopUint16(properties["ProductId"], &product_id_); | |
474 MaybePopUint16(properties["StorageType"], &storage_type_); | |
475 MaybePopUint16(properties["FilesystemType"], &filesystem_type_); | |
476 MaybePopUint16(properties["AccessCapability"], &access_capability_); | |
477 MaybePopUint32(properties["DeviceFlags"], &device_flags_); | |
478 MaybePopUint64(properties["MaxCapacity"], &max_capacity_); | |
479 MaybePopUint64(properties["FreeSpaceInBytes"], &free_space_in_bytes_); | |
480 MaybePopUint64(properties["FreeSpaceInObjects"], &free_space_in_objects_); | |
481 } | |
482 | |
483 //////////////////////////////////////////////////////////////////////////////// | |
484 // FileEntry | |
485 | |
486 FileEntry::FileEntry(dbus::Response* response) | |
487 : item_id_(0), | |
488 parent_id_(0), | |
489 filesize_(0), | |
490 file_type_(FILE_TYPE_UNKNOWN) { | |
491 InitializeFromResponse(response); | |
492 } | |
493 | |
494 FileEntry::~FileEntry() { | |
495 } | |
496 | |
497 // Initialize |this| from |response| given by the mtpd service. | |
498 void FileEntry::InitializeFromResponse(dbus::Response* response) { | |
499 dbus::MessageReader response_reader(response); | |
500 dbus::MessageReader array_reader(response); | |
501 if (!response_reader.PopArray(&array_reader)) { | |
502 LOG(ERROR) << "Invalid response: " << response->ToString(); | |
503 return; | |
504 } | |
505 // TODO(satorux): Rework this code using Protocol Buffers. crosbug.com/22626 | |
506 typedef std::map<std::string, dbus::MessageReader*> PropertiesMap; | |
507 PropertiesMap properties; | |
508 STLValueDeleter<PropertiesMap> properties_value_deleter(&properties); | |
509 while (array_reader.HasMoreData()) { | |
510 dbus::MessageReader* value_reader = new dbus::MessageReader(response); | |
511 dbus::MessageReader dict_entry_reader(response); | |
512 std::string key; | |
513 if (!array_reader.PopDictEntry(&dict_entry_reader) || | |
514 !dict_entry_reader.PopString(&key) || | |
515 !dict_entry_reader.PopVariant(value_reader)) { | |
516 LOG(ERROR) << "Invalid response: " << response->ToString(); | |
517 return; | |
518 } | |
519 properties[key] = value_reader; | |
520 } | |
521 | |
522 MaybePopString(properties["FileName"], &filename_); | |
523 MaybePopUint32(properties["ItemId"], &item_id_); | |
524 MaybePopUint32(properties["ParentId"], &parent_id_); | |
525 MaybePopUint64(properties["FileSize"], &filesize_); | |
526 | |
527 int64 modification_date = -1; | |
528 if (MaybePopInt64(properties["ModificationDate"], &modification_date)) | |
529 modification_date_ = base::Time::FromTimeT(modification_date); | |
530 | |
531 uint16 file_type = FILE_TYPE_OTHER; | |
532 if (MaybePopUint16(properties["FileType"], &file_type)) { | |
533 switch (file_type) { | |
534 case FILE_TYPE_FOLDER: | |
535 file_type_ = FILE_TYPE_FOLDER; | |
satorux1
2012/08/03 05:26:07
You might want to just fall through for known type
Lei Zhang
2012/08/03 06:29:30
Good idea, thanks.
| |
536 case FILE_TYPE_JPEG: | |
537 file_type_ = FILE_TYPE_JPEG; | |
538 case FILE_TYPE_JFIF: | |
539 file_type_ = FILE_TYPE_JFIF; | |
540 case FILE_TYPE_TIFF: | |
541 file_type_ = FILE_TYPE_TIFF; | |
542 case FILE_TYPE_BMP: | |
543 file_type_ = FILE_TYPE_BMP; | |
544 case FILE_TYPE_GIF: | |
545 file_type_ = FILE_TYPE_GIF; | |
546 case FILE_TYPE_PICT: | |
547 file_type_ = FILE_TYPE_PICT; | |
548 case FILE_TYPE_PNG: | |
549 file_type_ = FILE_TYPE_PNG; | |
550 case FILE_TYPE_WINDOWSIMAGEFORMAT: | |
551 file_type_ = FILE_TYPE_WINDOWSIMAGEFORMAT; | |
552 case FILE_TYPE_JP2: | |
553 file_type_ = FILE_TYPE_JP2; | |
554 case FILE_TYPE_JPX: | |
555 file_type_ = FILE_TYPE_JPX; | |
556 case FILE_TYPE_UNKNOWN: | |
557 file_type_ = FILE_TYPE_UNKNOWN; | |
558 default: | |
559 file_type_ = FILE_TYPE_OTHER; | |
560 break; | |
561 } | |
562 } | |
563 } | |
564 | |
565 //////////////////////////////////////////////////////////////////////////////// | |
566 // MTPDClient | |
567 | |
568 MTPDClient::MTPDClient() {} | |
569 | |
570 MTPDClient::~MTPDClient() {} | |
571 | |
572 // static | |
573 MTPDClient* MTPDClient::Create(DBusClientImplementationType type, | |
574 dbus::Bus* bus) { | |
575 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | |
576 return new MTPDClientImpl(bus); | |
577 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | |
578 return new MTPDClientStubImpl(); | |
579 } | |
580 | |
581 } // namespace chromeos | |
OLD | NEW |