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

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

Issue 10332253: gdata: Define the resource ID for the root directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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_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
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 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
869 // The title field for the root directory was originally empty, then 872 // The title field for the root directory was originally empty, then
870 // changed to "gdata", then changed to "drive". Discard the proto data if 873 // changed to "gdata", then changed to "drive". Discard the proto data if
871 // the older formats are detected. See crbug.com/128133 for details. 874 // the older formats are detected. See crbug.com/128133 for details.
872 const std::string& title = proto->gdata_directory().gdata_entry().title(); 875 const GDataEntryProto& entry = proto->gdata_directory().gdata_entry();
achuithb 2012/05/18 17:42:56 nit: maybe call this entry_proto?
satorux1 2012/05/18 17:55:28 Done.
873 if (title != "drive") { 876 if (entry.title() != "drive") {
874 LOG(ERROR) << "Incompatible proto detected: " << title; 877 LOG(ERROR) << "Incompatible proto detected (bad title): "
878 << entry.title();
879 return false;
880 }
881 if (entry.resource_id() != kGDataRootDirectoryResourceId) {
882 LOG(ERROR) << "Incompatible proto detected (bad resource id): "
883 << entry.resource_id();
875 return false; 884 return false;
876 } 885 }
877 886
878 FromProto(*proto.get()); 887 FromProto(*proto.get());
879 set_origin(FROM_CACHE); 888 set_origin(FROM_CACHE);
880 set_refresh_time(base::Time::Now()); 889 set_refresh_time(base::Time::Now());
881 } 890 }
882 return ok; 891 return ok;
883 } 892 }
884 893
885 } // namespace gdata 894 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698