| 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_files.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "chrome/browser/chromeos/gdata/find_entry_delegate.h" | 13 #include "chrome/browser/chromeos/gdata/find_entry_delegate.h" |
| 14 #include "chrome/browser/chromeos/gdata/gdata.pb.h" | 14 #include "chrome/browser/chromeos/gdata/gdata.pb.h" |
| 15 #include "chrome/browser/chromeos/gdata/gdata_parser.h" | 15 #include "chrome/browser/chromeos/gdata/gdata_parser.h" |
| 16 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
| 17 | 17 |
| 18 namespace gdata { | 18 namespace gdata { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // Content refresh time. | |
| 22 #ifndef NDEBUG | |
| 23 const int kRefreshTimeInSec = 10; | |
| 24 #else | |
| 25 const int kRefreshTimeInSec = 5*60; | |
| 26 #endif | |
| 27 | |
| 28 const char kSlash[] = "/"; | 21 const char kSlash[] = "/"; |
| 29 const char kEscapedSlash[] = "\xE2\x88\x95"; | 22 const char kEscapedSlash[] = "\xE2\x88\x95"; |
| 30 const FilePath::CharType kGDataRootDirectory[] = FILE_PATH_LITERAL("gdata"); | 23 const FilePath::CharType kGDataRootDirectory[] = FILE_PATH_LITERAL("gdata"); |
| 31 | 24 |
| 32 std::string CacheSubDirectoryTypeToString( | 25 std::string CacheSubDirectoryTypeToString( |
| 33 GDataRootDirectory::CacheSubDirectoryType subdir) { | 26 GDataRootDirectory::CacheSubDirectoryType subdir) { |
| 34 switch (subdir) { | 27 switch (subdir) { |
| 35 case GDataRootDirectory::CACHE_TYPE_META: return "meta"; | 28 case GDataRootDirectory::CACHE_TYPE_META: return "meta"; |
| 36 case GDataRootDirectory::CACHE_TYPE_PINNED: return "pinned"; | 29 case GDataRootDirectory::CACHE_TYPE_PINNED: return "pinned"; |
| 37 case GDataRootDirectory::CACHE_TYPE_OUTGOING: return "outgoing"; | 30 case GDataRootDirectory::CACHE_TYPE_OUTGOING: return "outgoing"; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 if (parent_link) | 256 if (parent_link) |
| 264 dir->parent_resource_id_ = ExtractResourceId(parent_link->href()); | 257 dir->parent_resource_id_ = ExtractResourceId(parent_link->href()); |
| 265 | 258 |
| 266 const Link* upload_link = doc->GetLinkByType(Link::RESUMABLE_CREATE_MEDIA); | 259 const Link* upload_link = doc->GetLinkByType(Link::RESUMABLE_CREATE_MEDIA); |
| 267 if (upload_link) | 260 if (upload_link) |
| 268 dir->upload_url_ = upload_link->href(); | 261 dir->upload_url_ = upload_link->href(); |
| 269 | 262 |
| 270 return dir; | 263 return dir; |
| 271 } | 264 } |
| 272 | 265 |
| 273 bool GDataDirectory::NeedsRefresh() const { | |
| 274 // Already refreshing by someone else. | |
| 275 if (origin_ == REFRESHING) | |
| 276 return false; | |
| 277 | |
| 278 // Refresh is needed for content read from disk cache or stale content. | |
| 279 if (origin_ == FROM_CACHE) | |
| 280 return true; | |
| 281 | |
| 282 if ((base::Time::Now() - refresh_time_).InSeconds() < kRefreshTimeInSec) | |
| 283 return false; | |
| 284 | |
| 285 return true; | |
| 286 } | |
| 287 | |
| 288 void GDataDirectory::AddEntry(GDataEntry* entry) { | 266 void GDataDirectory::AddEntry(GDataEntry* entry) { |
| 289 // The entry name may have been changed due to prior name de-duplication. | 267 // The entry name may have been changed due to prior name de-duplication. |
| 290 // We need to first restore the file name based on the title before going | 268 // We need to first restore the file name based on the title before going |
| 291 // through name de-duplication again when it is added to another directory. | 269 // through name de-duplication again when it is added to another directory. |
| 292 entry->SetFileNameFromTitle(); | 270 entry->SetFileNameFromTitle(); |
| 293 | 271 |
| 294 // Do file name de-duplication - find files with the same name and | 272 // Do file name de-duplication - find files with the same name and |
| 295 // append a name modifier to the name. | 273 // append a name modifier to the name. |
| 296 int max_modifier = 1; | 274 int max_modifier = 1; |
| 297 FilePath full_file_name(entry->file_name()); | 275 FilePath full_file_name(entry->file_name()); |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 bool ok = proto->ParseFromString(serialized_proto); | 800 bool ok = proto->ParseFromString(serialized_proto); |
| 823 if (ok) { | 801 if (ok) { |
| 824 FromProto(*proto.get()); | 802 FromProto(*proto.get()); |
| 825 set_origin(FROM_CACHE); | 803 set_origin(FROM_CACHE); |
| 826 set_refresh_time(base::Time::Now()); | 804 set_refresh_time(base::Time::Now()); |
| 827 } | 805 } |
| 828 return ok; | 806 return ok; |
| 829 } | 807 } |
| 830 | 808 |
| 831 } // namespace gdata | 809 } // namespace gdata |
| OLD | NEW |