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_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 Loading... |
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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 *url = gdata::util::GetFileResourceUrl(resource_id, delegate.file_name()); | 172 *url = gdata::util::GetFileResourceUrl(resource_id, delegate.file_name()); |
169 DVLOG(1) << "ModifyGDataFileResourceUrl " << *url; | 173 DVLOG(1) << "ModifyGDataFileResourceUrl " << *url; |
170 } | 174 } |
171 } | 175 } |
172 | 176 |
173 bool IsUnderGDataMountPoint(const FilePath& path) { | 177 bool IsUnderGDataMountPoint(const FilePath& path) { |
174 return GetGDataMountPointPath() == path || | 178 return GetGDataMountPointPath() == path || |
175 GetGDataMountPointPath().IsParent(path); | 179 GetGDataMountPointPath().IsParent(path); |
176 } | 180 } |
177 | 181 |
| 182 GDataSearchPathType GetSearchPathStatus(const FilePath& path) { |
| 183 std::vector<std::string> components; |
| 184 path.GetComponents(&components); |
| 185 return GetSearchPathStatusForPathComponents(components); |
| 186 } |
| 187 |
| 188 GDataSearchPathType GetSearchPathStatusForPathComponents( |
| 189 const std::vector<std::string>& path_components) { |
| 190 if (path_components.size() < arraysize(kGDataSearchPathComponents)) |
| 191 return GDATA_SEARCH_PATH_INVALID; |
| 192 |
| 193 for (size_t i = 0; i < arraysize(kGDataSearchPathComponents); i++) { |
| 194 if (path_components[i] != kGDataSearchPathComponents[i]) |
| 195 return GDATA_SEARCH_PATH_INVALID; |
| 196 } |
| 197 |
| 198 switch (path_components.size()) { |
| 199 case 2: |
| 200 return GDATA_SEARCH_PATH_ROOT; |
| 201 case 3: |
| 202 return GDATA_SEARCH_PATH_QUERY; |
| 203 case 4: |
| 204 return GDATA_SEARCH_PATH_RESULT; |
| 205 default: |
| 206 return GDATA_SEARCH_PATH_RESULT_CHILD; |
| 207 } |
| 208 } |
| 209 |
| 210 bool ParseSearchFileName(const std::string& search_file_name, |
| 211 std::string* resource_id, |
| 212 std::string* original_file_name) { |
| 213 DCHECK(resource_id); |
| 214 DCHECK(original_file_name); |
| 215 |
| 216 *resource_id = ""; |
| 217 *original_file_name = ""; |
| 218 |
| 219 size_t dot_index = search_file_name.find('.'); |
| 220 if (dot_index == std::string::npos) |
| 221 return false; |
| 222 |
| 223 *resource_id = search_file_name.substr(0, dot_index); |
| 224 if (search_file_name.length() - 1 > dot_index) |
| 225 *original_file_name = search_file_name.substr(dot_index + 1); |
| 226 return (!resource_id->empty() && !original_file_name->empty()); |
| 227 } |
| 228 |
178 FilePath ExtractGDataPath(const FilePath& path) { | 229 FilePath ExtractGDataPath(const FilePath& path) { |
179 if (!IsUnderGDataMountPoint(path)) | 230 if (!IsUnderGDataMountPoint(path)) |
180 return FilePath(); | 231 return FilePath(); |
181 | 232 |
182 std::vector<FilePath::StringType> components; | 233 std::vector<FilePath::StringType> components; |
183 path.GetComponents(&components); | 234 path.GetComponents(&components); |
184 | 235 |
185 // -1 to include 'gdata'. | 236 // -1 to include 'gdata'. |
186 FilePath extracted; | 237 FilePath extracted; |
187 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 Loading... |
313 // Assign the extracted extensions to md5 and extra_extension. | 364 // Assign the extracted extensions to md5 and extra_extension. |
314 int extension_count = extensions.size(); | 365 int extension_count = extensions.size(); |
315 *md5 = (extension_count > 0) ? extensions[extension_count - 1] : | 366 *md5 = (extension_count > 0) ? extensions[extension_count - 1] : |
316 std::string(); | 367 std::string(); |
317 *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] : | 368 *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] : |
318 std::string(); | 369 std::string(); |
319 } | 370 } |
320 | 371 |
321 } // namespace util | 372 } // namespace util |
322 } // namespace gdata | 373 } // namespace gdata |
OLD | NEW |