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

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

Issue 10274002: Add gdata content search (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: a nit Created 8 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
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_util.h" 5 #include "chrome/browser/chromeos/gdata/gdata_util.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 29 matching lines...) Expand all
40 namespace { 40 namespace {
41 41
42 const char kGDataSpecialRootPath[] = "/special"; 42 const char kGDataSpecialRootPath[] = "/special";
43 43
44 const char kGDataMountPointPath[] = "/special/gdata"; 44 const char kGDataMountPointPath[] = "/special/gdata";
45 45
46 const FilePath::CharType* kGDataMountPointPathComponents[] = { 46 const FilePath::CharType* kGDataMountPointPathComponents[] = {
47 "/", "special", "gdata" 47 "/", "special", "gdata"
48 }; 48 };
49 49
50 const FilePath::CharType* kGDataSearchPathComponents[] = {
51 "gdata", ".search"
52 };
53
50 const int kReadOnlyFilePermissions = base::PLATFORM_FILE_OPEN | 54 const int kReadOnlyFilePermissions = base::PLATFORM_FILE_OPEN |
51 base::PLATFORM_FILE_READ | 55 base::PLATFORM_FILE_READ |
52 base::PLATFORM_FILE_EXCLUSIVE_READ | 56 base::PLATFORM_FILE_EXCLUSIVE_READ |
53 base::PLATFORM_FILE_ASYNC; 57 base::PLATFORM_FILE_ASYNC;
54 58
55 class GetFileNameDelegate : public FindEntryDelegate { 59 class GetFileNameDelegate : public FindEntryDelegate {
56 public: 60 public:
57 GetFileNameDelegate() {} 61 GetFileNameDelegate() {}
58 virtual ~GetFileNameDelegate() {} 62 virtual ~GetFileNameDelegate() {}
59 63
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 *url = gdata::util::GetFileResourceUrl(resource_id, delegate.file_name()); 173 *url = gdata::util::GetFileResourceUrl(resource_id, delegate.file_name());
170 DVLOG(1) << "ModifyGDataFileResourceUrl " << *url; 174 DVLOG(1) << "ModifyGDataFileResourceUrl " << *url;
171 } 175 }
172 } 176 }
173 177
174 bool IsUnderGDataMountPoint(const FilePath& path) { 178 bool IsUnderGDataMountPoint(const FilePath& path) {
175 return GetGDataMountPointPath() == path || 179 return GetGDataMountPointPath() == path ||
176 GetGDataMountPointPath().IsParent(path); 180 GetGDataMountPointPath().IsParent(path);
177 } 181 }
178 182
183 GDataSearchPathType GetSearchPathStatus(const FilePath& path) {
184 std::vector<std::string> components;
185 path.GetComponents(&components);
186 return GetSearchPathStatusForPathComponents(components);
187 }
188
189 GDataSearchPathType GetSearchPathStatusForPathComponents(
190 const std::vector<std::string>& path_components) {
191 if (path_components.size() < arraysize(kGDataSearchPathComponents))
192 return GDATA_SEARCH_PATH_INVALID;
193
194 for (size_t i = 0; i < arraysize(kGDataSearchPathComponents); i++) {
195 if (path_components[i] != kGDataSearchPathComponents[i])
196 return GDATA_SEARCH_PATH_INVALID;
197 }
198
199 switch (path_components.size()) {
200 case 2:
201 return GDATA_SEARCH_PATH_ROOT;
202 case 3:
203 return GDATA_SEARCH_PATH_QUERY;
204 case 4:
205 return GDATA_SEARCH_PATH_RESULT;
206 default:
207 return GDATA_SEARCH_PATH_RESULT_CHILD;
208 }
209 }
210
211 void ParseSearchFileName(const std::string& search_file_name,
212 std::string* resource_id,
213 std::string* original_file_name) {
214 DCHECK(resource_id);
215 DCHECK(original_file_name);
216
217 *resource_id = "";
218 *original_file_name = "";
219
220 size_t dot_index = search_file_name.find('.');
221 if (dot_index == std::string::npos)
222 return;
223
224 *resource_id = search_file_name.substr(0, dot_index);
225 if (search_file_name.length() - 1 > dot_index)
226 *original_file_name = search_file_name.substr(dot_index + 1);
227 }
228
179 FilePath ExtractGDataPath(const FilePath& path) { 229 FilePath ExtractGDataPath(const FilePath& path) {
180 if (!IsUnderGDataMountPoint(path)) 230 if (!IsUnderGDataMountPoint(path))
181 return FilePath(); 231 return FilePath();
182 232
183 std::vector<FilePath::StringType> components; 233 std::vector<FilePath::StringType> components;
184 path.GetComponents(&components); 234 path.GetComponents(&components);
185 235
186 // -1 to include 'gdata'. 236 // -1 to include 'gdata'.
187 FilePath extracted; 237 FilePath extracted;
188 for (size_t i = arraysize(kGDataMountPointPathComponents) - 1; 238 for (size_t i = arraysize(kGDataMountPointPathComponents) - 1;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 // Assign the extracted extensions to md5 and extra_extension. 364 // Assign the extracted extensions to md5 and extra_extension.
315 int extension_count = extensions.size(); 365 int extension_count = extensions.size();
316 *md5 = (extension_count > 0) ? extensions[extension_count - 1] : 366 *md5 = (extension_count > 0) ? extensions[extension_count - 1] :
317 std::string(); 367 std::string();
318 *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] : 368 *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] :
319 std::string(); 369 std::string();
320 } 370 }
321 371
322 } // namespace util 372 } // namespace util
323 } // namespace gdata 373 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698