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

Side by Side Diff: chrome/browser/chromeos/drive/drive_files.cc

Issue 11106007: drive: Rename 'gdata' namespace to 'drive' in chrome/browser/chromeos/drive (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 2 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/drive/drive_files.h" 5 #include "chrome/browser/chromeos/drive/drive_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"
11 #include "chrome/browser/chromeos/drive/drive.pb.h" 11 #include "chrome/browser/chromeos/drive/drive.pb.h"
12 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" 12 #include "chrome/browser/chromeos/drive/drive_file_system_util.h"
13 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" 13 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h"
14 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 14 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
15 #include "net/base/escape.h" 15 #include "net/base/escape.h"
16 16
17 namespace gdata { 17 namespace drive {
18 18
19 // DriveEntry class. 19 // DriveEntry class.
20 20
21 DriveEntry::DriveEntry(DriveResourceMetadata* resource_metadata) 21 DriveEntry::DriveEntry(DriveResourceMetadata* resource_metadata)
22 : parent_(NULL), 22 : parent_(NULL),
23 resource_metadata_(resource_metadata), 23 resource_metadata_(resource_metadata),
24 deleted_(false) { 24 deleted_(false) {
25 DCHECK(resource_metadata); 25 DCHECK(resource_metadata);
26 } 26 }
27 27
28 DriveEntry::~DriveEntry() { 28 DriveEntry::~DriveEntry() {
29 } 29 }
30 30
31 DriveFile* DriveEntry::AsDriveFile() { 31 DriveFile* DriveEntry::AsDriveFile() {
32 return NULL; 32 return NULL;
33 } 33 }
34 34
35 DriveDirectory* DriveEntry::AsDriveDirectory() { 35 DriveDirectory* DriveEntry::AsDriveDirectory() {
36 return NULL; 36 return NULL;
37 } 37 }
38 38
39 void DriveEntry::InitFromDocumentEntry(const DocumentEntry& doc) { 39 void DriveEntry::InitFromDocumentEntry(const gdata::DocumentEntry& doc) {
40 // For regular files, the 'filename' and 'title' attribute in the metadata 40 // For regular files, the 'filename' and 'title' attribute in the metadata
41 // may be different (e.g. due to rename). To be consistent with the web 41 // may be different (e.g. due to rename). To be consistent with the web
42 // interface and other client to use the 'title' attribute, instead of 42 // interface and other client to use the 'title' attribute, instead of
43 // 'filename', as the file name in the local snapshot. 43 // 'filename', as the file name in the local snapshot.
44 title_ = UTF16ToUTF8(doc.title()); 44 title_ = UTF16ToUTF8(doc.title());
45 // SetBaseNameFromTitle() must be called after |title_| is set. 45 // SetBaseNameFromTitle() must be called after |title_| is set.
46 SetBaseNameFromTitle(); 46 SetBaseNameFromTitle();
47 47
48 file_info_.last_modified = doc.updated_time(); 48 file_info_.last_modified = doc.updated_time();
49 // If doc.last_viewed_time().is_null() then, we will pass 0 to the 49 // If doc.last_viewed_time().is_null() then, we will pass 0 to the
50 // protocol buffer. Moreover, this value may be unreliable. 50 // protocol buffer. Moreover, this value may be unreliable.
51 // See: crbug.com/152628. 51 // See: crbug.com/152628.
52 file_info_.last_accessed = doc.last_viewed_time(); 52 file_info_.last_accessed = doc.last_viewed_time();
53 file_info_.creation_time = doc.published_time(); 53 file_info_.creation_time = doc.published_time();
54 54
55 resource_id_ = doc.resource_id(); 55 resource_id_ = doc.resource_id();
56 content_url_ = doc.content_url(); 56 content_url_ = doc.content_url();
57 deleted_ = doc.deleted(); 57 deleted_ = doc.deleted();
58 58
59 const Link* edit_link = doc.GetLinkByType(Link::LINK_EDIT); 59 const gdata::Link* edit_link = doc.GetLinkByType(gdata::Link::LINK_EDIT);
60 if (edit_link) 60 if (edit_link)
61 edit_url_ = edit_link->href(); 61 edit_url_ = edit_link->href();
62 62
63 const Link* parent_link = doc.GetLinkByType(Link::LINK_PARENT); 63 const gdata::Link* parent_link = doc.GetLinkByType(gdata::Link::LINK_PARENT);
64 if (parent_link) 64 if (parent_link)
65 parent_resource_id_ = util::ExtractResourceIdFromUrl(parent_link->href()); 65 parent_resource_id_ = util::ExtractResourceIdFromUrl(parent_link->href());
66 } 66 }
67 67
68 const DriveFile* DriveEntry::AsDriveFileConst() const { 68 const DriveFile* DriveEntry::AsDriveFileConst() const {
69 // cast away const and call the non-const version. This is safe. 69 // cast away const and call the non-const version. This is safe.
70 return const_cast<DriveEntry*>(this)->AsDriveFile(); 70 return const_cast<DriveEntry*>(this)->AsDriveFile();
71 } 71 }
72 72
73 const DriveDirectory* DriveEntry::AsDriveDirectoryConst() const { 73 const DriveDirectory* DriveEntry::AsDriveDirectoryConst() const {
(...skipping 15 matching lines...) Expand all
89 } 89 }
90 90
91 void DriveEntry::SetBaseNameFromTitle() { 91 void DriveEntry::SetBaseNameFromTitle() {
92 base_name_ = util::EscapeUtf8FileName(title_); 92 base_name_ = util::EscapeUtf8FileName(title_);
93 } 93 }
94 94
95 // DriveFile class implementation. 95 // DriveFile class implementation.
96 96
97 DriveFile::DriveFile(DriveResourceMetadata* resource_metadata) 97 DriveFile::DriveFile(DriveResourceMetadata* resource_metadata)
98 : DriveEntry(resource_metadata), 98 : DriveEntry(resource_metadata),
99 kind_(ENTRY_KIND_UNKNOWN), 99 kind_(gdata::ENTRY_KIND_UNKNOWN),
100 is_hosted_document_(false) { 100 is_hosted_document_(false) {
101 file_info_.is_directory = false; 101 file_info_.is_directory = false;
102 } 102 }
103 103
104 DriveFile::~DriveFile() { 104 DriveFile::~DriveFile() {
105 } 105 }
106 106
107 DriveFile* DriveFile::AsDriveFile() { 107 DriveFile* DriveFile::AsDriveFile() {
108 return this; 108 return this;
109 } 109 }
110 110
111 void DriveFile::SetBaseNameFromTitle() { 111 void DriveFile::SetBaseNameFromTitle() {
112 if (is_hosted_document_) { 112 if (is_hosted_document_) {
113 base_name_ = util::EscapeUtf8FileName(title_ + document_extension_); 113 base_name_ = util::EscapeUtf8FileName(title_ + document_extension_);
114 } else { 114 } else {
115 DriveEntry::SetBaseNameFromTitle(); 115 DriveEntry::SetBaseNameFromTitle();
116 } 116 }
117 } 117 }
118 118
119 void DriveFile::InitFromDocumentEntry(const DocumentEntry& doc) { 119 void DriveFile::InitFromDocumentEntry(const gdata::DocumentEntry& doc) {
120 DriveEntry::InitFromDocumentEntry(doc); 120 DriveEntry::InitFromDocumentEntry(doc);
121 121
122 // Check if this entry is a true file, or... 122 // Check if this entry is a true file, or...
123 if (doc.is_file()) { 123 if (doc.is_file()) {
124 file_info_.size = doc.file_size(); 124 file_info_.size = doc.file_size();
125 file_md5_ = doc.file_md5(); 125 file_md5_ = doc.file_md5();
126 126
127 // The resumable-edit-media link should only be present for regular 127 // The resumable-edit-media link should only be present for regular
128 // files as hosted documents are not uploadable. 128 // files as hosted documents are not uploadable.
129 const Link* upload_link = 129 const gdata::Link* upload_link =
130 doc.GetLinkByType(Link::LINK_RESUMABLE_EDIT_MEDIA); 130 doc.GetLinkByType(gdata::Link::LINK_RESUMABLE_EDIT_MEDIA);
131 if (upload_link) 131 if (upload_link)
132 upload_url_ = upload_link->href(); 132 upload_url_ = upload_link->href();
133 } else { 133 } else {
134 // ... a hosted document. 134 // ... a hosted document.
135 // Attach .g<something> extension to hosted documents so we can special 135 // Attach .g<something> extension to hosted documents so we can special
136 // case their handling in UI. 136 // case their handling in UI.
137 // TODO(zelidrag): Figure out better way how to pass entry info like kind 137 // TODO(zelidrag): Figure out better way how to pass entry info like kind
138 // to UI through the File API stack. 138 // to UI through the File API stack.
139 document_extension_ = doc.GetHostedDocumentExtension(); 139 document_extension_ = doc.GetHostedDocumentExtension();
140 // We don't know the size of hosted docs and it does not matter since 140 // We don't know the size of hosted docs and it does not matter since
141 // is has no effect on the quota. 141 // is has no effect on the quota.
142 file_info_.size = 0; 142 file_info_.size = 0;
143 } 143 }
144 kind_ = doc.kind(); 144 kind_ = doc.kind();
145 content_mime_type_ = doc.content_mime_type(); 145 content_mime_type_ = doc.content_mime_type();
146 is_hosted_document_ = doc.is_hosted_document(); 146 is_hosted_document_ = doc.is_hosted_document();
147 // SetBaseNameFromTitle() must be called after |title_|, 147 // SetBaseNameFromTitle() must be called after |title_|,
148 // |is_hosted_document_| and |document_extension_| are set. 148 // |is_hosted_document_| and |document_extension_| are set.
149 SetBaseNameFromTitle(); 149 SetBaseNameFromTitle();
150 150
151 const Link* thumbnail_link = doc.GetLinkByType(Link::LINK_THUMBNAIL); 151 const gdata::Link* thumbnail_link = doc.GetLinkByType(
152 gdata::Link::LINK_THUMBNAIL);
152 if (thumbnail_link) 153 if (thumbnail_link)
153 thumbnail_url_ = thumbnail_link->href(); 154 thumbnail_url_ = thumbnail_link->href();
154 155
155 const Link* alternate_link = doc.GetLinkByType(Link::LINK_ALTERNATE); 156 const gdata::Link* alternate_link = doc.GetLinkByType(
157 gdata::Link::LINK_ALTERNATE);
156 if (alternate_link) 158 if (alternate_link)
157 alternate_url_ = alternate_link->href(); 159 alternate_url_ = alternate_link->href();
158 } 160 }
159 161
160 // DriveDirectory class implementation. 162 // DriveDirectory class implementation.
161 163
162 DriveDirectory::DriveDirectory(DriveResourceMetadata* resource_metadata) 164 DriveDirectory::DriveDirectory(DriveResourceMetadata* resource_metadata)
163 : DriveEntry(resource_metadata) { 165 : DriveEntry(resource_metadata) {
164 file_info_.is_directory = true; 166 file_info_.is_directory = true;
165 } 167 }
166 168
167 DriveDirectory::~DriveDirectory() { 169 DriveDirectory::~DriveDirectory() {
168 RemoveChildren(); 170 RemoveChildren();
169 } 171 }
170 172
171 DriveDirectory* DriveDirectory::AsDriveDirectory() { 173 DriveDirectory* DriveDirectory::AsDriveDirectory() {
172 return this; 174 return this;
173 } 175 }
174 176
175 void DriveDirectory::InitFromDocumentEntry(const DocumentEntry& doc) { 177 void DriveDirectory::InitFromDocumentEntry(const gdata::DocumentEntry& doc) {
176 DriveEntry::InitFromDocumentEntry(doc); 178 DriveEntry::InitFromDocumentEntry(doc);
177 179
178 const Link* upload_link = 180 const gdata::Link* upload_link =
179 doc.GetLinkByType(Link::LINK_RESUMABLE_CREATE_MEDIA); 181 doc.GetLinkByType(gdata::Link::LINK_RESUMABLE_CREATE_MEDIA);
180 if (upload_link) 182 if (upload_link)
181 upload_url_ = upload_link->href(); 183 upload_url_ = upload_link->href();
182 } 184 }
183 185
184 void DriveDirectory::AddEntry(DriveEntry* entry) { 186 void DriveDirectory::AddEntry(DriveEntry* entry) {
185 DCHECK(!entry->parent()); 187 DCHECK(!entry->parent());
186 188
187 // Try to add the entry to resource map. 189 // Try to add the entry to resource map.
188 if (!resource_metadata_->AddEntryToResourceMap(entry)) { 190 if (!resource_metadata_->AddEntryToResourceMap(entry)) {
189 LOG(WARNING) << "Duplicate resource=" << entry->resource_id() 191 LOG(WARNING) << "Duplicate resource=" << entry->resource_id()
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 const bool ok = entry_proto.SerializeToString(serialized_proto); 498 const bool ok = entry_proto.SerializeToString(serialized_proto);
497 DCHECK(ok); 499 DCHECK(ok);
498 } else if (dir) { 500 } else if (dir) {
499 DriveDirectoryProto dir_proto; 501 DriveDirectoryProto dir_proto;
500 dir->ToProto(&dir_proto); 502 dir->ToProto(&dir_proto);
501 const bool ok = dir_proto.SerializeToString(serialized_proto); 503 const bool ok = dir_proto.SerializeToString(serialized_proto);
502 DCHECK(ok); 504 DCHECK(ok);
503 } 505 }
504 } 506 }
505 507
506 } // namespace gdata 508 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_files.h ('k') | chrome/browser/chromeos/drive/drive_protocol_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698