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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_files.cc

Issue 10854180: Pass const ref instead of pointer for FromDocumentEntry() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix for comments. Created 8 years, 4 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
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 "base/platform_file.h" 7 #include "base/platform_file.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 28 matching lines...) Expand all
39 } 39 }
40 40
41 GDataFile* GDataEntry::AsGDataFile() { 41 GDataFile* GDataEntry::AsGDataFile() {
42 return NULL; 42 return NULL;
43 } 43 }
44 44
45 GDataDirectory* GDataEntry::AsGDataDirectory() { 45 GDataDirectory* GDataEntry::AsGDataDirectory() {
46 return NULL; 46 return NULL;
47 } 47 }
48 48
49 void GDataEntry::InitFromDocumentEntry(DocumentEntry* doc) { 49 void GDataEntry::InitFromDocumentEntry(const DocumentEntry& doc) {
50 // For regular files, the 'filename' and 'title' attribute in the metadata 50 // For regular files, the 'filename' and 'title' attribute in the metadata
51 // may be different (e.g. due to rename). To be consistent with the web 51 // may be different (e.g. due to rename). To be consistent with the web
52 // interface and other client to use the 'title' attribute, instead of 52 // interface and other client to use the 'title' attribute, instead of
53 // 'filename', as the file name in the local snapshot. 53 // 'filename', as the file name in the local snapshot.
54 title_ = UTF16ToUTF8(doc->title()); 54 title_ = UTF16ToUTF8(doc.title());
55 // SetBaseNameFromTitle() must be called after |title_| is set. 55 // SetBaseNameFromTitle() must be called after |title_| is set.
56 SetBaseNameFromTitle(); 56 SetBaseNameFromTitle();
57 57
58 file_info_.last_modified = doc->updated_time(); 58 file_info_.last_modified = doc.updated_time();
59 file_info_.last_accessed = doc->updated_time(); 59 file_info_.last_accessed = doc.updated_time();
60 file_info_.creation_time = doc->published_time(); 60 file_info_.creation_time = doc.published_time();
61 61
62 resource_id_ = doc->resource_id(); 62 resource_id_ = doc.resource_id();
63 content_url_ = doc->content_url(); 63 content_url_ = doc.content_url();
64 deleted_ = doc->deleted(); 64 deleted_ = doc.deleted();
65 65
66 const Link* edit_link = doc->GetLinkByType(Link::EDIT); 66 const Link* edit_link = doc.GetLinkByType(Link::EDIT);
67 if (edit_link) 67 if (edit_link)
68 edit_url_ = edit_link->href(); 68 edit_url_ = edit_link->href();
69 69
70 const Link* parent_link = doc->GetLinkByType(Link::PARENT); 70 const Link* parent_link = doc.GetLinkByType(Link::PARENT);
71 if (parent_link) 71 if (parent_link)
72 parent_resource_id_ = ExtractResourceId(parent_link->href()); 72 parent_resource_id_ = ExtractResourceId(parent_link->href());
73 } 73 }
74 74
75 const GDataFile* GDataEntry::AsGDataFileConst() const { 75 const GDataFile* GDataEntry::AsGDataFileConst() const {
76 // cast away const and call the non-const version. This is safe. 76 // cast away const and call the non-const version. This is safe.
77 return const_cast<GDataEntry*>(this)->AsGDataFile(); 77 return const_cast<GDataEntry*>(this)->AsGDataFile();
78 } 78 }
79 79
80 const GDataDirectory* GDataEntry::AsGDataDirectoryConst() const { 80 const GDataDirectory* GDataEntry::AsGDataDirectoryConst() const {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 132 }
133 133
134 void GDataFile::SetBaseNameFromTitle() { 134 void GDataFile::SetBaseNameFromTitle() {
135 if (is_hosted_document_) { 135 if (is_hosted_document_) {
136 base_name_ = EscapeUtf8FileName(title_ + document_extension_); 136 base_name_ = EscapeUtf8FileName(title_ + document_extension_);
137 } else { 137 } else {
138 GDataEntry::SetBaseNameFromTitle(); 138 GDataEntry::SetBaseNameFromTitle();
139 } 139 }
140 } 140 }
141 141
142 void GDataFile::InitFromDocumentEntry(DocumentEntry* doc) { 142 void GDataFile::InitFromDocumentEntry(const DocumentEntry& doc) {
143 GDataEntry::InitFromDocumentEntry(doc); 143 GDataEntry::InitFromDocumentEntry(doc);
144 144
145 // Check if this entry is a true file, or... 145 // Check if this entry is a true file, or...
146 if (doc->is_file()) { 146 if (doc.is_file()) {
147 file_info_.size = doc->file_size(); 147 file_info_.size = doc.file_size();
148 file_md5_ = doc->file_md5(); 148 file_md5_ = doc.file_md5();
149 149
150 // The resumable-edit-media link should only be present for regular 150 // The resumable-edit-media link should only be present for regular
151 // files as hosted documents are not uploadable. 151 // files as hosted documents are not uploadable.
152 const Link* upload_link = doc->GetLinkByType(Link::RESUMABLE_EDIT_MEDIA); 152 const Link* upload_link = doc.GetLinkByType(Link::RESUMABLE_EDIT_MEDIA);
153 if (upload_link) 153 if (upload_link)
154 upload_url_ = upload_link->href(); 154 upload_url_ = upload_link->href();
155 } else { 155 } else {
156 // ... a hosted document. 156 // ... a hosted document.
157 // Attach .g<something> extension to hosted documents so we can special 157 // Attach .g<something> extension to hosted documents so we can special
158 // case their handling in UI. 158 // case their handling in UI.
159 // TODO(zelidrag): Figure out better way how to pass entry info like kind 159 // TODO(zelidrag): Figure out better way how to pass entry info like kind
160 // to UI through the File API stack. 160 // to UI through the File API stack.
161 document_extension_ = doc->GetHostedDocumentExtension(); 161 document_extension_ = doc.GetHostedDocumentExtension();
162 // We don't know the size of hosted docs and it does not matter since 162 // We don't know the size of hosted docs and it does not matter since
163 // is has no effect on the quota. 163 // is has no effect on the quota.
164 file_info_.size = 0; 164 file_info_.size = 0;
165 } 165 }
166 kind_ = doc->kind(); 166 kind_ = doc.kind();
167 content_mime_type_ = doc->content_mime_type(); 167 content_mime_type_ = doc.content_mime_type();
168 is_hosted_document_ = doc->is_hosted_document(); 168 is_hosted_document_ = doc.is_hosted_document();
169 // SetBaseNameFromTitle() must be called after |title_|, 169 // SetBaseNameFromTitle() must be called after |title_|,
170 // |is_hosted_document_| and |document_extension_| are set. 170 // |is_hosted_document_| and |document_extension_| are set.
171 SetBaseNameFromTitle(); 171 SetBaseNameFromTitle();
172 172
173 const Link* thumbnail_link = doc->GetLinkByType(Link::THUMBNAIL); 173 const Link* thumbnail_link = doc.GetLinkByType(Link::THUMBNAIL);
174 if (thumbnail_link) 174 if (thumbnail_link)
175 thumbnail_url_ = thumbnail_link->href(); 175 thumbnail_url_ = thumbnail_link->href();
176 176
177 const Link* alternate_link = doc->GetLinkByType(Link::ALTERNATE); 177 const Link* alternate_link = doc.GetLinkByType(Link::ALTERNATE);
178 if (alternate_link) 178 if (alternate_link)
179 alternate_url_ = alternate_link->href(); 179 alternate_url_ = alternate_link->href();
180 } 180 }
181 181
182 // GDataDirectory class implementation. 182 // GDataDirectory class implementation.
183 183
184 GDataDirectory::GDataDirectory(GDataDirectoryService* directory_service) 184 GDataDirectory::GDataDirectory(GDataDirectoryService* directory_service)
185 : GDataEntry(directory_service) { 185 : GDataEntry(directory_service) {
186 file_info_.is_directory = true; 186 file_info_.is_directory = true;
187 } 187 }
188 188
189 GDataDirectory::~GDataDirectory() { 189 GDataDirectory::~GDataDirectory() {
190 RemoveChildren(); 190 RemoveChildren();
191 } 191 }
192 192
193 GDataDirectory* GDataDirectory::AsGDataDirectory() { 193 GDataDirectory* GDataDirectory::AsGDataDirectory() {
194 return this; 194 return this;
195 } 195 }
196 196
197 void GDataDirectory::InitFromDocumentEntry(DocumentEntry* doc) { 197 void GDataDirectory::InitFromDocumentEntry(const DocumentEntry& doc) {
198 GDataEntry::InitFromDocumentEntry(doc); 198 GDataEntry::InitFromDocumentEntry(doc);
199 199
200 const Link* upload_link = doc->GetLinkByType(Link::RESUMABLE_CREATE_MEDIA); 200 const Link* upload_link = doc.GetLinkByType(Link::RESUMABLE_CREATE_MEDIA);
201 if (upload_link) 201 if (upload_link)
202 upload_url_ = upload_link->href(); 202 upload_url_ = upload_link->href();
203 } 203 }
204 204
205 void GDataDirectory::AddEntry(GDataEntry* entry) { 205 void GDataDirectory::AddEntry(GDataEntry* entry) {
206 DCHECK(!entry->parent()); 206 DCHECK(!entry->parent());
207 207
208 // The entry name may have been changed due to prior name de-duplication. 208 // The entry name may have been changed due to prior name de-duplication.
209 // We need to first restore the file name based on the title before going 209 // We need to first restore the file name based on the title before going
210 // through name de-duplication again when it is added to another directory. 210 // through name de-duplication again when it is added to another directory.
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 DCHECK(ok); 527 DCHECK(ok);
528 } else if (dir) { 528 } else if (dir) {
529 GDataDirectoryProto dir_proto; 529 GDataDirectoryProto dir_proto;
530 dir->ToProto(&dir_proto); 530 dir->ToProto(&dir_proto);
531 const bool ok = dir_proto.SerializeToString(serialized_proto); 531 const bool ok = dir_proto.SerializeToString(serialized_proto);
532 DCHECK(ok); 532 DCHECK(ok);
533 } 533 }
534 } 534 }
535 535
536 } // namespace gdata 536 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_files.h ('k') | chrome/browser/chromeos/gdata/gdata_wapi_feed_processor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698