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

Side by Side Diff: chrome/browser/drive/drive_api_util.cc

Issue 881723002: Remove google_apis::ResourceEntry and related code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 (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/drive/drive_api_util.h" 5 #include "chrome/browser/drive/drive_api_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/md5.h" 11 #include "base/md5.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "google_apis/drive/drive_api_parser.h" 17 #include "google_apis/drive/drive_api_parser.h"
18 #include "google_apis/drive/gdata_wapi_parser.h"
19 #include "net/base/escape.h" 18 #include "net/base/escape.h"
20 #include "third_party/re2/re2/re2.h" 19 #include "third_party/re2/re2/re2.h"
21 #include "url/gurl.h" 20 #include "url/gurl.h"
22 21
23 namespace drive { 22 namespace drive {
24 namespace util { 23 namespace util {
25 namespace { 24 namespace {
26 25
27 struct HostedDocumentKind { 26 struct HostedDocumentKind {
28 const char* mime_type; 27 const char* mime_type;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 std::string CanonicalizeResourceId(const std::string& resource_id) { 123 std::string CanonicalizeResourceId(const std::string& resource_id) {
125 // If resource ID is in the old WAPI format starting with a prefix like 124 // If resource ID is in the old WAPI format starting with a prefix like
126 // "document:", strip it and return the remaining part. 125 // "document:", strip it and return the remaining part.
127 std::string stripped_resource_id; 126 std::string stripped_resource_id;
128 if (RE2::FullMatch(resource_id, "^[a-z-]+(?::|%3A)([\\w-]+)$", 127 if (RE2::FullMatch(resource_id, "^[a-z-]+(?::|%3A)([\\w-]+)$",
129 &stripped_resource_id)) 128 &stripped_resource_id))
130 return stripped_resource_id; 129 return stripped_resource_id;
131 return resource_id; 130 return resource_id;
132 } 131 }
133 132
134 scoped_ptr<google_apis::ResourceEntry>
135 ConvertFileResourceToResourceEntry(
136 const google_apis::FileResource& file_resource) {
137 scoped_ptr<google_apis::ResourceEntry> entry(new google_apis::ResourceEntry);
138
139 // ResourceEntry
140 entry->set_resource_id(file_resource.file_id());
141 if (file_resource.IsDirectory())
142 entry->set_kind(google_apis::ResourceEntry::ENTRY_KIND_FOLDER);
143 else if (file_resource.IsHostedDocument())
144 entry->set_kind(google_apis::ResourceEntry::ENTRY_KIND_UNKNOWN);
145 else
146 entry->set_kind(google_apis::ResourceEntry::ENTRY_KIND_FILE);
147 entry->set_title(file_resource.title());
148
149 // If file is removed completely, that information is only available in
150 // ChangeResource, and is reflected in |removed_|. If file is trashed, the
151 // file entry still exists but with its "trashed" label true.
152 entry->set_deleted(file_resource.labels().is_trashed());
153
154 return entry.Pass();
155 }
156
157 std::string GetMd5Digest(const base::FilePath& file_path) { 133 std::string GetMd5Digest(const base::FilePath& file_path) {
158 const int kBufferSize = 512 * 1024; // 512kB. 134 const int kBufferSize = 512 * 1024; // 512kB.
159 135
160 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ); 136 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
161 if (!file.IsValid()) 137 if (!file.IsValid())
162 return std::string(); 138 return std::string();
163 139
164 base::MD5Context context; 140 base::MD5Context context;
165 base::MD5Init(&context); 141 base::MD5Init(&context);
166 142
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 const std::string extension = base::FilePath(path.Extension()).AsUTF8Unsafe(); 183 const std::string extension = base::FilePath(path.Extension()).AsUTF8Unsafe();
208 for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) { 184 for (size_t i = 0; i < arraysize(kHostedDocumentKinds); ++i) {
209 if (extension == kHostedDocumentKinds[i].extension) 185 if (extension == kHostedDocumentKinds[i].extension)
210 return true; 186 return true;
211 } 187 }
212 return extension == kUnknownHostedDocumentExtension; 188 return extension == kUnknownHostedDocumentExtension;
213 } 189 }
214 190
215 } // namespace util 191 } // namespace util
216 } // namespace drive 192 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/drive/drive_api_util.h ('k') | chrome/browser/sync_file_system/drive_backend/conflict_resolver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698