| 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 "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "base/platform_file.h" | 8 #include "base/platform_file.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "chrome/browser/chromeos/gdata/gdata.pb.h" | 11 #include "chrome/browser/chromeos/gdata/gdata.pb.h" |
| 12 #include "chrome/browser/chromeos/gdata/gdata_parser.h" | 12 #include "chrome/browser/chromeos/gdata/gdata_parser.h" |
| 13 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 13 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 14 #include "net/base/escape.h" | 14 #include "net/base/escape.h" |
| 15 | 15 |
| 16 namespace gdata { | 16 namespace gdata { |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const char kSlash[] = "/"; | 19 const char kSlash[] = "/"; |
| 20 const char kEscapedSlash[] = "\xE2\x88\x95"; | 20 const char kEscapedSlash[] = "\xE2\x88\x95"; |
| 21 const FilePath::CharType kGDataRootDirectory[] = FILE_PATH_LITERAL("drive"); | |
| 22 | 21 |
| 23 std::string CacheSubDirectoryTypeToString( | 22 std::string CacheSubDirectoryTypeToString( |
| 24 GDataRootDirectory::CacheSubDirectoryType subdir) { | 23 GDataRootDirectory::CacheSubDirectoryType subdir) { |
| 25 switch (subdir) { | 24 switch (subdir) { |
| 26 case GDataRootDirectory::CACHE_TYPE_META: return "meta"; | 25 case GDataRootDirectory::CACHE_TYPE_META: return "meta"; |
| 27 case GDataRootDirectory::CACHE_TYPE_PINNED: return "pinned"; | 26 case GDataRootDirectory::CACHE_TYPE_PINNED: return "pinned"; |
| 28 case GDataRootDirectory::CACHE_TYPE_OUTGOING: return "outgoing"; | 27 case GDataRootDirectory::CACHE_TYPE_OUTGOING: return "outgoing"; |
| 29 case GDataRootDirectory::CACHE_TYPE_PERSISTENT: return "persistent"; | 28 case GDataRootDirectory::CACHE_TYPE_PERSISTENT: return "persistent"; |
| 30 case GDataRootDirectory::CACHE_TYPE_TMP: return "tmp"; | 29 case GDataRootDirectory::CACHE_TYPE_TMP: return "tmp"; |
| 31 case GDataRootDirectory::CACHE_TYPE_TMP_DOWNLOADS: | 30 case GDataRootDirectory::CACHE_TYPE_TMP_DOWNLOADS: |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 } | 423 } |
| 425 | 424 |
| 426 // GDataRootDirectory class implementation. | 425 // GDataRootDirectory class implementation. |
| 427 | 426 |
| 428 GDataRootDirectory::GDataRootDirectory() | 427 GDataRootDirectory::GDataRootDirectory() |
| 429 : ALLOW_THIS_IN_INITIALIZER_LIST(GDataDirectory(NULL, this)), | 428 : ALLOW_THIS_IN_INITIALIZER_LIST(GDataDirectory(NULL, this)), |
| 430 fake_search_directory_(new GDataDirectory(NULL, NULL)), | 429 fake_search_directory_(new GDataDirectory(NULL, NULL)), |
| 431 largest_changestamp_(0), serialized_size_(0) { | 430 largest_changestamp_(0), serialized_size_(0) { |
| 432 title_ = kGDataRootDirectory; | 431 title_ = kGDataRootDirectory; |
| 433 SetFileNameFromTitle(); | 432 SetFileNameFromTitle(); |
| 433 resource_id_ = kGDataRootDirectoryResourceId; |
| 434 // Add self to the map so the root directory can be looked up by the |
| 435 // resource ID. |
| 436 AddEntryToResourceMap(this); |
| 434 } | 437 } |
| 435 | 438 |
| 436 GDataRootDirectory::~GDataRootDirectory() { | 439 GDataRootDirectory::~GDataRootDirectory() { |
| 437 STLDeleteValues(&cache_map_); | 440 STLDeleteValues(&cache_map_); |
| 438 cache_map_.clear(); | 441 cache_map_.clear(); |
| 439 | 442 |
| 440 resource_map_.clear(); | 443 resource_map_.clear(); |
| 441 } | 444 } |
| 442 | 445 |
| 443 GDataRootDirectory* GDataRootDirectory::AsGDataRootDirectory() { | 446 GDataRootDirectory* GDataRootDirectory::AsGDataRootDirectory() { |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 ToProto(proto.get()); | 862 ToProto(proto.get()); |
| 860 const bool ok = proto->SerializeToString(serialized_proto); | 863 const bool ok = proto->SerializeToString(serialized_proto); |
| 861 DCHECK(ok); | 864 DCHECK(ok); |
| 862 } | 865 } |
| 863 | 866 |
| 864 bool GDataRootDirectory::ParseFromString(const std::string& serialized_proto) { | 867 bool GDataRootDirectory::ParseFromString(const std::string& serialized_proto) { |
| 865 scoped_ptr<GDataRootDirectoryProto> proto( | 868 scoped_ptr<GDataRootDirectoryProto> proto( |
| 866 new GDataRootDirectoryProto()); | 869 new GDataRootDirectoryProto()); |
| 867 bool ok = proto->ParseFromString(serialized_proto); | 870 bool ok = proto->ParseFromString(serialized_proto); |
| 868 if (ok) { | 871 if (ok) { |
| 872 const GDataEntryProto& entry_proto = |
| 873 proto->gdata_directory().gdata_entry(); |
| 869 // The title field for the root directory was originally empty, then | 874 // The title field for the root directory was originally empty, then |
| 870 // changed to "gdata", then changed to "drive". Discard the proto data if | 875 // changed to "gdata", then changed to "drive". Discard the proto data if |
| 871 // the older formats are detected. See crbug.com/128133 for details. | 876 // the older formats are detected. See crbug.com/128133 for details. |
| 872 const std::string& title = proto->gdata_directory().gdata_entry().title(); | 877 if (entry_proto.title() != "drive") { |
| 873 if (title != "drive") { | 878 LOG(ERROR) << "Incompatible proto detected (bad title): " |
| 874 LOG(ERROR) << "Incompatible proto detected: " << title; | 879 << entry_proto.title(); |
| 880 return false; |
| 881 } |
| 882 // The title field for the root directory was originally empty. Discard |
| 883 // the proto data if the older format is detected. |
| 884 if (entry_proto.resource_id() != kGDataRootDirectoryResourceId) { |
| 885 LOG(ERROR) << "Incompatible proto detected (bad resource ID): " |
| 886 << entry_proto.resource_id(); |
| 875 return false; | 887 return false; |
| 876 } | 888 } |
| 877 | 889 |
| 878 FromProto(*proto.get()); | 890 FromProto(*proto.get()); |
| 879 set_origin(FROM_CACHE); | 891 set_origin(FROM_CACHE); |
| 880 set_refresh_time(base::Time::Now()); | 892 set_refresh_time(base::Time::Now()); |
| 881 } | 893 } |
| 882 return ok; | 894 return ok; |
| 883 } | 895 } |
| 884 | 896 |
| 885 } // namespace gdata | 897 } // namespace gdata |
| OLD | NEW |