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

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

Issue 258783006: [fsp] Add the getMetadata operation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 7 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 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 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h "
6
7 #include <string>
8
9 #include "chrome/common/extensions/api/file_system_provider.h"
10 #include "chrome/common/extensions/api/file_system_provider_internal.h"
11
12 namespace chromeos {
13 namespace file_system_provider {
14 namespace operations {
15 namespace {
16
17 // Convert |value| into |output|. If parsing fails, then returns false.
18 bool ConvertRequestValueToFileInfo(scoped_ptr<RequestValue> value,
19 base::File::Info* output) {
20 using extensions::api::file_system_provider::EntryMetadata;
21 using extensions::api::file_system_provider_internal::
22 GetMetadataRequestedSuccess::Params;
23
24 const Params* params = value->get_metadata_success_params();
25 if (!params)
26 return false;
27
28 output->is_directory = params->metadata.is_directory;
29 output->size = static_cast<int64>(params->metadata.size);
30 output->is_symbolic_link = false; // Not supported.
31
32 std::string input_modification_time;
33 if (!params->metadata.modification_time.additional_properties.GetString(
34 "value", &input_modification_time)) {
35 return false;
36 }
37 if (!base::Time::FromString(input_modification_time.c_str(),
38 &output->last_modified)) {
39 return false;
40 }
41
42 return true;
43 }
44
45 } // namespace
46
47 GetMetadata::GetMetadata(
48 extensions::EventRouter* event_router,
49 const ProvidedFileSystemInfo& file_system_info,
50 const base::FilePath& directory_path,
51 const fileapi::AsyncFileUtil::GetFileInfoCallback& callback)
52 : Operation(event_router, file_system_info),
53 directory_path_(directory_path),
54 callback_(callback) {
55 }
56
57 GetMetadata::~GetMetadata() {
58 }
59
60 bool GetMetadata::Execute(int request_id) {
61 scoped_ptr<base::ListValue> values(new base::ListValue);
62 values->AppendString(directory_path_.AsUTF8Unsafe());
63 return SendEvent(
64 request_id,
65 extensions::api::file_system_provider::OnGetMetadataRequested::kEventName,
66 values.Pass());
67 }
68
69 void GetMetadata::OnSuccess(int /* request_id */,
70 scoped_ptr<RequestValue> result,
71 bool has_next) {
72 base::File::Info file_info;
73 const bool convert_result =
74 ConvertRequestValueToFileInfo(result.Pass(), &file_info);
75 DCHECK(convert_result);
76 callback_.Run(base::File::FILE_OK, file_info);
77 }
78
79 void GetMetadata::OnError(int /* request_id */, base::File::Error error) {
80 callback_.Run(error, base::File::Info());
81 }
82
83 } // namespace operations
84 } // namespace file_system_provider
85 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698