OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/gdata/gdata_files.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
6 | 6 |
7 #include <leveldb/db.h> | 7 #include <leveldb/db.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } | 73 } |
74 | 74 |
75 EntryInfoPairResult::EntryInfoPairResult() { | 75 EntryInfoPairResult::EntryInfoPairResult() { |
76 } | 76 } |
77 | 77 |
78 EntryInfoPairResult::~EntryInfoPairResult() { | 78 EntryInfoPairResult::~EntryInfoPairResult() { |
79 } | 79 } |
80 | 80 |
81 // GDataEntry class. | 81 // GDataEntry class. |
82 | 82 |
83 GDataEntry::GDataEntry(GDataDirectory* parent, | 83 GDataEntry::GDataEntry(GDataDirectoryService* directory_service) |
84 GDataDirectoryService* directory_service) | 84 : parent_(NULL), |
85 : directory_service_(directory_service), | 85 directory_service_(directory_service), |
86 deleted_(false) { | 86 deleted_(false) { |
87 SetParent(parent); | |
88 } | 87 } |
89 | 88 |
90 GDataEntry::~GDataEntry() { | 89 GDataEntry::~GDataEntry() { |
91 } | 90 } |
92 | 91 |
93 GDataFile* GDataEntry::AsGDataFile() { | 92 GDataFile* GDataEntry::AsGDataFile() { |
94 return NULL; | 93 return NULL; |
95 } | 94 } |
96 | 95 |
97 GDataDirectory* GDataEntry::AsGDataDirectory() { | 96 GDataDirectory* GDataEntry::AsGDataDirectory() { |
98 return NULL; | 97 return NULL; |
99 } | 98 } |
100 | 99 |
| 100 void GDataEntry::InitFromDocumentEntry(DocumentEntry* doc) { |
| 101 // For regular files, the 'filename' and 'title' attribute in the metadata |
| 102 // may be different (e.g. due to rename). To be consistent with the web |
| 103 // interface and other client to use the 'title' attribute, instead of |
| 104 // 'filename', as the file name in the local snapshot. |
| 105 title_ = UTF16ToUTF8(doc->title()); |
| 106 // SetBaseNameFromTitle() must be called after |title_| is set. |
| 107 SetBaseNameFromTitle(); |
| 108 |
| 109 file_info_.last_modified = doc->updated_time(); |
| 110 file_info_.last_accessed = doc->updated_time(); |
| 111 file_info_.creation_time = doc->published_time(); |
| 112 |
| 113 resource_id_ = doc->resource_id(); |
| 114 content_url_ = doc->content_url(); |
| 115 deleted_ = doc->deleted(); |
| 116 |
| 117 const Link* edit_link = doc->GetLinkByType(Link::EDIT); |
| 118 if (edit_link) |
| 119 edit_url_ = edit_link->href(); |
| 120 |
| 121 const Link* parent_link = doc->GetLinkByType(Link::PARENT); |
| 122 if (parent_link) |
| 123 parent_resource_id_ = ExtractResourceId(parent_link->href()); |
| 124 } |
| 125 |
101 const GDataFile* GDataEntry::AsGDataFileConst() const { | 126 const GDataFile* GDataEntry::AsGDataFileConst() const { |
102 // cast away const and call the non-const version. This is safe. | 127 // cast away const and call the non-const version. This is safe. |
103 return const_cast<GDataEntry*>(this)->AsGDataFile(); | 128 return const_cast<GDataEntry*>(this)->AsGDataFile(); |
104 } | 129 } |
105 | 130 |
106 const GDataDirectory* GDataEntry::AsGDataDirectoryConst() const { | 131 const GDataDirectory* GDataEntry::AsGDataDirectoryConst() const { |
107 // cast away const and call the non-const version. This is safe. | 132 // cast away const and call the non-const version. This is safe. |
108 return const_cast<GDataEntry*>(this)->AsGDataDirectory(); | 133 return const_cast<GDataEntry*>(this)->AsGDataDirectory(); |
109 } | 134 } |
110 | 135 |
111 FilePath GDataEntry::GetFilePath() const { | 136 FilePath GDataEntry::GetFilePath() const { |
112 FilePath path; | 137 FilePath path; |
113 if (parent()) | 138 if (parent()) |
114 path = parent()->GetFilePath(); | 139 path = parent()->GetFilePath(); |
115 path = path.Append(base_name()); | 140 path = path.Append(base_name()); |
116 return path; | 141 return path; |
117 } | 142 } |
118 | 143 |
119 void GDataEntry::SetParent(GDataDirectory* parent) { | 144 void GDataEntry::SetParent(GDataDirectory* parent) { |
120 parent_ = parent; | 145 parent_ = parent; |
121 parent_resource_id_ = parent ? parent->resource_id() : ""; | 146 parent_resource_id_ = parent ? parent->resource_id() : ""; |
122 } | 147 } |
123 | 148 |
124 void GDataEntry::SetBaseNameFromTitle() { | 149 void GDataEntry::SetBaseNameFromTitle() { |
125 base_name_ = EscapeUtf8FileName(title_); | 150 base_name_ = EscapeUtf8FileName(title_); |
126 } | 151 } |
127 | 152 |
128 // static | 153 // static |
129 GDataEntry* GDataEntry::FromDocumentEntry( | |
130 GDataDirectory* parent, | |
131 DocumentEntry* doc, | |
132 GDataDirectoryService* directory_service) { | |
133 DCHECK(doc); | |
134 if (doc->is_folder()) | |
135 return GDataDirectory::FromDocumentEntry(parent, doc, directory_service); | |
136 else if (doc->is_hosted_document() || doc->is_file()) | |
137 return GDataFile::FromDocumentEntry(parent, doc, directory_service); | |
138 | |
139 return NULL; | |
140 } | |
141 | |
142 // static | |
143 std::string GDataEntry::EscapeUtf8FileName(const std::string& input) { | 154 std::string GDataEntry::EscapeUtf8FileName(const std::string& input) { |
144 std::string output; | 155 std::string output; |
145 if (ReplaceChars(input, kSlash, std::string(kEscapedSlash), &output)) | 156 if (ReplaceChars(input, kSlash, std::string(kEscapedSlash), &output)) |
146 return output; | 157 return output; |
147 | 158 |
148 return input; | 159 return input; |
149 } | 160 } |
150 | 161 |
151 // static | 162 // static |
152 std::string GDataEntry::UnescapeUtf8FileName(const std::string& input) { | 163 std::string GDataEntry::UnescapeUtf8FileName(const std::string& input) { |
153 std::string output = input; | 164 std::string output = input; |
154 ReplaceSubstringsAfterOffset(&output, 0, std::string(kEscapedSlash), kSlash); | 165 ReplaceSubstringsAfterOffset(&output, 0, std::string(kEscapedSlash), kSlash); |
155 return output; | 166 return output; |
156 } | 167 } |
157 | 168 |
158 // GDataFile class implementation. | 169 // GDataFile class implementation. |
159 | 170 |
160 GDataFile::GDataFile(GDataDirectory* parent, | 171 GDataFile::GDataFile(GDataDirectoryService* directory_service) |
161 GDataDirectoryService* directory_service) | 172 : GDataEntry(directory_service), |
162 : GDataEntry(parent, directory_service), | |
163 kind_(DocumentEntry::UNKNOWN), | 173 kind_(DocumentEntry::UNKNOWN), |
164 is_hosted_document_(false) { | 174 is_hosted_document_(false) { |
165 file_info_.is_directory = false; | 175 file_info_.is_directory = false; |
166 } | 176 } |
167 | 177 |
168 GDataFile::~GDataFile() { | 178 GDataFile::~GDataFile() { |
169 } | 179 } |
170 | 180 |
171 GDataFile* GDataFile::AsGDataFile() { | 181 GDataFile* GDataFile::AsGDataFile() { |
172 return this; | 182 return this; |
173 } | 183 } |
174 | 184 |
175 void GDataFile::SetBaseNameFromTitle() { | 185 void GDataFile::SetBaseNameFromTitle() { |
176 if (is_hosted_document_) { | 186 if (is_hosted_document_) { |
177 base_name_ = EscapeUtf8FileName(title_ + document_extension_); | 187 base_name_ = EscapeUtf8FileName(title_ + document_extension_); |
178 } else { | 188 } else { |
179 GDataEntry::SetBaseNameFromTitle(); | 189 GDataEntry::SetBaseNameFromTitle(); |
180 } | 190 } |
181 } | 191 } |
182 | 192 |
183 // static | 193 void GDataFile::InitFromDocumentEntry(DocumentEntry* doc) { |
184 GDataEntry* GDataFile::FromDocumentEntry( | 194 GDataEntry::InitFromDocumentEntry(doc); |
185 GDataDirectory* parent, | |
186 DocumentEntry* doc, | |
187 GDataDirectoryService* directory_service) { | |
188 DCHECK(doc->is_hosted_document() || doc->is_file()); | |
189 GDataFile* file = new GDataFile(parent, directory_service); | |
190 | |
191 // For regular files, the 'filename' and 'title' attribute in the metadata | |
192 // may be different (e.g. due to rename). To be consistent with the web | |
193 // interface and other client to use the 'title' attribute, instead of | |
194 // 'filename', as the file name in the local snapshot. | |
195 file->title_ = UTF16ToUTF8(doc->title()); | |
196 | 195 |
197 // Check if this entry is a true file, or... | 196 // Check if this entry is a true file, or... |
198 if (doc->is_file()) { | 197 if (doc->is_file()) { |
199 file->file_info_.size = doc->file_size(); | 198 file_info_.size = doc->file_size(); |
200 file->file_md5_ = doc->file_md5(); | 199 file_md5_ = doc->file_md5(); |
201 | 200 |
202 // The resumable-edit-media link should only be present for regular | 201 // The resumable-edit-media link should only be present for regular |
203 // files as hosted documents are not uploadable. | 202 // files as hosted documents are not uploadable. |
204 const Link* upload_link = doc->GetLinkByType(Link::RESUMABLE_EDIT_MEDIA); | 203 const Link* upload_link = doc->GetLinkByType(Link::RESUMABLE_EDIT_MEDIA); |
205 if (upload_link) | 204 if (upload_link) |
206 file->upload_url_ = upload_link->href(); | 205 upload_url_ = upload_link->href(); |
207 } else { | 206 } else { |
208 // ... a hosted document. | 207 // ... a hosted document. |
209 // Attach .g<something> extension to hosted documents so we can special | 208 // Attach .g<something> extension to hosted documents so we can special |
210 // case their handling in UI. | 209 // case their handling in UI. |
211 // TODO(zelidrag): Figure out better way how to pass entry info like kind | 210 // TODO(zelidrag): Figure out better way how to pass entry info like kind |
212 // to UI through the File API stack. | 211 // to UI through the File API stack. |
213 file->document_extension_ = doc->GetHostedDocumentExtension(); | 212 document_extension_ = doc->GetHostedDocumentExtension(); |
214 // We don't know the size of hosted docs and it does not matter since | 213 // We don't know the size of hosted docs and it does not matter since |
215 // is has no effect on the quota. | 214 // is has no effect on the quota. |
216 file->file_info_.size = 0; | 215 file_info_.size = 0; |
217 } | 216 } |
218 file->kind_ = doc->kind(); | 217 kind_ = doc->kind(); |
219 const Link* edit_link = doc->GetLinkByType(Link::EDIT); | 218 content_mime_type_ = doc->content_mime_type(); |
220 if (edit_link) | 219 is_hosted_document_ = doc->is_hosted_document(); |
221 file->edit_url_ = edit_link->href(); | |
222 file->content_url_ = doc->content_url(); | |
223 file->content_mime_type_ = doc->content_mime_type(); | |
224 file->resource_id_ = doc->resource_id(); | |
225 file->is_hosted_document_ = doc->is_hosted_document(); | |
226 file->file_info_.last_modified = doc->updated_time(); | |
227 file->file_info_.last_accessed = doc->updated_time(); | |
228 file->file_info_.creation_time = doc->published_time(); | |
229 file->deleted_ = doc->deleted(); | |
230 const Link* parent_link = doc->GetLinkByType(Link::PARENT); | |
231 if (parent_link) | |
232 file->parent_resource_id_ = ExtractResourceId(parent_link->href()); | |
233 | |
234 // SetBaseNameFromTitle() must be called after |title_|, | 220 // SetBaseNameFromTitle() must be called after |title_|, |
235 // |is_hosted_document_| and |document_extension_| are set. | 221 // |is_hosted_document_| and |document_extension_| are set. |
236 file->SetBaseNameFromTitle(); | 222 SetBaseNameFromTitle(); |
237 | 223 |
238 const Link* thumbnail_link = doc->GetLinkByType(Link::THUMBNAIL); | 224 const Link* thumbnail_link = doc->GetLinkByType(Link::THUMBNAIL); |
239 if (thumbnail_link) | 225 if (thumbnail_link) |
240 file->thumbnail_url_ = thumbnail_link->href(); | 226 thumbnail_url_ = thumbnail_link->href(); |
241 | 227 |
242 const Link* alternate_link = doc->GetLinkByType(Link::ALTERNATE); | 228 const Link* alternate_link = doc->GetLinkByType(Link::ALTERNATE); |
243 if (alternate_link) | 229 if (alternate_link) |
244 file->alternate_url_ = alternate_link->href(); | 230 alternate_url_ = alternate_link->href(); |
245 | |
246 return file; | |
247 } | 231 } |
248 | 232 |
249 // GDataDirectory class implementation. | 233 // GDataDirectory class implementation. |
250 | 234 |
251 GDataDirectory::GDataDirectory(GDataDirectory* parent, | 235 GDataDirectory::GDataDirectory(GDataDirectoryService* directory_service) |
252 GDataDirectoryService* directory_service) | 236 : GDataEntry(directory_service) { |
253 : GDataEntry(parent, directory_service) { | |
254 file_info_.is_directory = true; | 237 file_info_.is_directory = true; |
255 } | 238 } |
256 | 239 |
257 GDataDirectory::~GDataDirectory() { | 240 GDataDirectory::~GDataDirectory() { |
258 RemoveChildren(); | 241 RemoveChildren(); |
259 } | 242 } |
260 | 243 |
261 GDataDirectory* GDataDirectory::AsGDataDirectory() { | 244 GDataDirectory* GDataDirectory::AsGDataDirectory() { |
262 return this; | 245 return this; |
263 } | 246 } |
264 | 247 |
265 // static | 248 void GDataDirectory::InitFromDocumentEntry(DocumentEntry* doc) { |
266 GDataEntry* GDataDirectory::FromDocumentEntry( | 249 GDataEntry::InitFromDocumentEntry(doc); |
267 GDataDirectory* parent, | |
268 DocumentEntry* doc, | |
269 GDataDirectoryService* directory_service) { | |
270 DCHECK(doc->is_folder()); | |
271 GDataDirectory* dir = new GDataDirectory(parent, directory_service); | |
272 dir->title_ = UTF16ToUTF8(doc->title()); | |
273 // SetBaseNameFromTitle() must be called after |title_| is set. | |
274 dir->SetBaseNameFromTitle(); | |
275 dir->file_info_.last_modified = doc->updated_time(); | |
276 dir->file_info_.last_accessed = doc->updated_time(); | |
277 dir->file_info_.creation_time = doc->published_time(); | |
278 dir->resource_id_ = doc->resource_id(); | |
279 dir->content_url_ = doc->content_url(); | |
280 dir->deleted_ = doc->deleted(); | |
281 | |
282 const Link* edit_link = doc->GetLinkByType(Link::EDIT); | |
283 DCHECK(edit_link) << "No edit link for dir " << dir->title_; | |
284 if (edit_link) | |
285 dir->edit_url_ = edit_link->href(); | |
286 | |
287 const Link* parent_link = doc->GetLinkByType(Link::PARENT); | |
288 if (parent_link) | |
289 dir->parent_resource_id_ = ExtractResourceId(parent_link->href()); | |
290 | 250 |
291 const Link* upload_link = doc->GetLinkByType(Link::RESUMABLE_CREATE_MEDIA); | 251 const Link* upload_link = doc->GetLinkByType(Link::RESUMABLE_CREATE_MEDIA); |
292 if (upload_link) | 252 if (upload_link) |
293 dir->upload_url_ = upload_link->href(); | 253 upload_url_ = upload_link->href(); |
294 | |
295 return dir; | |
296 } | 254 } |
297 | 255 |
298 void GDataDirectory::AddEntry(GDataEntry* entry) { | 256 void GDataDirectory::AddEntry(GDataEntry* entry) { |
299 // The entry name may have been changed due to prior name de-duplication. | 257 // The entry name may have been changed due to prior name de-duplication. |
300 // We need to first restore the file name based on the title before going | 258 // We need to first restore the file name based on the title before going |
301 // through name de-duplication again when it is added to another directory. | 259 // through name de-duplication again when it is added to another directory. |
302 entry->SetBaseNameFromTitle(); | 260 entry->SetBaseNameFromTitle(); |
303 | 261 |
304 // Do file name de-duplication - find files with the same name and | 262 // Do file name de-duplication - find files with the same name and |
305 // append a name modifier to the name. | 263 // append a name modifier to the name. |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 } | 503 } |
546 | 504 |
547 // GDataDirectoryService class implementation. | 505 // GDataDirectoryService class implementation. |
548 | 506 |
549 GDataDirectoryService::GDataDirectoryService() | 507 GDataDirectoryService::GDataDirectoryService() |
550 : blocking_task_runner_(NULL), | 508 : blocking_task_runner_(NULL), |
551 serialized_size_(0), | 509 serialized_size_(0), |
552 largest_changestamp_(0), | 510 largest_changestamp_(0), |
553 origin_(UNINITIALIZED), | 511 origin_(UNINITIALIZED), |
554 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 512 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
555 root_.reset(new GDataDirectory(NULL, this)); | 513 root_.reset(CreateGDataDirectory()); |
556 if (!util::IsDriveV2ApiEnabled()) | 514 if (!util::IsDriveV2ApiEnabled()) |
557 InitializeRootEntry(kGDataRootDirectoryResourceId); | 515 InitializeRootEntry(kGDataRootDirectoryResourceId); |
558 } | 516 } |
559 | 517 |
560 GDataDirectoryService::~GDataDirectoryService() { | 518 GDataDirectoryService::~GDataDirectoryService() { |
561 ClearRoot(); | 519 ClearRoot(); |
562 | 520 |
563 // Ensure db is closed on the blocking pool. | 521 // Ensure db is closed on the blocking pool. |
564 if (blocking_task_runner_ && directory_service_db_.get()) | 522 if (blocking_task_runner_ && directory_service_db_.get()) |
565 blocking_task_runner_->DeleteSoon(FROM_HERE, | 523 blocking_task_runner_->DeleteSoon(FROM_HERE, |
566 directory_service_db_.release()); | 524 directory_service_db_.release()); |
567 } | 525 } |
568 | 526 |
| 527 GDataEntry* GDataDirectoryService::FromDocumentEntry(DocumentEntry* doc) { |
| 528 DCHECK(doc); |
| 529 GDataEntry* entry = NULL; |
| 530 if (doc->is_folder()) |
| 531 entry = CreateGDataDirectory(); |
| 532 else if (doc->is_hosted_document() || doc->is_file()) |
| 533 entry = CreateGDataFile(); |
| 534 |
| 535 if (entry) |
| 536 entry->InitFromDocumentEntry(doc); |
| 537 return entry; |
| 538 } |
| 539 |
| 540 GDataFile* GDataDirectoryService::CreateGDataFile() { |
| 541 return new GDataFile(this); |
| 542 } |
| 543 |
| 544 GDataDirectory* GDataDirectoryService::CreateGDataDirectory() { |
| 545 return new GDataDirectory(this); |
| 546 } |
| 547 |
569 void GDataDirectoryService::InitializeRootEntry(const std::string& root_id) { | 548 void GDataDirectoryService::InitializeRootEntry(const std::string& root_id) { |
570 root_.reset(new GDataDirectory(NULL, this)); | 549 root_.reset(CreateGDataDirectory()); |
571 root_->set_title(kGDataRootDirectory); | 550 root_->set_title(kGDataRootDirectory); |
572 root_->SetBaseNameFromTitle(); | 551 root_->SetBaseNameFromTitle(); |
573 root_->set_resource_id(root_id); | 552 root_->set_resource_id(root_id); |
574 AddEntryToResourceMap(root_.get()); | 553 AddEntryToResourceMap(root_.get()); |
575 } | 554 } |
576 | 555 |
577 void GDataDirectoryService::ClearRoot() { | 556 void GDataDirectoryService::ClearRoot() { |
578 // Note that children have a reference to root_, | 557 // Note that children have a reference to root_, |
579 // so we need to delete them here. | 558 // so we need to delete them here. |
580 root_->RemoveChildren(); | 559 root_->RemoveChildren(); |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 file_specific_info->set_file_md5(file_md5_); | 1007 file_specific_info->set_file_md5(file_md5_); |
1029 file_specific_info->set_document_extension(document_extension_); | 1008 file_specific_info->set_document_extension(document_extension_); |
1030 file_specific_info->set_is_hosted_document(is_hosted_document_); | 1009 file_specific_info->set_is_hosted_document(is_hosted_document_); |
1031 } | 1010 } |
1032 | 1011 |
1033 bool GDataDirectory::FromProto(const GDataDirectoryProto& proto) { | 1012 bool GDataDirectory::FromProto(const GDataDirectoryProto& proto) { |
1034 DCHECK(proto.gdata_entry().file_info().is_directory()); | 1013 DCHECK(proto.gdata_entry().file_info().is_directory()); |
1035 DCHECK(!proto.gdata_entry().has_file_specific_info()); | 1014 DCHECK(!proto.gdata_entry().has_file_specific_info()); |
1036 | 1015 |
1037 for (int i = 0; i < proto.child_files_size(); ++i) { | 1016 for (int i = 0; i < proto.child_files_size(); ++i) { |
1038 scoped_ptr<GDataFile> file(new GDataFile(NULL, directory_service_)); | 1017 scoped_ptr<GDataFile> file(directory_service_->CreateGDataFile()); |
1039 if (!file->FromProto(proto.child_files(i))) { | 1018 if (!file->FromProto(proto.child_files(i))) { |
1040 RemoveChildren(); | 1019 RemoveChildren(); |
1041 return false; | 1020 return false; |
1042 } | 1021 } |
1043 AddEntry(file.release()); | 1022 AddEntry(file.release()); |
1044 } | 1023 } |
1045 for (int i = 0; i < proto.child_directories_size(); ++i) { | 1024 for (int i = 0; i < proto.child_directories_size(); ++i) { |
1046 scoped_ptr<GDataDirectory> dir(new GDataDirectory(NULL, | 1025 scoped_ptr<GDataDirectory> dir(directory_service_->CreateGDataDirectory()); |
1047 directory_service_)); | |
1048 if (!dir->FromProto(proto.child_directories(i))) { | 1026 if (!dir->FromProto(proto.child_directories(i))) { |
1049 RemoveChildren(); | 1027 RemoveChildren(); |
1050 return false; | 1028 return false; |
1051 } | 1029 } |
1052 AddEntry(dir.release()); | 1030 AddEntry(dir.release()); |
1053 } | 1031 } |
1054 | 1032 |
1055 // The states of the directory should be updated after children are | 1033 // The states of the directory should be updated after children are |
1056 // handled successfully, so that incomplete states are not left. | 1034 // handled successfully, so that incomplete states are not left. |
1057 if (!GDataEntry::FromProto(proto.gdata_entry())) | 1035 if (!GDataEntry::FromProto(proto.gdata_entry())) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 } | 1128 } |
1151 | 1129 |
1152 scoped_ptr<GDataEntry> GDataDirectoryService::FromProtoString( | 1130 scoped_ptr<GDataEntry> GDataDirectoryService::FromProtoString( |
1153 const std::string& serialized_proto) { | 1131 const std::string& serialized_proto) { |
1154 GDataEntryProto entry_proto; | 1132 GDataEntryProto entry_proto; |
1155 if (!entry_proto.ParseFromString(serialized_proto)) | 1133 if (!entry_proto.ParseFromString(serialized_proto)) |
1156 return scoped_ptr<GDataEntry>(); | 1134 return scoped_ptr<GDataEntry>(); |
1157 | 1135 |
1158 scoped_ptr<GDataEntry> entry; | 1136 scoped_ptr<GDataEntry> entry; |
1159 if (entry_proto.file_info().is_directory()) { | 1137 if (entry_proto.file_info().is_directory()) { |
1160 entry.reset(new GDataDirectory(NULL, this)); | 1138 entry.reset(CreateGDataDirectory()); |
1161 // Call GDataEntry::FromProto instead of GDataDirectory::FromProto because | 1139 // Call GDataEntry::FromProto instead of GDataDirectory::FromProto because |
1162 // the proto does not include children. | 1140 // the proto does not include children. |
1163 if (!entry->FromProto(entry_proto)) { | 1141 if (!entry->FromProto(entry_proto)) { |
1164 NOTREACHED() << "FromProto (directory) failed"; | 1142 NOTREACHED() << "FromProto (directory) failed"; |
1165 entry.reset(); | 1143 entry.reset(); |
1166 } | 1144 } |
1167 } else { | 1145 } else { |
1168 scoped_ptr<GDataFile> file(new GDataFile(NULL, this)); | 1146 scoped_ptr<GDataFile> file(CreateGDataFile()); |
1169 // Call GDataFile::FromProto. | 1147 // Call GDataFile::FromProto. |
1170 if (file->FromProto(entry_proto)) { | 1148 if (file->FromProto(entry_proto)) { |
1171 entry.reset(file.release()); | 1149 entry.reset(file.release()); |
1172 } else { | 1150 } else { |
1173 NOTREACHED() << "FromProto (file) failed"; | 1151 NOTREACHED() << "FromProto (file) failed"; |
1174 } | 1152 } |
1175 } | 1153 } |
1176 return entry.Pass(); | 1154 return entry.Pass(); |
1177 } | 1155 } |
1178 | 1156 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 DCHECK(result.get()); | 1195 DCHECK(result.get()); |
1218 | 1196 |
1219 result->second.path = second_path; | 1197 result->second.path = second_path; |
1220 result->second.error = error; | 1198 result->second.error = error; |
1221 result->second.proto = entry_proto.Pass(); | 1199 result->second.proto = entry_proto.Pass(); |
1222 | 1200 |
1223 callback.Run(result.Pass()); | 1201 callback.Run(result.Pass()); |
1224 } | 1202 } |
1225 | 1203 |
1226 } // namespace gdata | 1204 } // namespace gdata |
OLD | NEW |