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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/operations/get_metadata.cc

Issue 513683002: [fsp] Add support for providing thumbnails. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use scoped_ptr for EntryMetadata. Created 6 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h " 5 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h "
6 6
7 #include <algorithm>
7 #include <string> 8 #include <string>
8 9
9 #include "chrome/common/extensions/api/file_system_provider.h" 10 #include "chrome/common/extensions/api/file_system_provider.h"
10 #include "chrome/common/extensions/api/file_system_provider_internal.h" 11 #include "chrome/common/extensions/api/file_system_provider_internal.h"
11 12
12 namespace chromeos { 13 namespace chromeos {
13 namespace file_system_provider { 14 namespace file_system_provider {
14 namespace operations { 15 namespace operations {
15 namespace { 16 namespace {
16 17
17 // Convert |value| into |output|. If parsing fails, then returns false. 18 // Convert |value| into |output|. If parsing fails, then returns false.
18 bool ConvertRequestValueToFileInfo(scoped_ptr<RequestValue> value, 19 bool ConvertRequestValueToFileInfo(scoped_ptr<RequestValue> value,
19 EntryMetadata* output) { 20 EntryMetadata* output) {
20 using extensions::api::file_system_provider::EntryMetadata; 21 using extensions::api::file_system_provider::EntryMetadata;
21 using extensions::api::file_system_provider_internal:: 22 using extensions::api::file_system_provider_internal::
22 GetMetadataRequestedSuccess::Params; 23 GetMetadataRequestedSuccess::Params;
23 24
24 const Params* params = value->get_metadata_success_params(); 25 const Params* params = value->get_metadata_success_params();
25 if (!params) 26 if (!params)
26 return false; 27 return false;
27 28
28 output->name = params->metadata.name; 29 output->name = params->metadata.name;
29 output->is_directory = params->metadata.is_directory; 30 output->is_directory = params->metadata.is_directory;
30 output->size = static_cast<int64>(params->metadata.size); 31 output->size = static_cast<int64>(params->metadata.size);
31 32
32 if (params->metadata.mime_type.get())
33 output->mime_type = *params->metadata.mime_type.get();
34
35 std::string input_modification_time; 33 std::string input_modification_time;
36 if (!params->metadata.modification_time.additional_properties.GetString( 34 if (!params->metadata.modification_time.additional_properties.GetString(
37 "value", &input_modification_time)) { 35 "value", &input_modification_time)) {
38 return false; 36 return false;
39 } 37 }
40 38
41 // Allow to pass invalid modification time, since there is no way to verify 39 // Allow to pass invalid modification time, since there is no way to verify
42 // it easily on any earlier stage. 40 // it easily on any earlier stage.
43 base::Time::FromString(input_modification_time.c_str(), 41 base::Time::FromString(input_modification_time.c_str(),
44 &output->modification_time); 42 &output->modification_time);
45 43
44 if (params->metadata.mime_type.get())
45 output->mime_type = *params->metadata.mime_type.get();
46
47 if (params->metadata.thumbnail.get()) {
48 // Sanity check for the thumbnail format. Note, that another, more granural
49 // check is done in custom bindings. Note, this is an extra check only for
50 // the security reasons.
51 const std::string expected_prefix = "data:";
52 std::string thumbnail_prefix =
53 params->metadata.thumbnail.get()->substr(0, expected_prefix.size());
54 std::transform(thumbnail_prefix.begin(),
55 thumbnail_prefix.end(),
56 thumbnail_prefix.begin(),
57 ::tolower);
58
59 if (expected_prefix != thumbnail_prefix)
60 return false;
61
62 output->thumbnail = *params->metadata.thumbnail.get();
63 }
64
46 return true; 65 return true;
47 } 66 }
48 67
49 } // namespace 68 } // namespace
50 69
51 GetMetadata::GetMetadata( 70 GetMetadata::GetMetadata(
52 extensions::EventRouter* event_router, 71 extensions::EventRouter* event_router,
53 const ProvidedFileSystemInfo& file_system_info, 72 const ProvidedFileSystemInfo& file_system_info,
54 const base::FilePath& entry_path, 73 const base::FilePath& entry_path,
74 ProvidedFileSystemInterface::MetadataFieldMask fields,
55 const ProvidedFileSystemInterface::GetMetadataCallback& callback) 75 const ProvidedFileSystemInterface::GetMetadataCallback& callback)
56 : Operation(event_router, file_system_info), 76 : Operation(event_router, file_system_info),
57 entry_path_(entry_path), 77 entry_path_(entry_path),
78 fields_(fields),
58 callback_(callback) { 79 callback_(callback) {
59 } 80 }
60 81
61 GetMetadata::~GetMetadata() { 82 GetMetadata::~GetMetadata() {
62 } 83 }
63 84
64 bool GetMetadata::Execute(int request_id) { 85 bool GetMetadata::Execute(int request_id) {
65 scoped_ptr<base::DictionaryValue> values(new base::DictionaryValue); 86 scoped_ptr<base::DictionaryValue> values(new base::DictionaryValue);
66 values->SetString("entryPath", entry_path_.AsUTF8Unsafe()); 87 values->SetString("entryPath", entry_path_.AsUTF8Unsafe());
88 values->SetBoolean(
89 "thumbnail",
90 (fields_ & ProvidedFileSystemInterface::METADATA_FIELD_THUMBNAIL) != 0);
91
67 return SendEvent( 92 return SendEvent(
68 request_id, 93 request_id,
69 extensions::api::file_system_provider::OnGetMetadataRequested::kEventName, 94 extensions::api::file_system_provider::OnGetMetadataRequested::kEventName,
70 values.Pass()); 95 values.Pass());
71 } 96 }
72 97
73 void GetMetadata::OnSuccess(int /* request_id */, 98 void GetMetadata::OnSuccess(int /* request_id */,
74 scoped_ptr<RequestValue> result, 99 scoped_ptr<RequestValue> result,
75 bool has_more) { 100 bool has_more) {
76 EntryMetadata metadata; 101 scoped_ptr<EntryMetadata> metadata(new EntryMetadata);
77 const bool convert_result = 102 const bool convert_result =
78 ConvertRequestValueToFileInfo(result.Pass(), &metadata); 103 ConvertRequestValueToFileInfo(result.Pass(), metadata.get());
79 104
80 if (!convert_result) { 105 if (!convert_result) {
81 LOG(ERROR) << "Failed to parse a response for the get metadata operation."; 106 LOG(ERROR) << "Failed to parse a response for the get metadata operation.";
82 callback_.Run(EntryMetadata(), base::File::FILE_ERROR_IO); 107 callback_.Run(make_scoped_ptr<EntryMetadata>(NULL),
108 base::File::FILE_ERROR_IO);
83 return; 109 return;
84 } 110 }
85 111
86 callback_.Run(metadata, base::File::FILE_OK); 112 callback_.Run(metadata.Pass(), base::File::FILE_OK);
87 } 113 }
88 114
89 void GetMetadata::OnError(int /* request_id */, 115 void GetMetadata::OnError(int /* request_id */,
90 scoped_ptr<RequestValue> /* result */, 116 scoped_ptr<RequestValue> /* result */,
91 base::File::Error error) { 117 base::File::Error error) {
92 callback_.Run(EntryMetadata(), error); 118 callback_.Run(make_scoped_ptr<EntryMetadata>(NULL), error);
93 } 119 }
94
95 } // namespace operations 120 } // namespace operations
96 } // namespace file_system_provider 121 } // namespace file_system_provider
97 } // namespace chromeos 122 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698